Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions app/modules/intelligence/agents/chat_agents/pydantic_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,27 @@


def handle_exception(tool_func):
@functools.wraps(tool_func)
def wrapper(*args, **kwargs):
try:
return tool_func(*args, **kwargs)
except Exception:
# Use Loguru's native exception() with context kwargs
logger.exception("Exception in tool function", tool_name=tool_func.__name__)
return "An internal error occurred. Please try again later."
if inspect.iscoroutinefunction(tool_func):
@functools.wraps(tool_func)
async def async_wrapper(*args, **kwargs):
try:
return await tool_func(*args, **kwargs)
except Exception as e:
# Log full stack trace for debugging
logger.exception("Exception in async tool function", tool_name=tool_func.__name__)
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard Python logging module's exception() method doesn't accept keyword arguments like tool_name. This will raise a TypeError at runtime. Instead, include the tool name in the message string itself.

Copilot uses AI. Check for mistakes.
return f"Tool execution error: {e!s}"
return async_wrapper
else:
@functools.wraps(tool_func)
def sync_wrapper(*args, **kwargs):
try:
return tool_func(*args, **kwargs)
except Exception as e:
# Log full stack trace for debugging
logger.exception("Exception in sync tool function", tool_name=tool_func.__name__)
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard Python logging module's exception() method doesn't accept keyword arguments like tool_name. This will raise a TypeError at runtime. Instead, include the tool name in the message string itself.

Copilot uses AI. Check for mistakes.
return f"Tool execution error: {e!s}"

return wrapper
return sync_wrapper


class PydanticRagAgent(ChatAgent):
Expand Down