Agents and Memory
Environment + tools + a model that plans: how to build one, break it and measure it.
Shape
- Agent = environment + actions (tools); the model plans, acts, and decides when it's done. RAG is an agent whose tools are retrievers.
- Workflow (Anthropic): LLM calls on code paths you wrote. Agent: the model picks the path. Start with the simplest thing that works.
- Compounding: n steps at per-step accuracy p → pn. 95% × 10 steps ≈ 60%; × 100 steps ≈ 0.6%.
Tools
| Kind | Examples |
|---|---|
| Knowledge augmentation (read) | Retrievers, SQL, internal APIs, web search |
| Capability extension (read) | Calculator, converters, code interpreter, image generator, OCR |
| Write actions | Send email, update DB, payments, merge code: gate with human approval |
- Function calling: declare name + parameters + description → model returns a tool call → your code executes → result goes back in context.
- Tool choice:
required(must call) ·none·auto(model decides). - APIs can check the function exists, not that values are right: log every call's parameters.
- Lethal trifecta (Willison): private data + untrusted content + external communication. Never all three.
- Better tool use: better descriptions and examples, simpler tools (split them), poka-yoke arguments (e.g. absolute paths), stronger model, finetune.
- Pick tools by ablation: remove one; if scores don't drop, drop it.
Plan → validate → execute → reflect
- Decouple planning from execution. Validate with heuristics (only known tools, ≤ N steps) or an AI judge.
- Humans can write, approve, or execute any step; define the automation level per action.
- ReAct: Thought → Act → Observation, repeated until Finish. Reflexion: evaluator + self-reflection before the next attempt. Cost: tokens and latency.
- Plans in natural language survive tool renames but need a translator to executable calls.
- Control flows: sequential, parallel, if, loop. Parallel cuts latency.
Failure modes → what to measure
| Failure | Example |
|---|---|
| Planning: invalid tool | bing_search when only web_search exists |
| Planning: invalid parameters | send_email(attachment=…), no such argument |
| Planning: wrong parameter values | lbs_to_kg(lbs=100) for 120 lb |
| Planning: goal failure | Trip plan over the $5,000 budget; finished after the deadline |
| Planning: reflection error | 40 of 50 people roomed, “Done!” |
| Tool failure | SQL generator writes the wrong year; missing a tool the task needs |
| Efficiency | Correct, but too many steps, too much cost or time |
Metrics: % valid plans, plans needed per valid plan, % valid tool calls, rate of each failure, steps / cost / time per task vs. a baseline.
Memory
| Mechanism | Is | For |
|---|---|---|
| Internal knowledge | Weights | Needed by every task (change via finetuning) |
| Short-term | Context window | This task, right now |
| Long-term | External store + retrieval | Rare or cross-session information |
- Management = add + delete in short-term memory; overflow goes to long-term.
- FIFO is simple but can drop the first messages, which often hold the goal. Better: summaries (+ named entities), or reflection that inserts, merges or replaces.