Fix agui tool call args being a json string

This commit is contained in:
Yiorgis Gozadinos 2025-12-16 15:32:10 +02:00
parent 218126de8d
commit 9818cac4eb
No known key found for this signature in database
3 changed files with 9 additions and 3 deletions

View file

@ -1,6 +1,7 @@
"""Interactive CLI chat loop for research graph with human-in-the-loop.""" """Interactive CLI chat loop for research graph with human-in-the-loop."""
import asyncio import asyncio
import json
from pydantic_ai import Agent from pydantic_ai import Agent
from rich.console import Console from rich.console import Console
@ -225,7 +226,8 @@ async def run_interactive_research(
pass pass
elif event_type == "TOOL_CALL_ARGS": elif event_type == "TOOL_CALL_ARGS":
args = event.get("delta", {}) delta = event.get("delta", "{}")
args = json.loads(delta) if isinstance(delta, str) else delta
original_question = args.get("original_question", "") original_question = args.get("original_question", "")
sub_questions = list(args.get("sub_questions", [])) sub_questions = list(args.get("sub_questions", []))
qa_responses = args.get("qa_responses", []) qa_responses = args.get("qa_responses", [])

View file

@ -289,10 +289,12 @@ def emit_tool_call_args(tool_call_id: str, args: dict[str, Any]) -> dict[str, An
Returns: Returns:
ToolCallArgs event dict ToolCallArgs event dict
""" """
import json
return { return {
"type": "TOOL_CALL_ARGS", "type": "TOOL_CALL_ARGS",
"toolCallId": tool_call_id, "toolCallId": tool_call_id,
"delta": args, "delta": json.dumps(args),
} }

View file

@ -160,12 +160,14 @@ def test_emit_tool_call_start_with_parent():
def test_emit_tool_call_args(): def test_emit_tool_call_args():
"""Test TOOL_CALL_ARGS event creation.""" """Test TOOL_CALL_ARGS event creation."""
import json
args = {"query": "test query", "limit": 10} args = {"query": "test query", "limit": 10}
event = emit_tool_call_args("call-1", args) event = emit_tool_call_args("call-1", args)
assert event["type"] == "TOOL_CALL_ARGS" assert event["type"] == "TOOL_CALL_ARGS"
assert event["toolCallId"] == "call-1" assert event["toolCallId"] == "call-1"
assert event["delta"] == args assert event["delta"] == json.dumps(args)
def test_emit_tool_call_end(): def test_emit_tool_call_end():