feat: RFC: tools API rework

# What does this PR do?
This PR proposes updates to the tools API in Inference and Agent.

Goals:
1. Agent's tool specification should be consistent with Inference's tool spec, but with add-ons.
2. Formal types should be defined for built in tools. Currently Agent tools args are untyped, e.g. how does one know that `builtin::rag_tool` takes a `vector_db_ids` param or even how to know 'builtin::rag_tool' is even available (in code, outside of docs)?

Inference:
1. BuiltinTool is to be removed and replaced by a formal `type` parameter.
2. 'brave_search' is replaced by 'web_search' to be more generic. It will still be translated back to brave_search when the prompt is constructed to be consistent with model training.
3. I'm not sure what `photogen` is. Maybe it can be removed?

Agent:
1. Uses the same format as in Inference for builtin tools.
2. New tools types are added, i.e. knowledge_sesarch (currently rag_tool), and MCP tool.
3. Toolgroup as a concept will be removed since it's really only used for MCP.
4. Instead MCPTool is its own type and available tools provided by the server will be expanded by default. Users can specify a subset of tool names if desired.

Example snippet:
```

agent = Agent(
    client,
    model=model_id,
    instructions="You are a helpful assistant. Use the tools you have access to for providing relevant answers.",
    tools=[
        KnowledgeSearchTool(vector_store_id="1234"),
        KnowledgeSearchTool(vector_store_id="5678", name="paper_search", description="Search research papers"),
        KnowledgeSearchTool(vector_store_id="1357", name="wiki_search", description="Search wiki pages"),
        # no need to register toolgroup, just pass in the server uri
        # all available tools will be used
        MCPTool(server_uri="http://localhost:8000/sse"),
        # can specify a subset of available tools
        MCPTool(server_uri="http://localhost:8000/sse", tool_names=["list_directory"]),
        MCPTool(server_uri="http://localhost:8000/sse", tool_names=["list_directory"]),
        # custom tool
        my_custom_tool,
    ]
)
```

## Test Plan
# What does this PR do?


## Test Plan
# What does this PR do?


## Test Plan
This commit is contained in:
Eric Huang 2025-03-26 11:14:40 -07:00
parent 39e094736f
commit 7027b537e0
22 changed files with 951 additions and 525 deletions

View file

