AB
AiBoss
Tutorials

Claude has officially released the "Agent Building Guide" (Chinese version).

This article summarizes Anthropic's annual work and design principles in building large-scale language models (LLMs) and agents. Written by Anthropic, the article covers the characteristics of successful solutions, intelligent...

Claude 官方发布《Agent 构建指南》(中文版)

This article mainly discusses Anthropic's work in building large-scale language models.LLM)andintelligentbodyAnnual summary and design principles for (agents). This article, written by Anthropic, includes...Characteristics of a successful solution,intelligentbodyDefinition,When to useintelligentbody,Framework usage,Modules and Workflows,Workflow pattern,intelligentbodyApplication scenariosas well asPractical CasesSections such as [list of sections]. The article emphasizes [the following].SimpleThe importance of sexiness, transparency, and a well-designed agent-computer interface (ACI), and providing best practices and plug-in tools for tool development.Prompt wordsDetailed project information. Based on the above, Anthropic shares how to build valuable...intelligentbodyand provide for developerspracticalThe suggestion.

December 20, 2024

Over the past year, Anthropic has collaborated with multiple industry teams to build large-scale language models.LLMThe most successful solutions don't use complex frameworks or specialized software packages. Instead, they use...SimpleIt is built from composable modules. In this article, Anthropic shares lessons learned from working with clients and building its own agents, and offers developers advice on how to build effective agents.

What isAgent?

What isAgent?Agent"It can have multiple definitions. Some clients will..."AgentDefined as fully autonomous systems, they can operate independently for extended periods and use various tools to accomplish complex tasks. Others...AgentThe description is that it follows a predefined workflow and is more conforming to standards. At Anthropic, all these variations are categorized as...Proxy systemButWorkflowandactingAn important architectural difference was drawn between them:

  • WorkflowyesLLMA system that orchestrates tools based on predefined code paths.
  • actingyesLLMA system that dynamically plans its processes and tools and controls how tasks are completed.

Below, we will discuss these two types of agent systems in detail. (See Appendix 1, "In Practice")AgentIn the article, "The 'Information on the Use of Systems by Customers'", two areas were highlighted where customers found these systems particularly valuable.

When (and when not) to useAgent?

In constructionLLMWhen using applications, it is recommended to look for as many as possible.SimpleThe solution is to add complexity only when necessary. This might mean not building a proxy system at all. Proxy systems often incur delays and costs for better task performance, and the trade-offs need to be considered.

When more complexity is required, workflows offer predictability and consistency for well-defined tasks, while at the expense of large-scale flexibility and model-driven decision-making,AgentThat's a better choice. However, for many applications, optimizing a single...LLMInvocation, along with retrieval and contextual examples, is usually sufficient.

When and how to use the framework?

Many frameworks can make proxy systems easier to implement, including:

These frameworks simplify the invocation.LLM,fastWriting and parsing standardized low-level tasks such as related tool plugins and chained calls simplifies the operation process. However, these create additional layers of abstraction, which may obscure the underlying prompts and responses, making debugging more difficult. They may also make it harder for developers to...SimpleThis increases the complexity of the task when the settings can be completed.

We recommend that developers use it directly first.LLM API: Many common patterns can be implemented with just a few lines of code. If you do want to use a framework, ensure you understand the underlying code. Incorrect assumptions about the underlying mechanisms are a common source of errors for clients.

View ourOfficial ManualTo obtain some example implementations.

Build modules, workflows, and proxies

This section will explore common patterns in agent systems encountered in production. We will start with the basic building blocks—enhanced...LLMStart by gradually increasing the complexity, fromSimpleThe combined workflow is transferred to the autonomous agent.

Modules: EnhancedLLM

The basic building blocks of the agent system are enhanced through features such as retrieval, tools, and memory.LLMThe current model canautomaticUse these capabilities effectively—autonomously generate search queries, select appropriate tools, and decide which information to retain.

We recommend focusing on two key aspects of implementation: tailoring specific use cases to the use case and ensuring that...LLMsupplySimpleFurthermore, it has a well-documented interface. While there are many ways to implement these enhancements, one approach is to use Anthropic's recently released model.Context Protocol(Model Context Protocol), which allows developers to...SimpleofClient-side implementationIt integrates with a variety of third-party tools that leverage this protocol.

In the remainder of this article, it will be assumed that each timeLLMThese enhanced capabilities can be accessed through any call.

Workflow: Hint Chain Workflow

A cue chain breaks a task down into a series of steps, each of which...LLMThe call processes the output of the previous call. You can add programmatic checks (see "gate" in the diagram below) at any intermediate step to ensure the process proceeds as expected.

  • Applicable ScenariosThis workflow is ideal for scenarios where tasks can be easily and clearly broken down into fixed subtasks. The main objective is to make each...LLMCalls become easier, allowing for trade-offs between response speed and higher accuracy.
  • Example of using hint chains:
    • Generate marketing copy and then translate it into different languages.
    • Write an outline for the document, check that the outline meets certain standards, and then write the document based on the outline.

    Workflow: Routing Workflow

    Routing categorizes inputs and directs them to subsequent specialized tasks. Workflows allow for the separation of concerns and the construction of more specialized hints. Without such workflows, optimizations for one type of input might harm the performance of others.

    • Applicable ScenariosRouting is suitable for complex tasks that have clear categories, are suitable for separate processing, and whose classification can be determined by...LLMOr more traditional classification models/algorithms can handle it accurately.
    • Applicable examples:
      • Guide different types of customer service inquiries (general questions, refund requests, technical support) to different downstream processes, prompts, and tools.
      • WillSimpleCommon problems are routed to smaller models, such asClaude 3.5 Haiku, routing difficult/unusual problems to more...powerfulThe model, such asClaude 3.5 Sonnet, optimized for cost and speed.

      Workflow: Parallelized Workflow

      LLMSometimes a task can be completed simultaneously, and its output can be programmatically aggregated. This workflow now exists in two key variants:

      • Sectioning (task decomposition): Decompose a task into independent subtasks that run in parallel.
      • Voting: Running the same task multiple times to get different outputs.
      • Applicable ScenariosParallelization is effective when the divided subtasks can be parallelized to improve speed, or when multiple perspectives are needed to obtain more reliable results. For complex tasks with multiple considerations, each consideration is handled separately.LLMDuring call processing,LLMThey performed better.
      • Applicable examples:
        • Sectioning (task breakdown):
          • In a security setup, one model handles user queries, while another filters for inappropriate content or requests. This is generally better than having the same model handle user queries.LLMSimultaneous invocation of security protection and core response performs better.
          • automaticChemical assessment is used to evaluateLLMPerformance given prompts, eachLLMIt is used to evaluate different aspects of model performance.
          • Review the code for vulnerabilities, and if you find any issues, review and flag the code with multiple different prompts.
          • To assess whether the given content is inappropriate, use multiple prompts to evaluate different aspects or set different voting thresholds to balance the accuracy of the test.

          Workflow: Coordinator-Executor Workflow

          In a coordinator-executor workflow, a central...LLMDynamically decompose tasks and delegate them to workers. LLMs (workers)LLM), and take their results into account.

          • Applicable ScenariosThis approach is suitable for complex tasks where the required subtasks cannot be predicted (e.g., in coding, the number of files that need to be changed and the changes within each file may depend on the task itself). While its flowchart is similar to Parallelization, the key difference is its greater flexibility—the subtasks are not predefined but determined by the Orchestrator based on specific inputs.
          • Applicable examples:
            • Encoded products that make complex changes to multiple files each time.
            • Search tasks involve collecting and analyzing information from multiple sources to find potentially relevant information.

            Workflow: Evaluator-Optimizer Workflow

            In this workflow, oneLLMOne function is responsible for generating the response, while another provides evaluation and feedback in a loop.

            • Applicable ScenariosThis workflow is particularly effective when there are clear evaluation criteria and the value of iterative refinement can be measured. Good adaptability has two hallmarks: first, when humans express feedback...LLMThe response can be significantly improved; secondly,LLMIt can provide such feedback. This is similar to the iterative writing process that human writers may go through when crafting a refined document.
            • Applicable examples:
              • Literary translation, including some subtle aspects of translation.LLMIt might not be captured initially, but assessmentLLMWe can provide helpful suggestions for improvement.
              • Complex search tasks require multiple rounds of searching and analysis to gather comprehensive information, and are responsible for evaluation. LLM Decide whether further searching is needed.

              acting

              along withLLMWith the maturation of key capabilities such as understanding complex inputs, reasoning and planning, using tools, and correcting errors, agents began to emerge in production.

              The agent's work begins with commands from a human user or through interactive discussions. Once the task is defined, the agent plans and acts independently, possibly asking the human for more information or judgment. During execution, it is crucial for the agent to obtain "real-world" information (such as tool call results or code execution) from the environment at each step to assess its progress. The agent can then pause to obtain human feedback when encountering obstacles. Tasks typically terminate upon completion, but often include termination conditions (such as a maximum number of iterations) to maintain control.

              Agents can handle complex tasks, but their implementation is usually very...SimpleThey typically use tools in a loop based solely on environmental feedback.LLMTherefore, a well-designed and clear toolset and documentation are essential. Appendix 2 ("Prompt "Engineering your Tools" details best practices for tool development.

              (Self-operated agency)

              • Applicable ScenariosAgents can be used for open problems where the number of steps required is difficult or impossible to predict and where a fixed path cannot be specified.LLMMultiple loops may run, and you must have a certain degree of trust in its decision-making capabilities. The agent's autonomy makes it particularly ideal for performing tasks in a trusted environment. However, the agent's autonomy also means higher costs and the potential for accumulating errors. Extensive testing in a sandbox environment with appropriate security measures is recommended.
              • Applicable examples: Here are some examples from our own implementation:

                (Advanced process of encoding agent)

                These paradigms are not strictly defined. They are common patterns that developers can build upon and combine to adapt to different use cases. And anyLLMWith the same functionality, the key to success is measuring performance and iterating on implementation. To reiterate: only consider adding complexity when it significantly improves results.

                existLLMSuccess in any field isn't about building the most complex systems, but about building the right systems for the needs.SimpleThe prompt begins, followed by comprehensive evaluation and optimization, only when more...SimpleA multi-step proxy system is only added when the solution provided is insufficient.

                When implementing the proxy, we try to follow three core principles:

                • Ensure the agent designSimple.
                • Prioritize by clearly showing the agent's planning steps.transparency.
                • Through comprehensive toolsDocumentation and TestsCarefully craft your Agent-Computer Interface (ACI) interface.

                Frameworks can help youfastGet started with basic components, but when moving to production, don't hesitate to reduce abstraction layers and build using fundamental components whenever possible. By following these principles, you can create more than just basic components.powerfulMoreover, it is a reliable, maintainable, and trusted agent.

                Acknowledgments

                Written by Erik Schluntz and Barry Zhang. This work draws on our experience building proxies at Anthropic and valuable insights shared by our clients, for which we are deeply grateful.

                GetAgent Original PDF file of the "Building Guide"Scan the QR code to follow and reply:241222

                Appendix 1: Agents in Practice

                Our collaboration with our clients revealsAITwo particularly promising applications of agents demonstrate the practical value of the aforementioned model. Both applications illustrate that agents are most valuable for tasks requiring dialogue and action, with clear success criteria, feedback loops, and the integration of valuable human oversight.

                A. Customer Support

                Customer support incorporates a familiar chatbot interface and is enhanced through tool integrations. This is a natural scenario for a more open agency because:

                • It follows a dialogue flow, allowing for natural interaction, while also requiring access to external information and operations;
                • Tools can be integrated to extract customer data, order history, and knowledge base articles;
                • Operations such as issuing refunds or updating work orders can be processed in a procedural manner;
                • By using user-defined solutions, we can explicitly measure whether agents have solved the problem.

                Some companies have demonstrated the viability of this approach through usage-based pricing models that charge only for successful solutions, showcasing confidence in the effectiveness of their agents.

                B. Encoding Agent

                The software development field showsLLMThe significant potential of this functionality lies in its evolution from code completion to autonomous problem-solving. Delegates are particularly effective because:

                • The solution to the code problem can be achieved throughautomaticVerification was performed using chemical testing.
                • Agents can use test results as feedback to iterate on solutions;
                • The problem is well-defined and structured;
                • Output quality can be objectively measured.

                In our own implementation, the proxy is based onSWE-bench verificationThe benchmark can solve real-world GitHub questions independently. However, despite...automaticWhile functional testing helps verify functionality, human review remains crucial to ensure that the solution meets broader system requirements.

                Appendix 2: Tips for your tools

                Regardless of the type of proxy system you are building, tool plugins are likely to be an important part of your proxy. Tools enable...ClaudeWe can interact with external services and APIs by specifying their exact structure and definition in our API.ClaudeWhen responding, if it plans to invoke a tool, it will include a [missing information] in the API response.Tool usage blockTool definitions and specifications should receive the same level of attention as overall tooltips in terms of tooltips engineering. This brief appendix describes how to perform tooltips engineering.

                There are typically several ways to specify the same operation. For example, file editing can be specified by writing a diff or rewriting the entire file. For structured output, code can be returned in Markdown or JSON. In software engineering, these diffs are superficial and can be converted from one format to another without loss of quality.

                However, some formats are forLLMIt's more difficult to write in JSON than other formats. Writing diffs requires knowing how many lines in the block header are changing before writing new code. Writing code in JSON (compared to Markdown) requires additional escaping for line breaks and quotes.

                Our recommendations for deciding on the tool format are as follows:

                • Give the model enough tokens to "think" before it gets into a dead end.
                • Maintain a format similar to text that appears naturally on the Internet.
                • Ensure there is no formatting "overhead," such as having to accurately calculate thousands of lines of code or perform string escaping on any code it writes.

                One rule of thumb is to invest the same amount of effort in creating a good Agent-Computer Interface (ACI) as you do in Human-Computer Interface (HCI). Here are some ideas on how to do this:

                • Put yourself in the model's shoes. Based on the description and parameters, is the use of this tool obvious, or does it require careful consideration? A good tool definition typically includes example usage, boundary cases, input format requirements, and clear boundaries with other tools.
                • How can I change parameter names or descriptions to make the task more obvious? Think of it like writing easy-to-read documentation for your team's junior developers. This is especially important when using many similar tools.
                • How to test the model using your tools: in ourworkbenchRun multiple sample inputs on it to find out what mistakes the model made and iterate.
                • Implement for your toolsError prevention measuresChange the parameters to make it harder to make mistakes.

                In constructionSWE-benchWhen using proxies, Anthropic actually spends more time optimizing tools than optimizing overall suggestions. For example, Anthropic found that models would throw errors when using tools with relative file paths, especially after the proxy was moved out of the root directory. To resolve this, the tools were changed to always require absolute file paths, and we found that the models used this approach perfectly.

                How to use Tencent Hunyuan video generation model: firsthand testing

                How to useAILearn how to make a Zen Master video in three steps!