Skip to main content
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. Rather than prescribing specific frameworks, ACP emphasizes patterns over frameworks, echoing sentiments expressed in Anthropic’s insightful article on building effective agents. 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.

When to Use Composition Patterns

  • Prompt Chaining: When you need sequential processing where each step builds on the previous output (writing → editing → translation).
  • Routing: When different request types need specialized handling (customer support routing to technical/billing/general agents).
  • Parallelization: When independent tasks can be processed simultaneously for faster results (generating multiple translations or analyses).
  • Hierarchical: When you need coordination between high-level planning and specialized execution agents.
Let’s explore the implementation of these patterns using ACP.

Prompt Chaining Example

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.
agent.py
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.

Intelligent Routing Example

See the complete source code on GitHub.
Routing enables dynamic agent selection based on request content. A router agent analyzes incoming requests and forwards them to the most appropriate specialist agent. The following example exposes 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 both translation_french and translation_spanish agents via ACP by using run_agent.
  • Based on the user’s input, the router decides which agent to invoke to fulfill the user’s request.

Parallelization Example

See the complete source code on GitHub.
Parallelization executes multiple agents simultaneously to reduce overall processing time. Use this pattern when you need the same input processed by different agents or when tasks are independent. This example uses asyncio.gather to execute multiple remote agent calls concurrently via ACP. The process then awaits both responses, effectively blocking until all agents return their results.
Key points:
  • The run_agent function enables remote invocation of agents through ACP.
  • The aggregator agent invokes both translation_french and translation_spanish in parallel using asyncio.gather