@ -3798,6 +3798,21 @@
],
"title": "AppendRowsRequest"
},
"CodeInterpreterTool": {
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "code_interpreter",
"default": "code_interpreter"
}
},
"additionalProperties": false,
"required": [
"type"
],
"title": "CodeInterpreterTool"
},
"CompletionMessage": {
"type": "object",
"properties": {
@ -3837,6 +3852,34 @@
"title": "CompletionMessage",
"description": "A message containing the model's (assistant) response in a chat conversation."
},
"FunctionTool": {
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "function",
"default": "function"
},
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"parameters": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/ToolParamDefinition"
}
}
},
"additionalProperties": false,
"required": [
"type",
"name"
],
"title": "FunctionTool"
},
"GrammarResponseFormat": {
"type": "object",
"properties": {
@ -4138,25 +4181,21 @@
"ToolCall": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"function",
"web_search",
"wolfram_alpha",
"code_interpreter"
],
"title": "ToolType"
},
"call_id": {
"type": "string"
},
"tool_name": {
"oneOf": [
{
"type": "string",
"enum": [
"brave_search",
"wolfram_alpha",
"photogen",
"code_interpreter"
],
"title": "BuiltinTool"
},
{
"type": "string"
}
]
"type": "string"
},
"arguments": {
"oneOf": [
@ -4237,48 +4276,13 @@
},
"additionalProperties": false,
"required": [
"type",
"call_id",
"tool_name",
"arguments"
],
"title": "ToolCall"
},
"ToolDefinition": {
"type": "object",
"properties": {
"tool_name": {
"oneOf": [
{
"type": "string",
"enum": [
"brave_search",
"wolfram_alpha",
"photogen",
"code_interpreter"
],
"title": "BuiltinTool"
},
{
"type": "string"
}
]
},
"description": {
"type": "string"
},
"parameters": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/ToolParamDefinition"
}
}
},
"additionalProperties": false,
"required": [
"tool_name"
],
"title": "ToolDefinition"
},
"ToolParamDefinition": {
"type": "object",
"properties": {
@ -4428,6 +4432,36 @@
"title": "UserMessage",
"description": "A message from the user in a chat conversation."
},
"WebSearchTool": {
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "web_search",
"default": "web_search"
}
},
"additionalProperties": false,
"required": [
"type"
],
"title": "WebSearchTool"
},
"WolframAlphaTool": {
"type": "object",
"properties": {
"type": {
"type": "string",
"const": "wolfram_alpha",
"default": "wolfram_alpha"
}
},
"additionalProperties": false,
"required": [
"type"
],
"title": "WolframAlphaTool"
},
"BatchChatCompletionRequest": {
"type": "object",
"properties": {
@ -4449,7 +4483,29 @@
"tools": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ToolDefinition"
"oneOf": [
{
"$ref": "#/components/schemas/WebSearchTool"
},
{
"$ref": "#/components/schemas/WolframAlphaTool"
},
{
"$ref": "#/components/schemas/CodeInterpreterTool"
},
{
"$ref": "#/components/schemas/FunctionTool"
}
],
"discriminator": {
"propertyName": "type",
"mapping": {
"web_search": "#/components/schemas/WebSearchTool",
"wolfram_alpha": "#/components/schemas/WolframAlphaTool",
"code_interpreter": "#/components/schemas/CodeInterpreterTool",
"function": "#/components/schemas/FunctionTool"
}
}
}
},
"tool_choice": {
@ -4734,6 +4790,41 @@
"title": "ToolConfig",
"description": "Configuration for tool use."
},
"ToolDefinitionDeprecated": {
"type": "object",
"properties": {
"tool_name": {
"oneOf": [
{
"type": "string",
"enum": [
"brave_search",
"wolfram_alpha",
"code_interpreter"
],
"title": "BuiltinTool"
},
{
"type": "string"
}
]
},
"description": {
"type": "string"
},
"parameters": {
"type": "object",
"additionalProperties": {
"$ref": "#/components/schemas/ToolParamDefinition"
}
}
},
"additionalProperties": false,
"required": [
"tool_name"
],
"title": "ToolDefinitionDeprecated"
},
"ChatCompletionRequest": {
"type": "object",
"properties": {
@ -4753,10 +4844,42 @@
"description": "Parameters to control the sampling strategy"
},
"tools": {
"type": "array",
"items": {
"$ref": "#/components/schemas/ToolDefinition"
},
"oneOf": [
{
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/WebSearchTool"
},
{
"$ref": "#/components/schemas/WolframAlphaTool"
},
{
"$ref": "#/components/schemas/CodeInterpreterTool"
},
{
"$ref": "#/components/schemas/FunctionTool"
}
],
"discriminator": {
"propertyName": "type",
"mapping": {
"web_search": "#/components/schemas/WebSearchTool",
"wolfram_alpha": "#/components/schemas/WolframAlphaTool",
"code_interpreter": "#/components/schemas/CodeInterpreterTool",
"function": "#/components/schemas/FunctionTool"
}
}
}
},
{
"type": "array",
"items": {
"$ref": "#/components/schemas/ToolDefinitionDeprecated"
}
}
],
"description": "(Optional) List of tool definitions available to the model"
},
"tool_choice": {
@ -5630,21 +5753,7 @@
"type": "string"
},
"tool_name": {
"oneOf": [
{
"type": "string",
"enum": [
"brave_search",
"wolfram_alpha",
"photogen",
"code_interpreter"
],
"title": "BuiltinTool"
},
{
"type": "string"
}
]
"type": "string"
},
"content": {
"$ref": "#/components/schemas/InterleavedContent"