import asyncio
from timbal import Agent, Workflow
from timbal.state import get_run_context
classifier = Agent(
name="classifier",
model="openai/gpt-5-mini",
system_prompt="Classify the message as 'technical' or 'billing'. One word only.",
max_tokens=64,
)
technical_agent = Agent(
name="technical_agent",
model="anthropic/claude-sonnet-4-6",
system_prompt="You are a technical support specialist.",
max_tokens=1024,
)
billing_agent = Agent(
name="billing_agent",
model="openai/gpt-5-mini",
system_prompt="You are a billing support specialist.",
max_tokens=1024,
)
workflow = (
Workflow(name="support_router")
.step(classifier)
.step(
technical_agent,
when=lambda: "technical"
in get_run_context().step_span("classifier").output.collect_text().lower(),
)
.step(
billing_agent,
when=lambda: "billing"
in get_run_context().step_span("classifier").output.collect_text().lower(),
)
)
async def main():
result = await workflow(prompt="I can't access my account after the upgrade").collect()
print(result.output.collect_text())
asyncio.run(main())