-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
smolagents uses MCP Adapt to parse the tool definition, which for example gives the following JSON schema
'lifecycle_stage': {'anyOf': [{'enum': ['development',
'r_and_d',
'production',
'retired'],
'type': 'string'},
{'type': 'null'}],
'default': None,
'description': 'The lifecycle stage of the Software.',
'title': 'Lifecycle Stage',
'type': 'string'},
My type of this argument is Literal[...] | None. This type should be parsed to 'type' instead of anyOf.
MCPAdapt handles anyOf for some other frameworks, but not smolagents.
This is not that trivial because smolagents tool doesn't seem to support enum type.
Any ideas? So far I can only do my best post processing the schema.
This is what I have in my schema post processing:
properties = deepcopy(tool.inputs)
required = []
for key, value in properties.items():
if value["type"] == "any":
value["type"] = "string"
if not ("anyOf" in value and any(t["type"] == "null" for t in value["anyOf"])):
required.append(key)
# parse anyOf
if "anyOf" in value:
types = []
enum = None
for t in value["anyOf"]:
if t["type"] == "any":
types.append("string")
else:
types.append(t["type"])
if "enum" in t: # assuming there is only one enum in anyOf
enum = t["enum"]
value["type"] = types if len(types) > 1 else types[0]
if enum is not None:
value["enum"] = enum
value.pop("anyOf")And resulting:
'lifecycle_stage': {'default': None,
'description': 'The lifecycle stage of the AI system.',
'title': 'Lifecycle Stage',
'type': ['string', 'null'],
'enum': ['development',
'r_and_d',
'production',
'retired']},
Metadata
Metadata
Assignees
Labels
No labels