Support Anthropic conversation logging and retries
Tests / Test apps.device-host-agent.tests.test_mcp_token.test_load_or_create_concurrent_calls_do_not_corrupt failed

This commit is contained in:
showtan001
2026-08-30 22:29:19 +08:00
parent 44e1a6651a
commit 5458f3b8a4
4 changed files with 113 additions and 14 deletions
+16 -3
View File
@@ -444,9 +444,22 @@ def create_console_app(
]
if not messages:
raise HTTPException(status_code=400, detail="messages are invalid")
result = await asyncio.to_thread(
conversation_agent.chat_for_device, device_id.strip(), messages
)
if conversation_log is not None:
await asyncio.to_thread(
conversation_log.append,
{"type": "user_request", "device_id": device_id.strip(), "messages": messages},
)
try:
result = await asyncio.to_thread(
conversation_agent.chat_for_device, device_id.strip(), messages
)
except Exception as exc:
if conversation_log is not None:
await asyncio.to_thread(
conversation_log.append,
{"type": "agent_error", "device_id": device_id.strip(), "error": str(exc)},
)
raise HTTPException(status_code=502, detail=str(exc)) from exc
return JSONResponse(
{"content": result.content, "tool_calls": result.tool_calls}
)