forked from openai/swarm
-
Notifications
You must be signed in to change notification settings - Fork 3
/
context_variables.py
38 lines (28 loc) · 966 Bytes
/
context_variables.py
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
from swarm import Swarm, Agent
client = Swarm()
def instructions(context_variables):
name = context_variables.get("name", "User")
return f"You are a helpful agent. Greet the user by name ({name})."
def print_account_details(context_variables: dict):
user_id = context_variables.get("user_id", None)
name = context_variables.get("name", None)
print(f"Account Details: {name} {user_id}")
return "Success"
agent = Agent(
name="Agent",
instructions=instructions,
functions=[print_account_details],
)
context_variables = {"name": "James", "user_id": 123}
response = client.run(
messages=[{"role": "user", "content": "Hi!"}],
agent=agent,
context_variables=context_variables,
)
print(response.messages[-1]["content"])
response = client.run(
messages=[{"role": "user", "content": "Print my account details!"}],
agent=agent,
context_variables=context_variables,
)
print(response.messages[-1]["content"])