feat(tools)!: substantial clean up of "Tool" related datatypes (#3627)

This is a sweeping change to clean up some gunk around our "Tool"
definitions.

First, we had two types `Tool` and `ToolDef`. The first of these was a
"Resource" type for the registry but we had stopped registering tools
inside the Registry long back (and only registered ToolGroups.) The
latter was for specifying tools for the Agents API. This PR removes the
former and adds an optional `toolgroup_id` field to the latter.

Secondly, as pointed out by @bbrowning in
https://github.com/llamastack/llama-stack/pull/3003#issuecomment-3245270132,
we were doing a lossy conversion from a full JSON schema from the MCP
tool specification into our ToolDefinition to send it to the model.
There is no necessity to do this -- we ourselves aren't doing any
execution at all but merely passing it to the chat completions API which
supports this. By doing this (and by doing it poorly), we encountered
limitations like not supporting array items, or not resolving $refs,
etc.

To fix this, we replaced the `parameters` field by `{ input_schema,
output_schema }` which can be full blown JSON schemas.

Finally, there were some types in our llama-related chat format
conversion which needed some cleanup. We are taking this opportunity to
clean those up.

This PR is a substantial breaking change to the API. However, given our
window for introducing breaking changes, this suits us just fine. I will
be landing a concurrent `llama-stack-client` change as well since API
shapes are changing.
This commit is contained in:
Ashwin Bharambe 2025-10-02 15:12:03 -07:00 committed by GitHub
parent 1f5003d50e
commit ef0736527d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
179 changed files with 34186 additions and 9171 deletions

View file

@ -3143,6 +3143,10 @@ components:
ToolDef:
type: object
properties:
toolgroup_id:
type: string
description: >-
(Optional) ID of the tool group this tool belongs to
name:
type: string
description: Name of the tool
@ -3150,12 +3154,30 @@ components:
type: string
description: >-
(Optional) Human-readable description of what the tool does
parameters:
type: array
items:
$ref: '#/components/schemas/ToolParameter'
input_schema:
type: object
additionalProperties:
oneOf:
- type: 'null'
- type: boolean
- type: number
- type: string
- type: array
- type: object
description: >-
(Optional) List of parameters this tool accepts
(Optional) JSON Schema for tool inputs (MCP inputSchema)
output_schema:
type: object
additionalProperties:
oneOf:
- type: 'null'
- type: boolean
- type: number
- type: string
- type: array
- type: object
description: >-
(Optional) JSON Schema for tool outputs (MCP outputSchema)
metadata:
type: object
additionalProperties:
@ -3174,50 +3196,6 @@ components:
title: ToolDef
description: >-
Tool definition used in runtime contexts.
ToolParameter:
type: object
properties:
name:
type: string
description: Name of the parameter
parameter_type:
type: string
description: >-
Type of the parameter (e.g., string, integer)
description:
type: string
description: >-
Human-readable description of what the parameter does
required:
type: boolean
default: true
description: >-
Whether this parameter is required for tool invocation
items:
type: object
description: >-
Type of the elements when parameter_type is array
title:
type: string
description: (Optional) Title of the parameter
default:
oneOf:
- type: 'null'
- type: boolean
- type: number
- type: string
- type: array
- type: object
description: >-
(Optional) Default value for the parameter if not provided
additionalProperties: false
required:
- name
- parameter_type
- description
- required
title: ToolParameter
description: Parameter definition for a tool.
TopKSamplingStrategy:
type: object
properties:
@ -3630,33 +3608,6 @@ components:
title: BuiltinTool
- type: string
arguments:
oneOf:
- type: string
- type: object
additionalProperties:
oneOf:
- type: string
- type: integer
- type: number
- type: boolean
- type: 'null'
- type: array
items:
oneOf:
- type: string
- type: integer
- type: number
- type: boolean
- type: 'null'
- type: object
additionalProperties:
oneOf:
- type: string
- type: integer
- type: number
- type: boolean
- type: 'null'
arguments_json:
type: string
additionalProperties: false
required: