fix: guard optional agent thought payloads

This commit is contained in:
-LAN- 2025-11-03 12:47:28 +08:00
parent 67cdd72563
commit a38425e7b5
No known key found for this signature in database
GPG Key ID: 6BA0D108DED011FF
1 changed files with 18 additions and 8 deletions

View File

@ -346,7 +346,8 @@ class BaseAgentRunner(AppRunner):
raise ValueError("agent thought not found")
if thought:
agent_thought.thought += thought
existing_thought = agent_thought.thought or ""
agent_thought.thought = f"{existing_thought}{thought}"
if tool_name:
agent_thought.tool = tool_name
@ -449,14 +450,23 @@ class BaseAgentRunner(AppRunner):
tools = tools.split(";")
tool_calls: list[AssistantPromptMessage.ToolCall] = []
tool_call_response: list[ToolPromptMessage] = []
try:
tool_inputs = json.loads(agent_thought.tool_input)
except Exception:
tool_input_payload = agent_thought.tool_input
if tool_input_payload:
try:
tool_inputs = json.loads(tool_input_payload)
except Exception:
tool_inputs = {tool: {} for tool in tools}
else:
tool_inputs = {tool: {} for tool in tools}
try:
tool_responses = json.loads(agent_thought.observation)
except Exception:
tool_responses = dict.fromkeys(tools, agent_thought.observation)
observation_payload = agent_thought.observation
if observation_payload:
try:
tool_responses = json.loads(observation_payload)
except Exception:
tool_responses = dict.fromkeys(tools, observation_payload)
else:
tool_responses = dict.fromkeys(tools, observation_payload)
for tool in tools:
# generate a uuid for tool call