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.
Prompt Chaining Example
See the complete source code on
GitHub.
agent.py
- 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.
- 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.
Parallelization Example
See the complete source code on
GitHub.
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.
- The
run_agent
function enables remote invocation of agents through ACP. - The aggregator agent invokes both
translation_french
andtranslation_spanish
in parallel usingasyncio.gather