patricksamuel commited on
Commit
6e11f00
·
verified ·
1 Parent(s): 5ea72fa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -191,21 +191,30 @@ When you've found the answer, stop reasoning and return ONLY the answer.
191
  )
192
 
193
  print("\n--- Intermediate Reasoning ---")
194
- final_answer = None
195
  stream = Runner.run_streamed(my_agent, input=question, max_turns=25)
196
 
197
- for event in stream:
198
- if event.thought:
199
- print("🧠 Thought:", event.thought)
200
- if event.tool_call:
201
- print("⚙️ Action:", event.tool_call)
202
- if event.observation:
203
- print("🔍 Observation:", event.observation)
204
- if event.final_output:
205
- print(f"✅ Final Answer: {event.final_output}")
206
- final_answer = event.final_output
207
-
208
- return final_answer
 
 
 
 
 
 
 
 
 
209
 
210
  # result = Runner.run_sync(
211
  # my_agent,
 
191
  )
192
 
193
  print("\n--- Intermediate Reasoning ---")
194
+
195
  stream = Runner.run_streamed(my_agent, input=question, max_turns=25)
196
 
197
+ for event in result.stream_events():
198
+ # We'll ignore the raw responses event deltas
199
+ if event.type == "raw_response_event":
200
+ continue
201
+ # When the agent updates, print that
202
+ elif event.type == "agent_updated_stream_event":
203
+ print(f"Agent updated: {event.new_agent.name}")
204
+ continue
205
+ # When items are generated, print them
206
+ elif event.type == "run_item_stream_event":
207
+ if event.item.type == "tool_call_item":
208
+ print("-- Tool was called")
209
+ elif event.item.type == "tool_call_output_item":
210
+ print(f"-- Tool output: {event.item.output}")
211
+ elif event.item.type == "message_output_item":
212
+ print(f"-- Message output:\n {ItemHelpers.text_message_output(event.item)}")
213
+ else:
214
+ pass # Ignore other event types
215
+
216
+ print(f"Agent gave answer (first 50 chars): {result.final_output[:50]}...")
217
+ return result.final_output
218
 
219
  # result = Runner.run_sync(
220
  # my_agent,