Wild West API

Tool calling: letting a model use functions

Tool calling, also called function calling, lets a model respond with a structured request to run one of your functions, whose result you then send back to it.

What tool calling is

You describe a set of functions to the model: names, descriptions and a JSON Schema for the arguments. When the model decides one would help, it returns a tool call instead of (or along with) text, naming the function and giving arguments. Your code runs the function and sends the result back. The model then continues with that information. The model never runs anything itself; it only asks.

How the loop works

In the OpenAI-style format you pass a tools array:

{"model": "glm-5.3-outlaw",
 "messages": [{"role": "user", "content": "Roll for the lockpick."}],
 "tools": [{"type": "function", "function": {
   "name": "roll_dice",
   "description": "Roll dice, e.g. 1d20",
   "parameters": {"type": "object",
     "properties": {"dice": {"type": "string"}},
     "required": ["dice"]}}}]}

The reply has finish_reason: "tool_calls" and a tool_calls list, each with an id and arguments as a JSON string. You append that assistant message, then a message with "role": "tool", the matching tool_call_id and the result, and call the API again. tool_choice can force a specific tool, require any tool, or disable tools. The Anthropic-style /v1/messages format uses tool_use and tool_result content blocks for the same loop.

Uses in roleplay and fiction

  • Dice rolls and game mechanics that should be truly random rather than invented by the model.
  • Tracking inventory, health or relationship stats in your own code instead of in prose.
  • Looking up lore from a database, a form of RAG.
  • Triggering image generation or other frontend features. SillyTavern has a function calling option in Chat Completion that some extensions use.

Common mistakes

  • Not sending the assistant's tool call message back before the tool result. The IDs must match.
  • Parsing arguments without handling invalid JSON. Models occasionally produce malformed arguments.
  • Vague tool descriptions, so the model calls tools at the wrong time or never.
  • Running tool calls at high temperature or with creative samplers like XTC, which hurts argument accuracy.
  • Executing tool requests without validation. Treat arguments as untrusted input.
  • Offering dozens of tools at once. Every tool definition is sent as prompt tokens on each request, and a long list makes the model's choice less reliable.

Tool calling on Wild West API

All Wild West API models support tool calling: outlaw-1, glm-5.3-outlaw, glm-5.3-flash-outlaw, mimo-v2.6-flash-outlaw and qwen3.8-27b-outlaw. Use the OpenAI tools format on /v1/chat/completions or the Anthropic tool format on /v1/messages. See the docs for examples.

FAQ

Does the model run the function itself?

No. The model only returns the function name and arguments. Your code runs it and sends the result back in a tool message.

What is tool_choice?

A request field that lets the model decide (auto), forces it to call some tool (required), forces a specific function, or turns tools off (none).

Related

Uncensored AI models on one key

OpenAI and Anthropic compatible, pay as you go. New to it? Start with uncensored AI, explained.