Merge branch 'feature/agent-final-answer-first-char' into staging

This commit is contained in:
csh28 2026-05-11 21:29:07 +08:00
commit d0480cca1b
3 changed files with 12 additions and 3 deletions

View File

@ -1,6 +1,7 @@
"""Logging callback handler module."""
import logging
import traceback
from typing import Any, Optional, Dict, List
from langchain_core.callbacks import BaseCallbackHandler
from langchain_core.messages import BaseMessage
@ -80,4 +81,8 @@ class LoggingCallbackHandler(BaseCallbackHandler):
self, error: Exception, **kwargs: Any
) -> None:
"""Called when a tool invocation raises an error."""
self.logger.error(f"❌ Tool Error: {error}")
self.logger.error(
"❌ Tool Error: %s\n%s",
repr(error),
"".join(traceback.format_exception(type(error), error, error.__traceback__)),
)

View File

@ -78,6 +78,7 @@ async def _call_tool_with_meta_compat(self: ClientSession, *args: Any, **kwargs:
result = await self.send_request(
types.ClientRequest(
types.CallToolRequest(
method="tools/call",
params=types.CallToolRequestParams(
name=name,
arguments=arguments,

View File

@ -3,6 +3,7 @@ import os
import asyncio
import shutil
import time
import traceback
from typing import Union, Optional, Any, List, Dict
from fastapi import APIRouter, HTTPException, Header, Body
from fastapi.responses import StreamingResponse
@ -185,9 +186,11 @@ async def enhanced_generate_stream_response(
await output_queue.put(("agent_done", None))
except Exception as e:
logger.error(f"Error in agent task: {e}")
logger.error(f"Error in agent task: {e}\n{traceback.format_exc()}")
# Send error information to the client
await output_queue.put(("agent", f'data: {{"error": "{str(e)}"}}\n\n'))
await output_queue.put(
("agent", f"data: {json.dumps({'error': str(e)}, ensure_ascii=False)}\n\n")
)
# Send completion signal to ensure the output controller exits normally
await output_queue.put(("agent_done", None))