Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -319,26 +319,41 @@ async def run_query(query: str):
|
|
| 319 |
handler = web_agent.run(query, ctx=ctx)
|
| 320 |
|
| 321 |
# Stream content
|
| 322 |
-
full_response = ""
|
| 323 |
async for event in handler.stream_events():
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
if isinstance(event, AgentStream):
|
| 325 |
# This is the text being generated
|
| 326 |
-
if event.delta:
|
| 327 |
yield event.delta
|
|
|
|
| 328 |
elif isinstance(event, ToolCall):
|
| 329 |
-
#
|
| 330 |
-
tool_name =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
yield f"\n\n🔧 Using tool: {tool_name}...\n"
|
|
|
|
| 332 |
elif isinstance(event, ToolCallResult):
|
| 333 |
-
#
|
| 334 |
-
|
| 335 |
-
tool_name = "the tool"
|
| 336 |
-
if hasattr(event, "parent_id") and event.parent_id:
|
| 337 |
-
# This might help identify the parent tool call
|
| 338 |
-
tool_name = f"tool {event.parent_id}"
|
| 339 |
|
| 340 |
-
#
|
| 341 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
|
| 343 |
# Truncate long results for display
|
| 344 |
if isinstance(result, str) and len(result) > 200:
|
|
@@ -346,10 +361,13 @@ async def run_query(query: str):
|
|
| 346 |
else:
|
| 347 |
result_preview = str(result)
|
| 348 |
|
| 349 |
-
yield f"\n📊 Got result from
|
| 350 |
|
| 351 |
except Exception as e:
|
| 352 |
-
yield f"\n\n❌ Error: {str(e)}"
|
|
|
|
|
|
|
|
|
|
| 353 |
finally:
|
| 354 |
instrumentor.flush()
|
| 355 |
|
|
|
|
| 319 |
handler = web_agent.run(query, ctx=ctx)
|
| 320 |
|
| 321 |
# Stream content
|
|
|
|
| 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 |
+
# Handle ToolCall differently - check available attributes
|
| 334 |
+
tool_name = "unknown tool"
|
| 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 |
+
# Handle ToolCallResult - check available attributes
|
| 348 |
+
result = "Result not available"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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:
|
|
|
|
| 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 |
|