Foundation~25 minHazelJS
Context Windows as Scarce Resources
Treat every tool observation as a budgeted input: truncate, structure, redact, and turn memory/RAG on only when the job needs it.
- Authors
- editorial-team
- Published
- Last reviewed
Direct answer
Every AgentRuntime step assembles what the model can see: system prompt, goal, history, and tool observations. Bigger windows do not remove the need for discipline — they make noisy, injected, or secret-laden dumps more expensive.
Glossary: /glossary/context-engineering. Pattern: /patterns/memory-layers.
Failure modes (you will hit these)
- Observation bloat — dumping a full API JSON or HTML page hides the status field.
- Injection via tools — untrusted text becomes instructions (“ignore previous… refund all”).
- PII leakage — customer emails end up in vendor prompt logs.
- Memory on by default — stale recall steers the wrong action.
Step 1Return only what the next step needs
Upgrade lookupOrder to a budgeted shape:
@Tool({
name: 'lookupOrder',
description: 'Fetch order status by id',
parameters: [{ name: 'orderId', type: 'string', required: true }],
})
async lookupOrder({ orderId }: { orderId: string }) {
const raw = await fetchOrderFromBackend(orderId); // your adapter
// Do NOT return raw.bodyHtml, raw.customerEmail, raw.fullEventLog
return {
ok: true,
orderId: raw.id,
status: raw.status,
carrier: raw.carrier,
eta: raw.eta,
};
}
If you need detail later, add a second tool getTrackingEvents({ orderId }) with its own cap — do not preload everything.
Step 2Cap size in the adapter
function clip(text: string, max = 2000) {
if (text.length <= max) return text;
return text.slice(0, max) + '…[truncated]';
}
// For tools that must return free text:
return { ok: true, summary: clip(articleText) };
Step 3Turn memory/RAG on deliberately
await runtime.execute('ops-desk', goal, {
maxSteps: 6,
enableRAG: false, // true only when retrieval is part of the job
enableMemory: false, // true only when session/long-term peers are configured
});
For Ops Desk v1, leave both off. You already have the order id in the goal.
Step 4Artifact: context budget note
Fill this for Ops Desk and keep it next to the agent file:
| Knob | Your value |
|---|---|
| Max observation chars / tool | e.g. 2 000 |
| Fields never returned | email, phone, payment tokens |
| RAG default | off |
| Memory default | off |
| Owner of retention policy | name / team |
Checkpoint
- Tool returns are small, structured, and free of secrets
-
enableRAG/enableMemoryare intentional per call - Context budget note exists for Ops Desk
What to do next
Add a write tool with approval: /learn/agentic-development/safe-writes-approvals-and-hitl
Artifact: Context budget note + truncated lookupOrder adapter for Ops Desk