patricksamuel commited on
Commit
595a4a1
·
verified ·
1 Parent(s): 0888cfa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -185,17 +185,23 @@ When you've found the answer, stop reasoning and return ONLY the answer.
185
  model="gpt-4o-mini"
186
  )
187
 
188
- for update in Runner.run_streamed(my_agent, input=question, max_turns=25):
189
- if update.new_items:
190
- for step in update.new_items:
191
- print("🧠 Thought:", step.thought)
192
- print("⚙️ Action:", step.tool_call)
193
- print("🔍 Observation:", step.observation)
194
- print("-" * 50)
195
 
196
- # Final answer is in update.final_output (from the last loop iteration)
197
- print(f"Agent gave answer (first 50 chars): {update.final_output[:50]}...")
198
- return update.final_output
 
 
 
 
 
 
 
 
 
 
 
199
 
200
  # result = Runner.run_sync(
201
  # my_agent,
 
185
  model="gpt-4o-mini"
186
  )
187
 
188
+ import nest_asyncio
189
+ import asyncio
 
 
 
 
 
190
 
191
+ nest_asyncio.apply()
192
+
193
+ async def run_agent_streamed():
194
+ async for update in Runner.run_streamed(my_agent, input=question, max_turns=25):
195
+ if update.new_items:
196
+ for step in update.new_items:
197
+ print("🧠 Thought:", step.thought)
198
+ print("⚙️ Action:", step.tool_call)
199
+ print("🔍 Observation:", step.observation)
200
+ print("-" * 50)
201
+ print(f"Agent gave answer (first 50 chars): {update.final_output[:50]}...")
202
+ return update.final_output
203
+
204
+ result = await run_agent_streamed() # If already inside an async context
205
 
206
  # result = Runner.run_sync(
207
  # my_agent,