How to build an efficient agent: Anthropic official advice and practical guide

Anthropic official guide, revealing the secrets of building efficient agents.
Core content:
1. The difference and definition of Agent and Workflow
2. When to use agents and suggestions for choosing frameworks
3. 6 common patterns in practical applications
Anthropic officially released an article titled "How to Build Efficient Intelligent Agents".
This article is full of useful information and is well worth reading.
The article summarizes their experience in working with numerous cross-industry clients and shares their lessons learned and practical suggestions for developing intelligent agents.
Practice has proved that truly successful applications often adopt simple and composable models rather than complex frameworks .
It also summarizes 3 core principles and 6 common patterns.
The following are the key points I have compiled based on the original text.
The difference between Agent and Workflow
The words Agent and Workflow, as well as their corresponding Chinese translations, have been abused.
Therefore, before building an intelligent system, it is necessary to have a clear definition of it.
Within Anthropic, they are collectively referred to as Agentic Systems.
But there is a distinction in architecture:
Workflow: It is like a pre-set program that allows large models and various tools to run along a fixed path. Agents: More flexible! They can dynamically decide what to do next based on the situation. Such systems always maintain control while completing the task.
A clear definition is necessary to avoid inconsistent understanding among team members and reduce communication costs.
When (and when not) to use an agent
Advice: Look for the simplest solution possible and add complexity only when necessary .
This may mean that: many times, there is no need to build an agent system at all .
If the task is simple: directly call the big model API. If the task has higher complexity: Need more predictability and consistency? Use workflows. Need flexibility and model-driven decision making? Use agents.
For most applications, the task can be accomplished well by retrieving (Retrieval) and providing a few examples (Few-shots) for context.
Don't complicate the problem too early, start with the simplest .
When and how to use frameworks?
To implement an intelligent agent system, there are many frameworks that can be used, such as:
LangGraph Amazon Bedrock’s AI Agent framework Rivet Vellum
Although the framework provides us with convenience, it also brings complexity.
If you can directly call the large model API with a few lines of code, don't use a framework .
If you do use a framework, make sure you understand the underlying code behind it .
Common Patterns
In actual application scenarios, there are the following 6 common modes .
The augmented LLM : This is the most basic building block, an LLM enhanced with enhancements such as retrieval, tools, and memory. Prompt chaining : Chain multiple prompts together to allow LLM to complete the task step by step. Routing : Assign tasks to different tools or LLMs according to different situations. Parallelization : Run multiple tasks simultaneously to improve efficiency. Orchestrator-worker : A "coordinator" is responsible for assigning tasks, and multiple "workers" are responsible for execution. Evaluator-optimizer : An "evaluator" is responsible for evaluating the results, and an "optimizer" is responsible for improving them.
To learn more about the flowcharts and application scenarios of these patterns, please click ↙ “Read original text” at the end of the article.
Combine and customize these patterns
Many workflows may seem complex, but in reality, most are a combination of these patterns.
The patterns are not static and should be customized and combined according to actual scenarios.
? Key to success: Measure performance and continuously iterate on your implementation .
Adding complexity should only be considered if it significantly improves results .
When to use Agents
Open-ended problems where it is difficult or impossible to predict the number of steps required and you cannot hard-code a fixed path are good candidates for using agents.
Agents can handle complex tasks, but their implementations are often straightforward : they are often just large language models that use tools in a feedback loop based on the environment.
Therefore, it is critical to clearly and thoughtfully design the toolset and its documentation .
The autonomy of the agent implies higher costs and the potential for error exacerbation . Extensive testing in a sandbox environment with appropriate safeguards is recommended .
Anthropic provides the implementation code of two agents they have implemented themselves, one is SWE-bench tasks
, and the other is Computer Use
, there is a code link in the original text.
Pay equal attention to tool prompts
This part is in Appendix 2 of the article.
Tools are an important component of any intelligent agent being built.
Tool definitions and specifications should receive as much prompt engineering attention as the overall prompt word.
suggestion:
Give the model enough tokens to “think” before it gets stuck. Keep the format close to how the model would naturally appear in internet text. Make sure there is no "extra baggage" in terms of formatting, such as not having to accurately count thousands of lines of code or string escaping any code you write.
Rule of thumb:
When creating agent-computer interaction (ACI), the same effort should be put into human-computer interaction (HCI). That is, the same amount of effort should be put into ACI as into HCI.
Anthropic claims: They are building SWE-bench
During the process of the agent, more time is spent on optimizing the tool than on optimizing the overall prompt words .
Summarize
In the field of large models, the key to success is not to make the most complex system, but to make the right system that suits you .
Start with simple prompts, refine them through thorough evaluation, and add multi-step agents only when simpler solutions do not meet your needs to avoid unnecessary complexity that leads to issues such as higher latency, cost, and difficulty debugging.
Follow three core principles:
Keep it as simple as possible and avoid unnecessary complexity. Explicitly present the agent's planning steps, prioritizing transparency. The Agent-Computer Interface (ACI) is carefully crafted through detailed tool documentation and testing.
If an application that was quickly built using a framework earlier can be refactored to be implemented using basic components, you should do so without hesitation.