Skip to content
mentoor

Topic 1 of 5 · 4 min read

Pre-loading versus looking things up

Goal: Choose pre-loading, just-in-time lookup or a hybrid for a task and justify it by data size, freshness and latency.

Pre-load what every run needs and is small; let the agent look up everything else when a step actually asks for it. The choice is not ideology. It is a trade between size, freshness and speed.

Check yourself · 1 of 3

Which information is the best candidate to pre-load into every run of an agent?

Choose one answer

Why it matters

The context window is the model's working memory, and it is limited. Anthropic's context engineering article describes the shift from loading all relevant data up front to keeping light references (file paths, queries, links) and loading data into context at run time with tools. Stuffing a whole repository into the prompt costs tokens on every turn, buries the useful lines and goes stale the moment someone edits a file.

How to decide

Ask three questions about each piece of information:

  1. Size. Does it fit comfortably and get used on most runs? A 40-line style guide does. A 300-file codebase does not.
  2. Freshness. Can it change during the session or between sessions? Ticket status, a database row, a failing test log and the current git diff change often. Look them up.
  3. Latency and cost. Every lookup adds at least one model turn and a tool call. If the answer is needed on every run anyway, a lookup only adds delay.

Three patterns result:

  • Pre-load: a fixed, small, always-relevant block, such as project rules, the output format and the user's request. Claude Code's CLAUDE.md file works this way: it is read at the start of every session.
  • Just in time: the agent holds references and fetches on demand with grep, file reads, search or database queries.
  • Hybrid: load a small core up front, then explore. Many coding agents do this: rules in the prompt, the code explored with tools.

Before and after

Weak plan for a support-bot agent that answers questions about 2,000 help articles:

Plan: paste all help articles into the system prompt.
Pro: the model has everything.

Better plan:

Pre-load: tone rules, escalation policy, and the article index (title + one line + id).
Look up: open the full article by id only when the question matches an index entry.
Always fetch fresh: order status from the orders API.

The second plan keeps the prompt small, keeps order data current, and still lets the model see what exists.

What goes wrong

  • Pre-loading by default. The agent drowns in text it does not need, and quality drops as the window fills.
  • Looking up what is always needed. The agent spends a turn reading the same rules file every run.
  • Pre-loaded copies that go stale. A pasted schema or API list is wrong after the next migration, and the model still trusts it.
  • No map. With nothing pre-loaded about what exists, the agent does not know what to search for.

Examples

Choosing for a code-review agent

A review agent gets a pull request number.

  • Pre-load: the team's review checklist (short, always used) and the PR title and description.
  • Look up: the diff, the files it touches, and callers of changed functions, using the git and search tools.
  • Fresh each time: CI status, because it changes while the agent works.

Pasting the whole repository would cost tokens on every turn and still miss the callers the agent needs.

When pre-loading wins

A translation agent always needs the same 30-term glossary and brand voice rules. Looking them up would add a tool call to every run for no benefit, so they go in the prompt. Use lookup only when the content is large, changing or needed on a minority of runs.

Key points

  • Pre-load small, stable, always-needed information; look up large, changing or rarely needed information.
  • Decide per piece of data using three tests: size, freshness and latency.
  • Light references such as file paths, ids and queries let an agent load detail at run time.
  • A hybrid, with a small core up front and exploration with tools after, is the common default for coding agents.
  • Pre-loaded copies go stale silently, while a lookup returns the current state.

Common mistakes

  • Pasting entire repositories or document sets into the prompt because the window is large.
  • Making the agent look up a small file that every run needs.
  • Leaving stale copies of schemas, configs or API lists in a static prompt.
  • Giving the agent nothing about what exists, so it cannot know what to search for.

Check yourself · 2 of 3

An agent's system prompt contains a pasted copy of the database schema. What is the main risk?

Choose one answer

Check yourself · 3 of 3

A coding agent works in a repository with thousands of files. Which setup is the usual good default?

Choose one answer

Practice items, not counted towards your mastery.

Start here