mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-10-03 19:57:35 +00:00
fixes
This commit is contained in:
parent
139320e19f
commit
a78f981dbb
7 changed files with 91 additions and 199 deletions
120
docs/static/llama-stack-spec.html
vendored
120
docs/static/llama-stack-spec.html
vendored
|
@ -13069,12 +13069,57 @@
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Human-readable description of what the tool does"
|
"description": "Human-readable description of what the tool does"
|
||||||
},
|
},
|
||||||
"parameters": {
|
"input_schema": {
|
||||||
"type": "array",
|
"type": "object",
|
||||||
"items": {
|
"additionalProperties": {
|
||||||
"$ref": "#/components/schemas/ToolParameter"
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
},
|
},
|
||||||
"description": "List of parameters this tool accepts"
|
{
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"description": "JSON Schema for the tool's input parameters"
|
||||||
|
},
|
||||||
|
"output_schema": {
|
||||||
|
"type": "object",
|
||||||
|
"additionalProperties": {
|
||||||
|
"oneOf": [
|
||||||
|
{
|
||||||
|
"type": "null"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "boolean"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"description": "JSON Schema for the tool's output"
|
||||||
},
|
},
|
||||||
"metadata": {
|
"metadata": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
@ -13109,74 +13154,11 @@
|
||||||
"provider_id",
|
"provider_id",
|
||||||
"type",
|
"type",
|
||||||
"toolgroup_id",
|
"toolgroup_id",
|
||||||
"description",
|
"description"
|
||||||
"parameters"
|
|
||||||
],
|
],
|
||||||
"title": "Tool",
|
"title": "Tool",
|
||||||
"description": "A tool that can be invoked by agents."
|
"description": "A tool that can be invoked by agents."
|
||||||
},
|
},
|
||||||
"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."
|
|
||||||
},
|
|
||||||
"ToolGroup": {
|
"ToolGroup": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|
73
docs/static/llama-stack-spec.yaml
vendored
73
docs/static/llama-stack-spec.yaml
vendored
|
@ -9614,11 +9614,29 @@ components:
|
||||||
type: string
|
type: string
|
||||||
description: >-
|
description: >-
|
||||||
Human-readable description of what the tool does
|
Human-readable description of what the tool does
|
||||||
parameters:
|
input_schema:
|
||||||
type: array
|
type: object
|
||||||
items:
|
additionalProperties:
|
||||||
$ref: '#/components/schemas/ToolParameter'
|
oneOf:
|
||||||
description: List of parameters this tool accepts
|
- type: 'null'
|
||||||
|
- type: boolean
|
||||||
|
- type: number
|
||||||
|
- type: string
|
||||||
|
- type: array
|
||||||
|
- type: object
|
||||||
|
description: >-
|
||||||
|
JSON Schema for the tool's input parameters
|
||||||
|
output_schema:
|
||||||
|
type: object
|
||||||
|
additionalProperties:
|
||||||
|
oneOf:
|
||||||
|
- type: 'null'
|
||||||
|
- type: boolean
|
||||||
|
- type: number
|
||||||
|
- type: string
|
||||||
|
- type: array
|
||||||
|
- type: object
|
||||||
|
description: JSON Schema for the tool's output
|
||||||
metadata:
|
metadata:
|
||||||
type: object
|
type: object
|
||||||
additionalProperties:
|
additionalProperties:
|
||||||
|
@ -9638,53 +9656,8 @@ components:
|
||||||
- type
|
- type
|
||||||
- toolgroup_id
|
- toolgroup_id
|
||||||
- description
|
- description
|
||||||
- parameters
|
|
||||||
title: Tool
|
title: Tool
|
||||||
description: A tool that can be invoked by agents.
|
description: A tool that can be invoked by agents.
|
||||||
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.
|
|
||||||
ToolGroup:
|
ToolGroup:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
|
@ -48,14 +48,16 @@ class Tool(Resource):
|
||||||
:param type: Type of resource, always 'tool'
|
:param type: Type of resource, always 'tool'
|
||||||
:param toolgroup_id: ID of the tool group this tool belongs to
|
:param toolgroup_id: ID of the tool group this tool belongs to
|
||||||
:param description: Human-readable description of what the tool does
|
:param description: Human-readable description of what the tool does
|
||||||
:param parameters: List of parameters this tool accepts
|
:param input_schema: JSON Schema for the tool's input parameters
|
||||||
|
:param output_schema: JSON Schema for the tool's output
|
||||||
:param metadata: (Optional) Additional metadata about the tool
|
:param metadata: (Optional) Additional metadata about the tool
|
||||||
"""
|
"""
|
||||||
|
|
||||||
type: Literal[ResourceType.tool] = ResourceType.tool
|
type: Literal[ResourceType.tool] = ResourceType.tool
|
||||||
toolgroup_id: str
|
toolgroup_id: str
|
||||||
description: str
|
description: str
|
||||||
parameters: list[ToolParameter]
|
input_schema: dict[str, Any] | None = None
|
||||||
|
output_schema: dict[str, Any] | None = None
|
||||||
metadata: dict[str, Any] | None = None
|
metadata: dict[str, Any] | None = None
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -83,7 +83,8 @@ class ToolGroupsRoutingTable(CommonRoutingTableImpl, ToolGroups):
|
||||||
identifier=t.name,
|
identifier=t.name,
|
||||||
toolgroup_id=toolgroup.identifier,
|
toolgroup_id=toolgroup.identifier,
|
||||||
description=t.description or "",
|
description=t.description or "",
|
||||||
parameters=t.parameters or [],
|
input_schema=t.input_schema,
|
||||||
|
output_schema=t.output_schema,
|
||||||
metadata=t.metadata,
|
metadata=t.metadata,
|
||||||
provider_id=toolgroup.provider_id,
|
provider_id=toolgroup.provider_id,
|
||||||
)
|
)
|
||||||
|
|
|
@ -65,35 +65,10 @@ def convert_tooldef_to_chat_tool(tool_def):
|
||||||
from llama_stack.models.llama.datatypes import ToolDefinition
|
from llama_stack.models.llama.datatypes import ToolDefinition
|
||||||
from llama_stack.providers.utils.inference.openai_compat import convert_tooldef_to_openai_tool
|
from llama_stack.providers.utils.inference.openai_compat import convert_tooldef_to_openai_tool
|
||||||
|
|
||||||
# Build JSON Schema from tool parameters
|
|
||||||
properties = {}
|
|
||||||
required = []
|
|
||||||
|
|
||||||
for param in tool_def.parameters:
|
|
||||||
param_schema = {
|
|
||||||
"type": param.parameter_type,
|
|
||||||
"description": param.description,
|
|
||||||
}
|
|
||||||
if param.default is not None:
|
|
||||||
param_schema["default"] = param.default
|
|
||||||
if param.items is not None:
|
|
||||||
param_schema["items"] = param.items
|
|
||||||
|
|
||||||
properties[param.name] = param_schema
|
|
||||||
|
|
||||||
if param.required:
|
|
||||||
required.append(param.name)
|
|
||||||
|
|
||||||
input_schema = {
|
|
||||||
"type": "object",
|
|
||||||
"properties": properties,
|
|
||||||
"required": required,
|
|
||||||
}
|
|
||||||
|
|
||||||
internal_tool_def = ToolDefinition(
|
internal_tool_def = ToolDefinition(
|
||||||
tool_name=tool_def.name,
|
tool_name=tool_def.name,
|
||||||
description=tool_def.description,
|
description=tool_def.description,
|
||||||
input_schema=input_schema,
|
input_schema=tool_def.input_schema,
|
||||||
)
|
)
|
||||||
return convert_tooldef_to_openai_tool(internal_tool_def)
|
return convert_tooldef_to_openai_tool(internal_tool_def)
|
||||||
|
|
||||||
|
@ -546,33 +521,10 @@ class StreamingResponseOrchestrator:
|
||||||
from llama_stack.providers.utils.inference.openai_compat import convert_tooldef_to_openai_tool
|
from llama_stack.providers.utils.inference.openai_compat import convert_tooldef_to_openai_tool
|
||||||
|
|
||||||
def make_openai_tool(tool_name: str, tool: Tool) -> ChatCompletionToolParam:
|
def make_openai_tool(tool_name: str, tool: Tool) -> ChatCompletionToolParam:
|
||||||
# Build JSON Schema from tool parameters
|
|
||||||
properties = {}
|
|
||||||
required = []
|
|
||||||
|
|
||||||
for param in tool.parameters:
|
|
||||||
param_schema = {
|
|
||||||
"type": param.parameter_type,
|
|
||||||
"description": param.description,
|
|
||||||
}
|
|
||||||
if param.default is not None:
|
|
||||||
param_schema["default"] = param.default
|
|
||||||
|
|
||||||
properties[param.name] = param_schema
|
|
||||||
|
|
||||||
if param.required:
|
|
||||||
required.append(param.name)
|
|
||||||
|
|
||||||
input_schema = {
|
|
||||||
"type": "object",
|
|
||||||
"properties": properties,
|
|
||||||
"required": required,
|
|
||||||
}
|
|
||||||
|
|
||||||
tool_def = ToolDefinition(
|
tool_def = ToolDefinition(
|
||||||
tool_name=tool_name,
|
tool_name=tool_name,
|
||||||
description=tool.description,
|
description=tool.description,
|
||||||
input_schema=input_schema,
|
input_schema=tool.input_schema,
|
||||||
)
|
)
|
||||||
return convert_tooldef_to_openai_tool(tool_def)
|
return convert_tooldef_to_openai_tool(tool_def)
|
||||||
|
|
||||||
|
@ -659,16 +611,11 @@ class StreamingResponseOrchestrator:
|
||||||
MCPListToolsTool(
|
MCPListToolsTool(
|
||||||
name=t.name,
|
name=t.name,
|
||||||
description=t.description,
|
description=t.description,
|
||||||
input_schema={
|
input_schema=t.input_schema
|
||||||
|
or {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {},
|
||||||
p.name: {
|
"required": [],
|
||||||
"type": p.parameter_type,
|
|
||||||
"description": p.description,
|
|
||||||
}
|
|
||||||
for p in t.parameters
|
|
||||||
},
|
|
||||||
"required": [p.name for p in t.parameters if p.required],
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -68,9 +68,7 @@ public class FunctionTagCustomToolGenerator {
|
||||||
{
|
{
|
||||||
"name": "{{t.tool_name}}",
|
"name": "{{t.tool_name}}",
|
||||||
"description": "{{t.description}}",
|
"description": "{{t.description}}",
|
||||||
"parameters": {
|
"input_schema": { {{t.input_schema}} }
|
||||||
"type": "dict",
|
|
||||||
"properties": { {{t.parameters}} }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{{/let}}
|
{{/let}}
|
||||||
|
|
|
@ -110,18 +110,6 @@ def _convert_to_vllm_tools_in_request(tools: list[ToolDefinition]) -> list[dict]
|
||||||
compat_tools = []
|
compat_tools = []
|
||||||
|
|
||||||
for tool in tools:
|
for tool in tools:
|
||||||
properties = {}
|
|
||||||
compat_required = []
|
|
||||||
if tool.parameters:
|
|
||||||
for tool_key, tool_param in tool.parameters.items():
|
|
||||||
properties[tool_key] = {"type": tool_param.param_type}
|
|
||||||
if tool_param.description:
|
|
||||||
properties[tool_key]["description"] = tool_param.description
|
|
||||||
if tool_param.default:
|
|
||||||
properties[tool_key]["default"] = tool_param.default
|
|
||||||
if tool_param.required:
|
|
||||||
compat_required.append(tool_key)
|
|
||||||
|
|
||||||
# The tool.tool_name can be a str or a BuiltinTool enum. If
|
# The tool.tool_name can be a str or a BuiltinTool enum. If
|
||||||
# it's the latter, convert to a string.
|
# it's the latter, convert to a string.
|
||||||
tool_name = tool.tool_name
|
tool_name = tool.tool_name
|
||||||
|
@ -133,10 +121,11 @@ def _convert_to_vllm_tools_in_request(tools: list[ToolDefinition]) -> list[dict]
|
||||||
"function": {
|
"function": {
|
||||||
"name": tool_name,
|
"name": tool_name,
|
||||||
"description": tool.description,
|
"description": tool.description,
|
||||||
"parameters": {
|
"parameters": tool.input_schema
|
||||||
|
or {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": properties,
|
"properties": {},
|
||||||
"required": compat_required,
|
"required": [],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue