techlist.io

Tool Design

2 posts

Anthropic2025-09-295 min readCurated summary

Effective context engineering for AI agents

Anthropic argues that context engineering is the natural successor to prompt engineering. Instead of only writing better instructions, engineers must curate the full set of tokens an LLM sees during inference, because models have a finite "attention budget" that degrades as context grows. As agents run longer, they need strategies such as just-in-time retrieval, compaction, structured note-taking, and sub-agent architectures to keep that context small and high-signal. ## From Prompt Engineering to Context Engineering - Prompt engineering focuses on writing and organizing instructions, particularly system prompts. - Context engineering covers everything that lands in the context window during inference: system prompts, tools, external data, message history, and more. - Agents that run in loops generate new information every turn, so context must be continually curated and refined. ## Why Context Is a Finite Resource - **Context rot:** As the token count grows, a model's ability to accurately recall information from its context declines. This happens across all models, though degradation rates vary. - **Architectural limits:** Transformers let every token attend to every other token, creating n² pairwise relationships, which stretches attention thin as context grows. - **Training skew:** Models see shorter sequences more often in training, so they have less experience with long-range dependencies. - **Gradual degradation:** Techniques like position encoding interpolation extend context length with some loss in positional precision. The result is a performance gradient, not a hard cliff. ## Anatomy of Effective Context - **System prompts:** Aim for the "right altitude," between brittle hardcoded logic and vague high-level guidance. Organize sections with XML tags or Markdown headers, and start with a minimal prompt, then add instructions based on observed failures. - **Tools:** Keep tool sets minimal and non-overlapping, since a human who can't pick the right tool can't expect an agent to either. Tools should return token-efficient output and have clear, unambiguous parameters. - **Examples:** Curate a small set of diverse, canonical few-shot examples instead of listing every edge case in the prompt. ## Retrieval: From Pre-Loading to Just-in-Time Context - Anthropic defines an agent simply as "LLMs autonomously using tools in a loop." - Embedding-based retrieval before inference is common, but agents increasingly use "just-in-time" retrieval. They keep lightweight identifiers such as file paths, stored queries, or links, and load data on demand with tools. - Claude Code analyzes large databases by writing targeted queries and using commands like `head` and `tail`, without loading full datasets into context. - Metadata such as folder names, file names, and timestamps helps agents infer purpose and relevance. A `test_utils.py` in `tests/` means something different from one in `src/core_logic/`. - **Progressive disclosure:** Agents build understanding incrementally, with each step informing the next. - **Trade-offs:** Runtime exploration is slower and needs good tool design and heuristics, or agents can waste context on dead ends. - **Hybrid approach:** Claude Code drops `CLAUDE.md` files into context up front and uses `glob` and `grep` for on-demand retrieval. Less dynamic domains like legal or finance may suit this hybrid model well. ## Context Engineering for Long-Horizon Tasks Tasks like large migrations or extended research exceed the context window, so Anthropic recommends three techniques. Waiting for bigger windows isn't enough, since context pollution and relevance problems persist at every size. ### Compaction - Summarize a conversation nearing the context limit and start a new window with the summary. - Claude Code preserves architectural decisions, unresolved bugs, and implementation details, discards redundant tool outputs, and keeps the five most recently accessed files. - Tune the compaction prompt first for recall, then for precision. - **Tool result clearing** is a light-touch form of compaction: once a tool result is deep in history, the raw output is often no longer needed. ### Structured Note-Taking - The agent writes persistent notes outside the context window and reloads them later, such as a to-do list or a `NOTES.md` file. - Claude playing Pokémon tracked training progress over thousands of steps, mapped explored regions, and kept combat notes, then resumed multi-hour sequences after context resets. - The memory tool, released in public beta with Sonnet 4.5, supports file-based storage for knowledge that persists across sessions. ### Sub-agent Architectures - A lead agent coordinates a high-level plan while specialized sub-agents handle focused tasks in clean context windows. - Each sub-agent may use tens of thousands of tokens but returns a condensed summary, often 1,000–2,000 tokens. - This pattern substantially outperformed single-agent systems on complex research tasks. ### Choosing an Approach - **Compaction:** Extensive back-and-forth conversations. - **Note-taking:** Iterative development with clear milestones. - **Multi-agent architectures:** Complex research where parallel exploration pays off. ## Conclusion The guiding principle is to find the smallest set of high-signal tokens that makes the desired outcome most likely. Anthropic expects smarter models to need less prescriptive engineering, but treating context as a finite resource will stay central to building reliable agents. Its advice is to "do the simplest thing that works."

Anthropic2025-09-114 min readCurated summary

Writing effective tools for AI agents

# Designing Tools for AI Agents Tools for agents are a different kind of software: they form a contract between deterministic systems and non-deterministic agents, so they must be designed for how agents perceive and act, not simply wrapped around existing functions or APIs. The post argues that effective tools come from an evaluation-driven loop: build a quick prototype, measure it against realistic multi-step tasks, analyze agent transcripts, and iterate, often with agents like Claude Code doing the refactoring themselves. ## Building and Evaluating Tools - Prototype quickly by wrapping tools in a local MCP server or Desktop extension, connecting them to Claude Code (`claude mcp add`) or Claude Desktop, or passing them directly into API calls. - Provide LLM-friendly documentation (such as `llms.txt` files) to Claude when it helps write the tools. - Generate evaluation tasks grounded in realistic data and services, avoiding simplistic sandboxes. Strong tasks often require dozens of tool calls, while weak ones are single lookups. - Pair each task with a verifiable outcome, using exact matching or an LLM judge, and avoid verifiers that reject correct answers over formatting differences. - Run evaluations programmatically with simple agentic loops, one per task, and ask agents to output reasoning and feedback before their responses to encourage chain-of-thought behavior. - Track accuracy alongside runtime, total tool calls, token consumption, and tool errors. Frequent redundant calls can suggest consolidation opportunities. - Analyze transcripts for confusion, not just final answers, since agents often omit what matters most. Use held-out test sets to avoid overfitting. ## Choosing the Right Tools - Avoid tools that merely mirror API endpoints. Agents have limited context, so a `list_contacts` tool that dumps everything wastes it, while `search_contacts` returns only what's relevant. - Consolidate multi-step workflows into single tools, such as `schedule_event` instead of separate list and create calls, `search_logs` instead of `read_logs`, or `get_customer_context` instead of three separate lookups. - Give each tool a clear, distinct purpose, since overlapping tools distract agents from efficient strategies. ## Namespacing and Response Design - Group related tools under prefixes by service and resource (e.g., `asana_projects_search`) so agents can select the right tool. Prefix versus suffix choice affects results and should be tested per model. - Return high-signal fields like `name` or `file_type` rather than low-level identifiers like `uuid` or `mime_type`. Resolving UUIDs to human-readable identifiers reduced hallucinations in retrieval tasks. - Add a `response_format` enum (e.g., `concise` or `detailed`) so agents can choose between readable names and technical IDs needed for downstream calls. The post's example shows a 206-token detailed response versus a 72-token concise one. - Response structure (XML, JSON, Markdown) also affects performance, and the best choice varies by task and model. ## Token Efficiency and Error Handling - Use pagination, range selection, filtering, and truncation with sensible defaults. Claude Code caps tool responses at 25,000 tokens by default. - When truncating, guide agents toward efficient strategies, such as many small targeted searches instead of one broad search. - Write error messages that state specific, actionable fixes rather than opaque codes or tracebacks. ## Prompt-Engineering Tool Descriptions - Write descriptions as if onboarding a new hire, making implicit context explicit: query formats, niche terminology, and resource relationships. - Use unambiguous parameter names (`user_id` rather than `user`) and enforce inputs and outputs with strict data models. - Small description refinements can yield large gains. The post reports that precise description changes helped Claude Sonnet 3.5 reach state-of-the-art on SWE-bench Verified. - Tool annotations can disclose whether a tool needs open-world access or makes destructive changes. ## Conclusion Effective agent tools are clearly defined, use context judiciously, combine well across workflows, and let agents solve real tasks intuitively. Because the mechanisms agents use will keep evolving, a systematic, evaluation-driven process is the most reliable way to keep tools improving alongside the models that use them.