diff --git a/assistants/document-assistant/assistant/guidance/dynamic_ui_inspector.py b/assistants/document-assistant/assistant/guidance/dynamic_ui_inspector.py index 53a5657f..f12ffa16 100644 --- a/assistants/document-assistant/assistant/guidance/dynamic_ui_inspector.py +++ b/assistants/document-assistant/assistant/guidance/dynamic_ui_inspector.py @@ -103,8 +103,8 @@ async def get_dynamic_ui_state(context: ConversationContext) -> dict[str, Any]: with drive.open_file("ui_state.json") as f: ui_json = f.read().decode("utf-8") return json.loads(ui_json) - except (json.JSONDecodeError, FileNotFoundError) as e: - logger.error(f"Error reading dynamic UI state: {e}") + except (json.JSONDecodeError, FileNotFoundError): + logger.exception("Error reading dynamic UI state") return {} diff --git a/assistants/document-assistant/assistant/response/responder.py b/assistants/document-assistant/assistant/response/responder.py index 17902dea..b96d3021 100644 --- a/assistants/document-assistant/assistant/response/responder.py +++ b/assistants/document-assistant/assistant/response/responder.py @@ -516,8 +516,8 @@ def _override_edit_file_description(self, tools: list[ChatCompletionToolParam]) edit_tool["function"]["description"] = EDIT_TOOL_DESCRIPTION_HOSTED elif filesystem_root and edit_tool: edit_tool["function"]["description"] = EDIT_TOOL_DESCRIPTION_LOCAL - except Exception as e: - logger.error(f"Failed to override edit_file description: {e}") + except Exception: + logger.exception("Failed to override edit_file description") return tools return tools diff --git a/libraries/python/assistant-extensions/assistant_extensions/mcp/_client_utils.py b/libraries/python/assistant-extensions/assistant_extensions/mcp/_client_utils.py index 6e870d4e..57994fb6 100644 --- a/libraries/python/assistant-extensions/assistant_extensions/mcp/_client_utils.py +++ b/libraries/python/assistant-extensions/assistant_extensions/mcp/_client_utils.py @@ -165,9 +165,9 @@ async def connect_to_mcp_server_sse(client_settings: MCPClientSettings) -> Async yield client_session # Yield the session for use except ExceptionGroup as e: - logger.exception(f"TaskGroup failed in SSE client for {client_settings.server_config.key}: {e}") + logger.exception("TaskGroup failed in SSE client for %s", client_settings.server_config.key) for sub in e.exceptions: - logger.error(f"Sub-exception: {client_settings.server_config.key}: {sub}") + logger.exception("sub-exception: %s", client_settings.server_config.key, exc_info=sub) # If there's exactly one underlying exception, re-raise it if len(e.exceptions) == 1: raise e.exceptions[0] @@ -191,19 +191,18 @@ async def refresh_mcp_sessions(mcp_sessions: list[MCPSession], stack: AsyncExitS """ active_sessions = [] for session in mcp_sessions: - if not session.is_connected: - logger.info(f"Session {session.config.server_config.key} is disconnected. Attempting to reconnect...") - new_session = await reconnect_mcp_session(session.config, stack) - if new_session: - active_sessions.append(new_session) - else: - logger.error(f"Failed to reconnect MCP server {session.config.server_config.key}.") - else: + if session.is_connected: active_sessions.append(session) + continue + + logger.info(f"Session {session.config.server_config.key} is disconnected. Attempting to reconnect...") + new_session = await reconnect_mcp_session(session.config, stack) + active_sessions.append(new_session) + return active_sessions -async def reconnect_mcp_session(client_settings: MCPClientSettings, stack: AsyncExitStack) -> MCPSession | None: +async def reconnect_mcp_session(client_settings: MCPClientSettings, stack: AsyncExitStack) -> MCPSession: """ Attempt to reconnect to the MCP server using the provided configuration. Returns a new MCPSession if successful, or None otherwise. diff --git a/libraries/python/assistant-extensions/assistant_extensions/mcp/_openai_utils.py b/libraries/python/assistant-extensions/assistant_extensions/mcp/_openai_utils.py index f8491b88..21e10732 100644 --- a/libraries/python/assistant-extensions/assistant_extensions/mcp/_openai_utils.py +++ b/libraries/python/assistant-extensions/assistant_extensions/mcp/_openai_utils.py @@ -173,7 +173,7 @@ async def handle_message( try: return await self._message_handler(context, params) except Exception as e: - logger.error(f"Error handling sampling request: {e}") + logger.exception("Error handling sampling request") code = getattr(e, "status_code", 500) message = getattr(e, "message", "Error handling sampling request.") data = str(e)