Compose Agents
Learn how to build common composition patterns
ACP is designed to be agnostic regarding the internal implementation details of agents. It provides a standardized interface that facilitates communication between agents, enabling seamless composition.
The protocol emphasizes the importance of patterns over frameworks, echoing sentiments expressed in Anthropic’s insightful article.
Central to ACP’s composability are its message structure and agent execution model. A consistent message format and the capability to invoke agents remotely are crucial for effective composition.
Let’s explore the implementation of some patterns using ACP.
Example: Prompt Chaining
See the complete source code on GitHub.
Using ACP, prompt chaining can be implemented easily by sequentially running multiple agents and combining their outputs.
The following example demonstrates chaining two agents sequentially: first, an agent generates a punchy headline for a product; next, another agent translates the headline into Spanish. Finally, the composition agent combines these results and returns them to the client.
Key points:
- While the example uses a single ACP server to expose multiple agents for simplicity, practical implementations may involve distributed architectures.
- The
run_agent
function enables remote invocation of agents through ACP. - While the current example demonstrates agents that only accept and produce text, practical implementations may include more sophisticated use cases involving various types of artifacts.
Example: Routing
See the complete source code on GitHub.
Routing is a concept where a router (often an LLM) determines which agent should handle a particular request.
The following example illustrates routing by exposing ACP agents as tools to a router agent. The router agent evaluates the original request and forwards it to the appropriate agent based on its assessment.
Key points:
- The
run_agent
function enables remote invocation of agents through ACP. - The router agent is provided with a
TranslationTool
, which can invoke bothtranslation_french
andtranslation_spanish
agents via ACP by usingrun_agent
. - Based on the user’s input, the router decides which agent to invoke to fulfill the user’s request.