You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
result=Runner.run_sync(first_agent, input="Hi, my name is Sora.")
68
+
69
+
print("Step 1 done")
70
+
71
+
# 2. Ask it to generate a number
72
+
result=Runner.run_sync(
73
+
first_agent,
74
+
input=result.to_input_list()
75
+
+ [{"content": "Can you generate a random number between 0 and 100?", "role": "user"}],
76
+
)
77
+
78
+
print("Step 2 done")
79
+
80
+
# 3. Call the second agent
81
+
result=Runner.run_sync(
82
+
second_agent,
83
+
input=result.to_input_list()
84
+
+ [
85
+
{
86
+
"content": "I live in New York City. Whats the population of the city?",
87
+
"role": "user",
88
+
}
89
+
],
90
+
)
91
+
92
+
print("Step 3 done")
93
+
94
+
# 4. Cause a handoff to occur
95
+
result=Runner.run_sync(
96
+
second_agent,
97
+
input=result.to_input_list()
98
+
+ [
99
+
{
100
+
"content": "Por favor habla en español. ¿Cuál es mi nombre y dónde vivo?",
101
+
"role": "user",
102
+
}
103
+
],
104
+
)
105
+
106
+
print("Step 4 done")
107
+
108
+
print("\n===Final messages===\n")
109
+
110
+
# 5. That should have caused spanish_handoff_message_filter to be called, which means the
111
+
# output should be missing the first two messages, and have no tool calls.
112
+
# Let's print the messages to see what happened
113
+
formessageinresult.to_input_list():
114
+
print(json.dumps(message, indent=2))
115
+
# tool_calls = message.tool_calls if isinstance(message, AssistantMessage) else None
116
+
117
+
# print(f"{message.role}: {message.content}\n - Tool calls: {tool_calls or 'None'}")
118
+
"""
119
+
$python examples/handoffs/message_filter.py
120
+
Step 1 done
121
+
Step 2 done
122
+
Step 3 done
123
+
Step 4 done
124
+
125
+
===Final messages===
126
+
127
+
{
128
+
"content": "Can you generate a random number between 0 and 100?",
129
+
"role": "user"
130
+
}
131
+
{
132
+
"id": "...",
133
+
"content": [
134
+
{
135
+
"annotations": [],
136
+
"text": "Sure! Here's a random number between 0 and 100: **42**.",
137
+
"type": "output_text"
138
+
}
139
+
],
140
+
"role": "assistant",
141
+
"status": "completed",
142
+
"type": "message"
143
+
}
144
+
{
145
+
"content": "I live in New York City. Whats the population of the city?",
146
+
"role": "user"
147
+
}
148
+
{
149
+
"id": "...",
150
+
"content": [
151
+
{
152
+
"annotations": [],
153
+
"text": "As of the most recent estimates, the population of New York City is approximately 8.6 million people. However, this number is constantly changing due to various factors such as migration and birth rates. For the latest and most accurate information, it's always a good idea to check the official data from sources like the U.S. Census Bureau.",
154
+
"type": "output_text"
155
+
}
156
+
],
157
+
"role": "assistant",
158
+
"status": "completed",
159
+
"type": "message"
160
+
}
161
+
{
162
+
"content": "Por favor habla en espa\u00f1ol. \u00bfCu\u00e1l es mi nombre y d\u00f3nde vivo?",
163
+
"role": "user"
164
+
}
165
+
{
166
+
"id": "...",
167
+
"content": [
168
+
{
169
+
"annotations": [],
170
+
"text": "No tengo acceso a esa informaci\u00f3n personal, solo s\u00e9 lo que me has contado: vives en Nueva York.",
0 commit comments