-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouting_agent.py
More file actions
59 lines (48 loc) · 2.38 KB
/
routing_agent.py
File metadata and controls
59 lines (48 loc) · 2.38 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
# TODO: 1 - Import the KnowledgeAugmentedPromptAgent and RoutingAgent
from workflow_agents.base_agents import KnowledgeAugmentedPromptAgent
from workflow_agents.base_agents import RoutingAgent
import os
from dotenv import load_dotenv
# Load environment variables from .env file
load_dotenv()
openai_api_key = os.getenv("OPENAI_API_KEY")
persona = "You are a college professor"
knowledge = "You know everything about Texas"
# TODO: 2 - Define the Texas Knowledge Augmented Prompt Agent
texas_knowledge_agent = KnowledgeAugmentedPromptAgent(openai_api_key, persona, knowledge)
knowledge = "You know everything about Europe"
# TODO: 3 - Define the Europe Knowledge Augmented Prompt Agent
europe_knowledge_agent = KnowledgeAugmentedPromptAgent(openai_api_key, persona, knowledge)
persona = "You are a college math professor"
knowledge = "You know everything about math, you take prompts with numbers, extract math formulas, and show the answer without explanation"
# TODO: 4 - Define the Math Knowledge Augmented Prompt Agent
math_knowledge_agent = KnowledgeAugmentedPromptAgent(openai_api_key, persona, knowledge)
routing_agent = RoutingAgent(openai_api_key, {})
agents = [
{
"name": "texas agent",
"description": "Answer a question about Texas",
# TODO: 5 - Call the Texas Agent to respond to prompts
"func": lambda x: f"Routing data: {texas_knowledge_agent.respond(x)}"
},
{
"name": "europe agent",
"description": "Answer a question about Europe",
# TODO: 6 - Define a function to call the Europe Agent
"func": lambda x: f"Routing data: {europe_knowledge_agent.respond(x)}"
},
{
"name": "math agent",
"description": "When a prompt contains numbers, respond with a math formula",
# TODO: 7 - Define a function to call the Math Agent
"func": lambda x: f"Routing data: {math_knowledge_agent.respond(x)}"
}
]
routing_agent.agents = agents
# TODO: 8 - Print the RoutingAgent responses to the following prompts:
# - "Tell me about the history of Rome, Texas"
# - "Tell me about the history of Rome, Italy"
# - "One story takes 2 days, and there are 20 stories"
print(routing_agent.route("Tell me about the history of Rome, Texas"))
print(routing_agent.route("Tell me about the history of Rome, Italy"))
print(routing_agent.route("One story takes 2 days, and there are 20 stories"))