JasonFinley0821 commited on
Commit
31481c9
·
1 Parent(s): 604ac28

feat: try fix

Browse files
Files changed (1) hide show
  1. services/agents.py +14 -3
services/agents.py CHANGED
@@ -305,10 +305,21 @@ def format_agent_result(result):
305
  }
306
 
307
  elif isinstance(msg, ToolMessage):
308
- output["tool_result"] = json.loads(msg.content)
 
 
 
309
 
310
  elif isinstance(msg, AIMessage) and not msg.additional_kwargs.get("function_call"):
311
- output["final_response"] = msg.content
 
 
 
 
 
 
 
 
312
 
313
  return output
314
 
@@ -322,5 +333,5 @@ def run_agent(user_input: str):
322
 
323
  output_format = format_agent_result( result )
324
  print(f"output_format:{output_format}")
325
-
326
  return { "output": output_format }
 
305
  }
306
 
307
  elif isinstance(msg, ToolMessage):
308
+ try:
309
+ output["tool_result"] = json.loads(msg.content)
310
+ except Exception:
311
+ output["tool_result"] = msg.content # 若非 JSON
312
 
313
  elif isinstance(msg, AIMessage) and not msg.additional_kwargs.get("function_call"):
314
+ # 如果是 list of dict(如 [{'type': 'text','text':...}])
315
+ if isinstance(msg.content, list):
316
+ # 只取第一個 text
317
+ if len(msg.content) > 0 and "text" in msg.content[0]:
318
+ output["final_response"] = msg.content[0]["text"]
319
+ else:
320
+ output["final_response"] = str(msg.content)
321
+ else:
322
+ output["final_response"] = msg.content
323
 
324
  return output
325
 
 
333
 
334
  output_format = format_agent_result( result )
335
  print(f"output_format:{output_format}")
336
+
337
  return { "output": output_format }