diff --git a/agent/logging_handler.py b/agent/logging_handler.py index c3e21e7..60aa886 100644 --- a/agent/logging_handler.py +++ b/agent/logging_handler.py @@ -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__)), + ) diff --git a/agent/mcp_trace_meta.py b/agent/mcp_trace_meta.py index 4e4b5c7..f28c260 100644 --- a/agent/mcp_trace_meta.py +++ b/agent/mcp_trace_meta.py @@ -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, diff --git a/routes/chat.py b/routes/chat.py index 275f6d0..fd5dc50 100644 --- a/routes/chat.py +++ b/routes/chat.py @@ -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))