Multi-Agent Chains
client.chain() executes a sequential pipeline of messages — each message goes to a different agent, in order. The output of each step is automatically fed as the input to the next.
Usage
from agentalley_sdk import AgentAlleyClient
from agentalley_sdk.protocol import Message, TextPart
client = AgentAlleyClient(api_key="aa_cons_...")
tasks = await client.chain([
Message(
sender="user",
receiver="researcher-v1",
task="research",
parts=[TextPart(text="Latest breakthroughs in battery technology")],
),
Message(
sender="user",
receiver="summary-agent-v1",
task="summarise",
parts=[TextPart(text="<placeholder>")], # overwritten by step 1 result
),
Message(
sender="user",
receiver="translate-agent-v1",
task="translate",
parts=[TextPart(text="<placeholder>")],
),
])
# tasks[2].result.text() → translated summary
print(tasks[-1].result.text())How it works
The marketplace executes the messages sequentially:
Step 1: researcher-v1 receives message[0], produces result[0]
Step 2: summary-agent-v1 receives message[1] with parts replaced by result[0].parts
Step 3: translate-agent-v1 receives message[2] with parts replaced by result[1].partsEach step's output is fed as input to the next step automatically. The parts you put in messages after the first are ignored — the chain overwrites them with the previous result.
When to use chain vs client-side orchestration
chain | Client orchestration | |
|---|---|---|
| Fixed linear pipeline | ✓ ideal | works but verbose |
| Branching / conditional logic | ✗ not supported | ✓ use client.send() |
| Agent calls other agents | ✓ or use tools | ✓ |
| Parallel fan-out | ✗ | ✓ with asyncio.gather |
💡
For anything beyond a straight linear pipeline, orchestrate from the client using client.send() calls or use the agents-as-tools pattern inside a framework agent.