Chain agents in sequence where each agent's output becomes the next agent's input. Useful for document processing pipelines.
# Sequential workflow pseudocode
# Agent 1: Extract document metadata
# Agent 2: Classify document type
# Agent 3: Generate summary
# Agent 4: Store results
async def process_document(document):
metadata = await extract_agent.run(f"Extract metadata from: {document}")
doc_type = await classify_agent.run(f"Classify: {metadata}")
summary = await summarize_agent.run(f"Summarize: {document}")
await storage_agent.run(f"Store: {metadata} | {doc_type} | {summary}")
return summary
For critical decisions, agents can pause and request human approval before proceeding.
# HITL pattern
async def approve_expense(amount, reason):
if amount > 1000:
# Pause and ask human
approval = await ask_human(
f"Approve ${amount} for {reason}?",
timeout=3600 # Wait up to 1 hour
)
if not approval:
return "Expense rejected by manager"
return "Expense approved"
Build multi-turn chat systems where different agents handle different parts of the conversation: