-
-
Notifications
You must be signed in to change notification settings - Fork 781
Expand file tree
/
Copy pathworkflow_routing.py
More file actions
65 lines (55 loc) · 1.82 KB
/
workflow_routing.py
File metadata and controls
65 lines (55 loc) · 1.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
"""
Agentic Routing Workflow Example
Demonstrates decision-based routing where an agent classifier
routes to specialized handler agents based on the request type.
"""
from praisonaiagents import Agent, Workflow
from praisonaiagents.workflows import route
# Create classifier agent
classifier = Agent(
name="Classifier",
role="Request Classifier",
goal="Classify incoming requests",
instructions="Classify the request. Respond with ONLY 'technical', 'creative', or 'general'."
)
# Create specialized handler agents
tech_agent = Agent(
name="TechExpert",
role="Technical Expert",
goal="Handle technical questions",
instructions="You are a technical expert. Provide detailed technical answers."
)
creative_agent = Agent(
name="CreativeWriter",
role="Creative Writer",
goal="Handle creative requests",
instructions="You are a creative writer. Write engaging, creative content."
)
general_agent = Agent(
name="GeneralAssistant",
role="General Assistant",
goal="Handle general requests",
instructions="You are a helpful assistant. Provide clear, helpful responses."
)
# Create workflow with routing
workflow = AgentFlow(
name="Agentic Router",
steps=[
classifier,
route({
"technical": [tech_agent],
"creative": [creative_agent],
"default": [general_agent]
})
]
)
if __name__ == "__main__":
print("=== Testing Agentic Routing Workflow ===\n")
# Test 1: Technical question
print("--- Technical Request ---")
result = workflow.start("How does machine learning work?")
print(f"Result: {result['output'][:200]}...\n")
# Test 2: Creative request
print("--- Creative Request ---")
result = workflow.start("Write a poem about the ocean")
print(f"Result: {result['output'][:200]}...")