forked from conductor-oss/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path08_router_agent.py
More file actions
83 lines (66 loc) · 2.82 KB
/
Copy path08_router_agent.py
File metadata and controls
83 lines (66 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Copyright (c) 2025 Agentspan
# Licensed under the MIT License. See LICENSE file in the project root for details.
"""Router Agent — LLM-based routing to specialists.
Demonstrates the router strategy where a dedicated router/classifier agent
decides which specialist sub-agent handles each request.
Architecture:
team (ROUTER, router=selector)
├── planner — design/architecture tasks
├── coder — implementation tasks
└── reviewer — code review tasks
The selector is a separate agent whose only job is routing.
It is NOT one of the specialist agents.
Requirements:
- Conductor server with LLM support
- AGENTSPAN_SERVER_URL=http://localhost:8080/api as environment variable
- AGENTSPAN_LLM_MODEL=openai/gpt-4o-mini as environment variable
"""
from conductor.ai.agents import Agent, AgentRuntime, Strategy
from settings import settings
# ── Specialist agents ───────────────────────────────────────────────
planner = Agent(
name="planner",
model=settings.llm_model,
instructions="You create implementation plans. Break down tasks into clear numbered steps.",
)
coder = Agent(
name="coder",
model=settings.llm_model,
instructions="You write code. Output clean, well-documented Python code.",
)
reviewer = Agent(
name="reviewer",
model=settings.llm_model,
instructions="You review code. Check for bugs, style issues, and suggest improvements.",
)
# ── Dedicated router/classifier (separate from specialists) ─────────
selector = Agent(
name="dev_team_selector",
model=settings.llm_model,
instructions=(
"You are a request classifier. Select the right specialist:\n"
"- planner: for design, architecture, or planning tasks\n"
"- coder: for writing or implementing code\n"
"- reviewer: for reviewing, auditing, or improving existing code"
),
)
# ── Router team ─────────────────────────────────────────────────────
team = Agent(
name="dev_team",
model=settings.llm_model,
agents=[planner, coder, reviewer],
strategy=Strategy.ROUTER,
router=selector, # dedicated classifier — not one of the specialists
)
if __name__ == "__main__":
with AgentRuntime() as runtime:
result = runtime.run(team, "Write a Python function to validate email addresses using regex")
result.print_result()
# Production pattern:
# 1. Deploy once during CI/CD:
# runtime.deploy(team)
# CLI alternative:
# agentspan deploy --package examples.08_router_agent
#
# 2. In a separate long-lived worker process:
# runtime.serve(team)