Skip to main content
When your agent has access to dozens or hundreds of tools, don’t put every tool definition into the request — they eat up context and make the model more likely to pick the wrong tool. This guide walks through a tool-orchestration setup with the Kimi API: retrieve candidate tools with a search tool first, then inject tool definitions into the conversation on demand.

Declare a search tool, not all your tools

At the start of a conversation, declare only a single search_tools function — implemented by your backend — plus a small set of core tools you expect to use in every turn:
In the system prompt, advertise the domain tags the model can search (for example, a tool catalog or business domains) so it knows to call search_tools first when it needs a tool. No matter how large your total inventory is, each request then only carries a handful of tool declarations.

Use tool_choice to force first-turn retrieval

The model may choose not to call any tool and answer from memory. To make sure it retrieves before answering, set tool_choice: "required" on the first turn:
After retrieval, switch tool_choice back to "auto" for subsequent requests. Changing tool_choice does not invalidate the prefix cache, so you can adjust it per request. See Tool Choice for all accepted values.

Inject tool definitions on demand

When search_tools returns candidate tools, your application inserts the full declarations of the matching tools into messages via a system message carrying a tools field. The tools become visible to the model starting from that message’s position:
Injected tools coexist with the global tools declared at the top level. Dynamic declarations apply per request and are not retained by the server; keep the declaration unchanged in subsequent requests if you want the tool to remain available and preserve prefix cache hits. See Dynamically Loaded Tools for format requirements, cache behavior, and error details.

Pick the reasoning effort for the task

The top-level reasoning_effort request field supports low, high, and max, with max as the default. Decide on this setting based on task complexity before the conversation starts. See Reasoning Effort for configuration details.

The complete flow

  1. Conversation start: top-level tools carries only search_tools plus a few core tools;
  2. First-turn retrieval: tool_choice: "required" forces the model to call search_tools;
  3. Inject on demand: insert tool definitions via a system message based on the retrieval results;
  4. Call directly: the model calls the loaded tools in subsequent generations;
  5. Reasoning effort: decide on the top-level reasoning_effort setting before the conversation starts.