Skip to content

Conversation

@duguyue100
Copy link
Contributor

@duguyue100 duguyue100 commented Aug 22, 2025

Smolagents uses MCPAdapt, one problem is that it doesn't handle anyOf field from the input schema.

To mitigate this problem, I expanded get_tool_json_schema function that parses the argument properly.

Here is an example of before and after the change:
Before:

    'lifecycle_stage': {'anyOf': [{'enum': ['development',
        'ideation',
        'r_and_d',
        'testing',
        'production',
        'retired'],
       'type': 'string'},
      {'type': 'null'}],
     'default': None,
     'description': 'The lifecycle stage of the Software.',
     'title': 'Lifecycle Stage',
     'type': 'string'},

After

    'lifecycle_stage': {'default': None,
     'description': 'The lifecycle stage of the Software',
     'title': 'Lifecycle Stage',
     'type': 'string',
     'nullable': True,
     'enum': ['development',
      'ideation',
      'r_and_d',
      'testing',
      'production',
      'retired']},

if enum is not None:
value["enum"] = enum

value.pop("anyOf")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why this .pop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we parse anyOf, keeping it then results duplicated information. That's why we just pop the key after parsing it.

if t["type"] == "null":
continue
if t["type"] == "any":
types.append("string")
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have a type "any", why not use it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please check line 247, this is how we parse Any all along, i'm just following the current practice here.

enum = None
for t in value["anyOf"]:
if t["type"] == "null":
continue
Copy link
Collaborator

Choose a reason for hiding this comment

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

We have type "null", why not use it?

Copy link
Contributor Author

@duguyue100 duguyue100 Oct 13, 2025

Choose a reason for hiding this comment

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

This is covered by the nullable part above

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