Context and memory
Context is the model input for one invocation. Session history is the recorded sequence of work. Memory is an application-selected source of information that can outlive one invocation. A durable session does not automatically turn every past fact into useful memory.
Choose the source of each fact
Section titled “Choose the source of each fact”| Need | Owner | Example |
|---|---|---|
| Current request | Run input | A synthetic invoice to analyze |
| Recorded work | Session store | Tool calls, interruptions and results |
| Stable instructions | Agent prompt | Which evidence counts as an answer |
| Domain facts | Knowledge or tools | The current product catalog |
| Reusable experience | Memory | A verified preference with provenance |
| Model input size | Context policy | Selected history and bounded recall |
Keep the catalog in a domain service rather than teaching the model that a previous lookup is permanently current. Store a preference only when your application has authority to retain it. Treat recalled text as evidence with a source, rather than an instruction that can authorize tools.
Bound the model input
Section titled “Bound the model input”Choose a context policy for your agent. Context compaction changes the model-facing projection; it does not erase durable history. Preserve the evidence needed to resume pending work and understand earlier decisions. Test both a short interaction and a long session that reaches the configured threshold.
Prompt caching reuses provider work on matching input. It does not expand the context window or replace memory. A compaction strategy can affect cache reuse, so compare provider usage and runtime events rather than assuming that fewer visible messages always cost less.
Add memory deliberately
Section titled “Add memory deliberately”Use the generated project’s memory/ and knowledge/ seams. Define scope, eligibility, byte/item limits, freshness and provenance before adding recall. Make writes explicit and test rejected or outdated candidates as well as successful recall.
A useful regression case starts a second interaction, retrieves the retained fact, and proves that an unrelated session cannot gain authority from it. Regrading an old trajectory answers a different question from executing the changed agent again.
Read the context API, memory API and worked learning path.