Skip to content

Instantly share code, notes, and snippets.

@vinhnx
Created December 25, 2025 07:32
Show Gist options
  • Select an option

  • Save vinhnx/6007c8ffc80eedaefad249dfe49207f0 to your computer and use it in GitHub Desktop.

Select an option

Save vinhnx/6007c8ffc80eedaefad249dfe49207f0 to your computer and use it in GitHub Desktop.
Context Engineering for AI Agents with LangChain and Manus
Strategy Description Typical Implementation Advantages Risks/Trade-offs
Context Offloading Moving parts of the working context, especially large payloads or tool outputs, into external storage. External file systems, sandbox storage, or agent state (e.g., LangGraph state). Prevents context window flooding; reduces costs and performance degradation. Requires efficient retrieval; complexity in managing external state.
Context Reduction (Compaction) Reversible reduction removing info that can be reconstructed from environment or storage. Replace full outputs with identifiers like paths, URLs, or queries; keep latest tool calls detailed. Reduces context length while maintaining recoverability. Model may mimic compact format incorrectly; missing fields in new tool calls.
Context Reduction (Summarization) Irreversible compression of message history or tool outputs to fit context limits. Structured schemas/forms to retain key information over free-form prompts. Significant token reduction; mitigates context rot (128K–200K token thresholds). Irreversible loss of detail; risk of discarding critical information.
Context Isolation (Sub-agents) Split tasks across independent sub-agents with separate context windows. Multi-agent architectures; Agent-as-a-Tool with shared memory or sandbox. Separation of concerns; prevents a single window from exploding. Communication overhead; sync issues; increased latency.
Context Retrieval Retrieve offloaded information on demand via search. Vector stores, semantic search, file search tools (grep, glob, ripgrep). Only relevant data enters context; handles massive datasets. On-the-fly indexing can be slow; semantic search may return irrelevant matches.
Context Caching Store KV states to avoid reprocessing identical prefixes. Provider-specific caching (Anthropic input caching, Gemini caching). Lower latency and cost for recurring prefixes. Provider-dependent; cache breaks (tool order changes) trigger full pricing.
Layered Action Space Offload complexity from model function-calling into sandbox utilities and scripts. Three-tier system: atomic calls, sandbox CLI tools, packaged scripts/APIs. Reduces decision confusion; simplifies tool space. Utilities/scripts not schema-safe; harder constraint enforcement.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment