Skip to main content
In a long-horizon task, calling a flagship model at every step increases latency and token usage, while using only a lightweight model to execute tool calls may leave complex debugging or design trade-offs unresolved. To balance these trade-offs, you can wrap a flagship model as a client-side advisor tool. The lightweight executor can handle routine tool calls and consult the advisor when it encounters a difficult debugging or design problem.

Implement the client-side advisor tool

This example builds on the tool-calling workflow, using kimi-k2.6 as the executor model and kimi-k3.1-pro as the advisor model. Set your API key in the MOONSHOT_API_KEY environment variable before running the code:
The table below summarizes each part of the code:

Call the advisor in your tool-calling loop

Pass ADVISOR_TOOL alongside your application’s existing tool definitions (business_tools) to the executor model, and dispatch each call by tool name inside the loop:

Frequently asked questions

Maintain a client-side counter to cap consultations per task, for example, by setting the limit to one or two consult_advisor() calls per task, so the executor does not make a high-cost advisor request at every step.When the cap is reached or an advisor request fails, do not raise an exception that aborts the main loop. Instead, append a regular tool message to messages (such as "Advisor call limit reached; continue with the existing tool results") so the executor can proceed with the information it already has.
The executor’s reasoning_content preserves reasoning continuity across multi-step tool calls and must be retained unchanged in the executor’s messages list (see Thinking Models).When sending a standalone request to the advisor model, the advisor only needs the conversation history and results from completed tool calls. Stripping reasoning_content reduces input tokens for the advisor request and prevents unverified intermediate reasoning from biasing the advisor.