forked from hexo-ai/agent-from-scratch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsingle_agent_example.py
More file actions
37 lines (25 loc) · 1 KB
/
Copy pathsingle_agent_example.py
File metadata and controls
37 lines (25 loc) · 1 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
from dotenv import load_dotenv
_ = load_dotenv()
import json
from agent import pretty_print_messages, Agent, Swarm
def get_weather(location, time="now"):
return json.dumps({"location": location, "temperature": "65", "time": time})
def send_email(recipient, subject, body):
return f"Sent! email to {recipient} with the subject: {subject} and body: {body}"
weather_agent = Agent(
name="Weather Agent",
instructions="You are a helpful agent for giving information on weather.",
functions=[get_weather, send_email],
)
client = Swarm()
print("Starting Single Agent - Weather Agent")
print('Ask me how is the weather today in Brussels?')
messages = []
agent = weather_agent
while True:
user_input = input("\033[90mUser\033[0m: ")
messages.append({"role": "user", "content": user_input})
response = client.run(agent=agent, messages=messages)
pretty_print_messages(response.messages)
messages.extend(response.messages)
agent = response.agent