Skip to content

Code Improvements and allow managers without ´args´ - #3

Merged
Baraujo25 merged 1 commit into
mainfrom
TOOLS_IMPROVEMENTS
Nov 7, 2025
Merged

Code Improvements and allow managers without ´args´#3
Baraujo25 merged 1 commit into
mainfrom
TOOLS_IMPROVEMENTS

Conversation

@3dgiordano

Copy link
Copy Markdown
Collaborator

In models with non-reasoning capabilities or that don't adhere to pydantic's specification rules, allowing the args parameter to be null and initializing it is a better option for managers that don't have arguments.
This improves the potential for retries in pydantic due to errors that occur when the tool is incorrectly called by the AI ​​because it follows the text specification but not the formal schema specification.
This would be a good idea to replicate as a pattern for other or future MCPs.

I proceeded to create utility files for each type of manager that needed them. This way, managers retain only the minimum logic, and the rest is delegated to their specific utility files.

This allows for smaller managers and avoids having a single utility file for all managers when specific logic is required.

Comment thread tools/device_manager.py
Comment on lines -80 to +84
args: Dict[str, Any] = Field(description="Dictionary with parameters"),
args: Dict[str, Any] = Field(description="Dictionary with parameters", default=None),
ctx: Context = Field(description="Context object providing access to MCP capabilities")
) -> BaseResult:

if args is None:
args = {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What about

args: Dict[str, Any] = Field(description="Dictionary with parameters", default={})

, does it work? It could avoid us setting None, conditional (if args is None) and then setting {}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If it does work, maybe we could impact the change in all tools, what do you think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I mentioned this when I share the PR link.

"There's an issue there which is the comparison of whether arg is None and is initialized as dict; the default of pydantic has other mechanisms but they are convoluted, this method at least is visually clear."

There are some problems in pydantic to be able to do it as you mention, there are also other ways to do it in pydantic but it requires unnecessary over-engineering.

@Baraujo25
Baraujo25 merged commit 46642ac into main Nov 7, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants