Principle:1ay1 Agentty Context Injection
| Knowledge Sources | |
|---|---|
| Domains | RAG, LLM_Inference |
| Last Updated | 2026-10-28 12:00 GMT |
Overview
Process of injecting retrieved, compressed, source-tagged context snippets into an agent's tool interface so the model can ground its responses in real file paths and line numbers without the snippets consuming unbounded context.
Description
After retrieval, diversification, and compression, the results are code/documentation snippets with provenance (file path, line numbers). These must be delivered to the model in a form it can use: source-tagged, byte-budgeted, and accessible through the agent's tool interface (e.g., search_code and search_docs tools).
The injection surface is a ToolOutput with snippets formatted for model consumption — each snippet carries its file path and line range so the model can cite and navigate. A byte budget ensures the total injected context stays bounded.
Usage
Use this principle when:
- An agent needs to ground responses in retrieved code or documentation
- Retrieved snippets must carry provenance (file, line numbers) for citation
- Context injection must stay within a byte budget
Theoretical Basis
# Abstract algorithm (NOT real implementation)
def search_code(query, engine):
results = engine.retrieve(query) # hybrid retrieval
results = rerank(query, results) # deterministic reranking
results = mmr(results, lambda=0.7) # diversification
results = compress(results, byte_budget) # sentence-level trim
# Format as ToolOutput with source tags
return ToolOutput(text=format_snippets(results))
# Each snippet: "path/to/file.py:L42-80\n<code>"