大模型网摘deepseek.wang

Prompt Tutorials · 2026-11-19

Prompt Patterns for Tool Calling with DeepSeek

Tool calling is something you can't avoid when building agents or workflows with DeepSeek. From hands-on experience, the model's ability to understand tools is rarely the problem—most failures trace back to the prompts: vague tool descriptions, missing parameter constraints, or unclear rules about when to call. This post breaks down how to write supporting prompts for tool-calling scenarios, with templates you can copy and adapt.

First Decide: Do You Need Reasoning Mode?

DeepSeek's R series supports a switchable deep-thinking mode suited to complex reasoning, while the V series targets general conversation with faster responses. Treat tool calling differently depending on the case:

You can state this directly in the prompt: "This is a simple lookup—give the result directly, no extended reasoning." Deep reasoning models don't respond to roleplay flourishes. Writing "you are a senior expert" does far less than spelling out "which field to return when the call fails, and what the parameter defaults are."

A Prompt Template for Tool Descriptions

A common cause of failed calls is that the model simply doesn't know "when this tool should be used." A good tool description covers three things: scope of use, parameter constraints, and a fallback for failure. Paste this template and adapt it:

You are a tool-calling assistant. You may only obtain information by calling tools;
never fabricate data from memory.

Available tools:
1. query_order(order_id: string, include_logistics: boolean)
   - Purpose: look up order status and logistics info.
   - order_id: a 12-digit numeric string. If the user's message does not contain a
     clear 12-digit order number, ask first—never guess.
   - include_logistics: set to true when the user mentions "logistics", "shipping",
     or "where is my package"; otherwise false.
   - When to use: only for order-related questions. Do not call for small talk or
     product inquiries.
2. create_ticket(user_id: string, issue: string, level: int)
   - issue: no more than 200 characters summarizing the user's problem.
   - level: 1-3. Use 1 for general issues, 2 for usage-blocking problems, 3 for
     anything involving money.

Output rules:
- If parameters are missing, ask the user to complete them. Never pass empty values
  or guessed defaults.
- When a tool returns an error, explain it to the user in one sentence. Do not dump
  the raw error message.

The key is hard constraints like "never guess" and "ask first," plus explicit value rules for every parameter. Models are highly sensitive to negative prohibitions and concrete examples—the more specific you are, the lower the fabricated-parameter rate.

A Prompt Template for Multi-Tool Orchestration

For chained tasks, the goal is to make the model plan before acting. Reasoning mode is recommended here, along with an explicit decision order in the prompt:

You are a customer-service ticketing assistant. Follow this workflow:

Step 1: Classify intent. Is the user's message a query, a complaint, or other?
Step 2: Plan. For queries, call query_order. For complaints, call query_order first
  to confirm the facts, then decide whether to call create_ticket based on the result.
  List the plan in one line before executing.
Step 3: Execute calls. Call one tool at a time; wait for the result before deciding
  the next step.
Step 4: Summarize. Explain the outcome to the user in no more than 100 words.

Constraints:
- If the user's message has no order number, ask for it and pause the workflow.
- If a complaint involves an order with normal status, do not create a ticket—
  just explain.
- Never make more than 3 tool calls in a single reply.

This kind of template pairs well with reasoning mode, because "list a plan, then execute" aligns with the model's step-by-step reasoning habits.

Two Notes on Chinese Context and Local Deployment

DeepSeek handles Chinese context well, so write tool descriptions directly in Chinese—no need to force everything into English. A common, readable convention is English parameter names with Chinese descriptions. If you're running open-weight local deployments, note that tool-calling stability is sensitive to context length: don't stuff the tool definitions plus conversation history into the full context window; leave room for generation. For exact deployment parameters, refer to the official documentation. Also, since DeepSeek's API pricing is low, you can afford to write detailed constraints and examples in your prompts—don't trim tool descriptions to a single line to save tokens. What you save there costs you more in rework.

One last suggestion: treat the templates above as scaffolding. After swapping in your own tool list, run a regression test with ten real user messages, observe where parameter fabrication and missed calls concentrate, and patch constraints accordingly. Prompts for tool calling are iterated into shape, not written once and done.