Context engineering best practices for AI agents

Multiple engineering posts outline production context strategies for AI agents and memory systems. - ChatGPT uses a four-tier context structure: session metadata, user memory store, recent conversation summaries (~15 dialogs), and current session window. - Context engineering five pillars: Agent, Query Augmentation, Retrieval, Memory, Tools. - Anthropic defines context engineering as building a dynamic, fault-tolerant workspace for models, not just prompt wording. - Google ADK recommends treating context as a compiled view with layers: working context, session, memory, artifacts; on-demand artifact loading and processor chains. - Manus practices: prefix-freezing to protect KV-cache, explicit state recitation to prevent "lost-in-the-middle", preserve error traces as negative samples, and introduce structure entropy to avoid pattern overfitting. - Tactical patterns: tool search, programmatic tool calling, dual-agent harness (initializer + coding agent), Git commits as external anchors, tool definition slimming and on-demand loading.
Key insights
ChatGPT employs a four-layer memory and context architecture
Analysis shows ChatGPT structures memory into four layers: session metadata for environment context, a persistent user memory store for long-term facts, a recent-dialogue summary of roughly 15 recent conversations, and the full current session window with sliding eviction. This design balances personalization with latency and cost by avoiding heavy vector-search on every request.
Context engineering reframes prompts as dynamic, compiled views
Weaviate and Google ADK materials define context engineering as building pipelines that compile source data into a working view for LLMs. ADK prescribes layered context (working, session, memory, artifacts), processor chains, relevance management, and on-demand artifact loading to control latency and avoid context pollution.
Operational patterns mitigate long-run agent degradation
Manus and Anthropic engineering notes recommend operational tactics: prefix-freezing to preserve KV-cache reuse, explicit state recitation to keep critical state in model attention, preserving error logs as negative-context training, tool-search to avoid stuffing tool definitions into system prompts, and dual-agent architectures to create durable anchors for long-running tasks.
Tooling and retrieval must be decoupled and dynamically loaded
Authors recommend slimming tool definitions and implementing tool-search so an agent only loads specific tool definitions on demand; retrieval should return concise, relevance-ranked material and artifacts should be referenced by name/version rather than inlined to avoid context pollution.