Model tool calling
Declare functions, execute tools, and return results with Asale's OpenAI, Anthropic, and Gemini APIs.
本頁尚未翻譯,目前顯示英文版本。
The model requests a tool call; your application executes it. A function definition gives the model a name, description, and input schema. It does not give the model direct access to your code or the marketplace. For Asale-managed execution, see the Tool Market API.
The tool calling loop
- Get an API key and choose a model that supports function calling and has supply in the model market or
GET /v1/models. - Send the tool definitions with the user input. Validate each returned function name, arguments, and permissions before executing it locally or submitting a marketplace run.
- Preserve the full assistant message or output items and return a matching result for every call. Keep the tool definitions in follow-up requests. Stop when the model returns an answer without further calls.
| API | Declaration | Model returns | Send back |
|---|---|---|---|
| Chat Completions | tools[].function.parameters | choices[0].message.tool_calls | A role: "tool" message with tool_call_id matching the call id |
| Responses | type: "function", name, and parameters on each tool | function_call items in output | Original input and prior output items, followed by function_call_output items with matching call_id values |
| Anthropic Messages | tools[].input_schema | tool_use blocks in content | tool_result blocks in a new user message, with tool_use_id matching each call id |
| Gemini GenerateContent | tools[].functionDeclarations[].parametersJsonSchema | functionCall parts in candidates[0].content.parts | functionResponse parts in a new user message, with the function name, the returned id if present, and a response object |
Request examples
Open the API section for Google Search and expand OpenAI, Anthropic, or Gemini. The example declares google_search as a model function and submits the model's arguments to POST /v1/tool-runs using the same name. Every market tool eligible for model use has examples generated from its own input schema.
Tool choice, parallel calls, and streaming
- Start by letting the model decide when to call a function. OpenAI and Anthropic expose
tool_choicein their own formats; Gemini usestoolConfig.functionCallingConfig. Supported options vary by model and supplying channel. - A single turn can request several tools. Independent calls can run in parallel, but every result must match its corresponding call. Run dependent calls in order, and do not assume every channel supports forcing sequential calls.
- For streams, assemble the full name, ID, and argument payload before execution. Start with non-streaming requests, and preserve original assistant items rather than reconstructing any opaque fields such as thought signatures.
- Limit rounds, calls, runtime, and spend. Validate model-generated arguments and treat external results, such as page text or transcripts, as data rather than instructions.