Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -318,56 +318,25 @@ async def run_query(query: str):
|
|
318 |
# Start the handler
|
319 |
handler = web_agent.run(query, ctx=ctx)
|
320 |
|
321 |
-
#
|
322 |
async for event in handler.stream_events():
|
323 |
-
# Add some debugging info to understand event structure
|
324 |
-
# print(f"Event type: {type(event)}")
|
325 |
-
# print(f"Event attrs: {dir(event)}")
|
326 |
-
|
327 |
if isinstance(event, AgentStream):
|
328 |
-
# This is the text being generated
|
329 |
if hasattr(event, 'delta') and event.delta:
|
330 |
yield event.delta
|
331 |
|
|
|
|
|
332 |
elif isinstance(event, ToolCall):
|
333 |
-
#
|
334 |
-
|
335 |
-
|
336 |
-
# Try different possible attribute locations
|
337 |
-
if hasattr(event, 'name'):
|
338 |
-
tool_name = event.name
|
339 |
-
elif hasattr(event, 'function_name'):
|
340 |
-
tool_name = event.function_name
|
341 |
-
elif hasattr(event, 'tool_name'):
|
342 |
-
tool_name = event.tool_name
|
343 |
-
|
344 |
-
yield f"\n\n🔧 Using tool: {tool_name}...\n"
|
345 |
|
346 |
elif isinstance(event, ToolCallResult):
|
347 |
-
#
|
348 |
-
|
349 |
-
|
350 |
-
# Try different possible attribute locations
|
351 |
-
if hasattr(event, 'result'):
|
352 |
-
result = event.result
|
353 |
-
elif hasattr(event, 'output'):
|
354 |
-
result = event.output
|
355 |
-
elif hasattr(event, 'data') and hasattr(event.data, 'get'):
|
356 |
-
result = event.data.get("result", "")
|
357 |
-
|
358 |
-
# Truncate long results for display
|
359 |
-
if isinstance(result, str) and len(result) > 200:
|
360 |
-
result_preview = result[:200] + "... (truncated)"
|
361 |
-
else:
|
362 |
-
result_preview = str(result)
|
363 |
-
|
364 |
-
yield f"\n📊 Got result from tool\n"
|
365 |
|
366 |
except Exception as e:
|
367 |
yield f"\n\n❌ Error: {str(e)}\n"
|
368 |
-
# For debugging:
|
369 |
-
import traceback
|
370 |
-
yield f"Traceback: {traceback.format_exc()}"
|
371 |
finally:
|
372 |
instrumentor.flush()
|
373 |
|
|
|
318 |
# Start the handler
|
319 |
handler = web_agent.run(query, ctx=ctx)
|
320 |
|
321 |
+
# Just stream the text content naturally, with minimal additions
|
322 |
async for event in handler.stream_events():
|
|
|
|
|
|
|
|
|
323 |
if isinstance(event, AgentStream):
|
324 |
+
# This is the text being generated - pass it through directly
|
325 |
if hasattr(event, 'delta') and event.delta:
|
326 |
yield event.delta
|
327 |
|
328 |
+
# We can optionally add minimal annotations for tool calls and results
|
329 |
+
# But we'll keep it simple to avoid interfering with the agent's natural output
|
330 |
elif isinstance(event, ToolCall):
|
331 |
+
# We could optionally add a subtle marker here
|
332 |
+
pass # Or comment this out if you want nothing added
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
333 |
|
334 |
elif isinstance(event, ToolCallResult):
|
335 |
+
# We could optionally add a subtle marker here
|
336 |
+
pass # Or comment this out if you want nothing added
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
337 |
|
338 |
except Exception as e:
|
339 |
yield f"\n\n❌ Error: {str(e)}\n"
|
|
|
|
|
|
|
340 |
finally:
|
341 |
instrumentor.flush()
|
342 |
|