Conversation
Implemented a logging wrapper system that automatically logs all tool calls with: - Tool name and parameters when called - Tool result when completed - Error information if tool fails This approach uses a decorator wrapper to add logging to all tools without requiring changes to individual tool implementations. The wrapper is applied via a custom tool decorator that wraps agent.tool registration. Benefits: - Centralized logging configuration - No modifications needed to existing tools - Consistent log format across all tools - Easy to maintain and extend
There was a problem hiding this comment.
Pull request overview
This PR implements a centralized logging wrapper system for all tool calls in the meshbot application. The approach uses a decorator pattern to automatically log tool invocations, results, and errors without requiring manual logging code in individual tool implementations. The logging provides consistent formatting with emojis and truncation for readability.
Key changes:
- New
logging_wrapper.pymodule with decorator functions that wrap tool calls with automatic logging - Updated all tool registration functions to use the logging decorator instead of
@agent.tooldirectly - Removed manual logging statements from individual tool functions
- Minor code formatting improvements in
storage.pyandmain.py
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/meshbot/tools/logging_wrapper.py | New module providing with_tool_logging decorator and create_logging_tool_decorator factory function |
| src/meshbot/tools/weather.py | Replaced @agent.tool with @tool() decorator and removed manual logging statements |
| src/meshbot/tools/utility.py | Applied logging wrapper to all 4 utility tools and removed manual logging |
| src/meshbot/tools/query.py | Applied logging wrapper to all query tools |
| src/meshbot/tools/fun.py | Applied logging wrapper to all fun tools |
| src/meshbot/tools/conversation.py | Applied logging wrapper to all conversation tools and removed manual logging |
| src/meshbot/storage.py | Code formatting improvements (line length compliance) |
| src/meshbot/main.py | Code formatting improvements (line length compliance) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| truncated_params[k] = v | ||
| params_str = f" with {truncated_params}" | ||
|
|
||
| logger.info(f"🔧 TOOL CALL: {tool_name}(){params_str}") |
There was a problem hiding this comment.
[nitpick] The logging format uses emoji symbols (🔧, ✅, ❌) which may not display correctly in all logging environments or terminals. Consider using plain text prefixes like '[TOOL_CALL]', '[TOOL_RESULT]', '[TOOL_ERROR]' for better compatibility, or make the emoji usage configurable.
| # Extract meaningful parameters (skip ctx and self) | ||
| params_str = "" | ||
| if kwargs: | ||
| # Filter out context and other internal params | ||
| display_params = { | ||
| k: v | ||
| for k, v in kwargs.items() | ||
| if k not in ["ctx", "self"] and not k.startswith("_") | ||
| } |
There was a problem hiding this comment.
The logging wrapper only extracts parameters from kwargs but ignores positional args. In the tools being wrapped, parameters are passed as keyword arguments, but if tools were called with positional arguments, those would not be logged. Consider also processing args or documenting that tools must use keyword arguments only.
Implemented a logging wrapper system that automatically logs all tool calls with:
This approach uses a decorator wrapper to add logging to all tools without requiring changes to individual tool implementations. The wrapper is applied via a custom tool decorator that wraps agent.tool registration.
Benefits: