
V4-Pro 0813 Just Went GA: A Multi-Step DeepSeek Agent
Summary
Build a tool-using DeepSeek V4-Pro agent with effort escalation, on the day it hit GA.
V4-Pro 0813 Just Went GA: Build a Multi-Step Agent Today
DeepSeek promoted V4-Pro-0813 to general availability on August 13, 2026. After four months in preview, the headline of the GA release is not a benchmark score. It is agent capability: the checkpoint is tuned for tasks where a model calls tools, runs code, and grinds through a multi-step job without a human babysitting each turn.
Two things landed with GA that change how you write agent code. First, reasoning_effort now takes three levels, low, high, and max, on both V4-Pro and V4-Flash. Second, the API stayed OpenAI-compatible, so the tool-calling loop you already know still works. That combination lets you build an agent that thinks cheaply on easy steps and spends more only when a step is hard.
This guide builds that agent from scratch in Python: a working tool-use loop, per-step effort escalation, prompt caching to keep the bill low, and the gotchas that bite people on day one. Everything below is checked against DeepSeek's OpenAI-compatible surface as documented for the 0813 GA release.
What you need before you start
- Python 3.9+ and the official OpenAI SDK:
pip install openai(version 1.40 or newer). - A funded DeepSeek account. There is no free request tier; add a couple of dollars of credit at platform.deepseek.com or calls return HTTP 402.
- An API key from the dashboard, stored as an environment variable. The key works for both the OpenAI-compatible base URL and the Anthropic-compatible one.
- Basic familiarity with JSON tool schemas. If you have written OpenAI function calling before, you already know 90% of this.
export DEEPSEEK_API_KEY="sk-your-key-here"
pip install "openai>=1.40"
Step 1 - Point the OpenAI SDK at DeepSeek
V4-Pro speaks the OpenAI ChatCompletions spec. You do not need a DeepSeek SDK. Create a standard OpenAI client and change the base URL. The model IDs are deepseek-v4-pro (top reasoning and agentic) and deepseek-v4-flash (cheaper and faster).
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DEEPSEEK_API_KEY"],
base_url="https://api.deepseek.com", # /v1 also works
)
resp = client.chat.completions.create(
model="deepseek-v4-pro",
messages=[{"role": "user", "content": "Reply with the single word: ready"}],
)
print(resp.choices[0].message.content)
Expected output:
ready
If that prints, your key and balance are good and the rest of the guide will run.
Step 2 - Define the tools the agent can call
An agent is only as useful as the tools you hand it. A tool is a JSON schema plus a real Python function. Keep descriptions blunt and specific; the model reads them to decide when to call each one. Here are two tools for a small operations assistant: an arithmetic calculator and a SKU price lookup.
import json
TOOLS = [
{"type": "function", "function": {
"name": "calculator",
"description": "Evaluate a basic arithmetic expression and return the number.",
"parameters": {"type": "object",
"properties": {"expression": {"type": "string",
"description": "e.g. '12.5 * 40 * 1.08'"}},
"required": ["expression"]}}},
{"type": "function", "function": {
"name": "unit_price",
"description": "Return the price per unit in USD for a known SKU.",
"parameters": {"type": "object",
"properties": {"sku": {"type": "string"}},
"required": ["sku"]}}},
]
PRICES = {"A-100": 12.5, "B-200": 7.0}
def run_tool(name, args):
if name == "calculator":
# eval with no builtins is fine for a demo; use a real parser in prod
return {"result": eval(args["expression"], {"__builtins__": {}}, {})}
if name == "unit_price":
return {"sku": args["sku"], "price": PRICES.get(args["sku"])}
return {"error": f"unknown tool {name}"}
The run_tool dispatcher is the boundary between the model and your real systems. In production this is where you would query a database, hit an internal API, or read a file. The model never runs anything itself; it only asks.
Step 3 - Write the tool-use loop
The core of every agent is a loop. The model responds either with a final answer or with one or more tool calls. When it asks for tools, you run them, append the results, and call the model again. Repeat until it stops asking, or until you hit a step budget so a confused model cannot bill you forever.
Two ordering rules are easy to get wrong and both break the request. The assistant message that contains tool_calls must be appended to the history before the tool result messages. And every tool result must carry the exact tool_call_id from the call it answers.
def agent(client, question, max_steps=6):
messages = [
{"role": "system", "content":
"You are a precise ops assistant. Use tools for any number; never guess."},
{"role": "user", "content": question},
]
effort = "low" # start cheap, escalate later (Step 4)
for step in range(max_steps):
r = client.chat.completions.create(
model="deepseek-v4-pro",
messages=messages,
tools=TOOLS,
tool_choice="auto",
extra_body={"reasoning_effort": effort},
)
msg = r.choices[0].message
if not msg.tool_calls: # model is done
return msg.content, step + 1
# 1) append the assistant's tool-call message FIRST
messages.append(msg.model_dump())
# 2) then one tool result per call, matched by id
for call in msg.tool_calls:
args = json.loads(call.function.arguments)
out = run_tool(call.function.name, args)
messages.append({
"role": "tool",
"tool_call_id": call.id,
"content": json.dumps(out),
})
effort = "high" # next round: think harder
return "step budget exhausted", max_steps
Run it against a two-step question. The agent must look up a price, then compute a taxed total. It cannot answer in one shot, so it will call both tools before replying.
answer, steps = agent(
client,
"Order 40 units of SKU A-100 with 8% tax. What is the total?")
print(f"[{steps} steps] {answer}")
Example output:
[3 steps] 40 units of A-100 at $12.50 each plus 8% tax comes to $540.00.
Under the hood: turn 1 the model calls unit_price for A-100; turn 2 it calls calculator on 12.5*40*1.08; turn 3 it has both facts and writes the final sentence. No number was hallucinated because the system prompt forbids guessing and the tools supply the ground truth.
Step 4 - Escalate reasoning effort per step
This is the feature the 0813 GA release unlocked. Instead of paying for maximum reasoning on every turn, start at low and raise the level only when the work gets hard. Reasoning tokens are billed as output tokens, so max is a real line item, not a free switch. Escalating on demand is how you keep an agent cheap without making it dumb.
A simple, effective policy: run tool-selection turns at low, then bump to high once results are in and the model has to synthesize. Reserve max for turns you know are genuinely hard, such as a final numeric proof or a tricky plan. The loop above already flips low to high after the first tool round; here is an explicit policy function you can plug in.
def effort_for(step, last_tool_error):
if last_tool_error: # a tool failed, let the model reason about recovery
return "max"
if step == 0: # first pass: just pick tools
return "low"
return "high" # synthesis turns
# in the loop:
# effort = effort_for(step, last_tool_error)
# ... extra_body={"reasoning_effort": effort}
You pass the level through extra_body because it is a DeepSeek-specific field the OpenAI SDK does not model natively. The accepted values on the GA checkpoint are exactly low, high, and max. Older code that triggered extended thinking by inflating max_tokens should migrate to this parameter.
Step 5 - Cut the bill with prompt caching
V4 caches prompt prefixes automatically. When a later request repeats the same leading tokens, those tokens bill at the cache-hit rate instead of the cache-miss rate. On V4-Pro that is roughly $0.003625 per million versus $0.435 per million, about 120x cheaper. Agent loops are the ideal case because every turn resends the same system prompt and tool schemas as a stable prefix.
You do not configure anything. You just avoid breaking the prefix. Three rules:
- Keep the system prompt and tool definitions byte-identical across turns. A timestamp or a shuffled tool order silently drops the cache and you pay full input price again.
- Front-load static context. Put large unchanging material (instructions, schemas, pinned documents) first and the variable user input last, because the cache matches from the start of the prompt forward.
- Watch the cache-hit rate in the dashboard. A low rate almost always means something in your prefix is changing when it should not.
One caveat with a deadline: from 16:00 UTC on August 16, 2026, DeepSeek moves to peak and off-peak pricing, and the cache-read multiplier is the largest single jump. Caching still wins, but model your agent's stable-prefix cost against the new rates before you scale it.
A worked example: a three-step procurement check
Put it together with a question that forces three tool calls and a synthesis turn. The agent must price two different SKUs, sum a mixed order, and apply tax. This is the kind of task where a one-shot LLM quietly invents a number and effort escalation earns its keep.
q = ("A customer orders 40 of A-100 and 25 of B-200. "
"Apply 8% tax to the combined subtotal. Give the final total.")
answer, steps = agent(client, q, max_steps=8)
print(f"[{steps} steps] {answer}")
Example output:
[4 steps] Subtotal: 40 x $12.50 = $500.00 and 25 x $7.00 = $175.00,
combined $675.00. With 8% tax the final total is $729.00.
Verify it by hand: 40 x 12.5 = 500, 25 x 7 = 175, subtotal 675, times 1.08 = 729. The arithmetic came from the calculator tool, not the model's head, which is exactly why it is correct. Swap the two stub tools for a real pricing API and a real tax service and you have a production procurement agent with the same 30 lines of loop.
Common pitfalls and how to avoid them
- Tool message ordering. Append the assistant message that holds
tool_callsbefore any tool result. Reverse the order and the API rejects the request with a 400. - Mismatched tool_call_id. Each tool result must echo the exact id from its call. If the model made two parallel calls, you must return two results, each with the right id, or the next turn fails.
- Effort cost blindness. Reasoning tokens bill as output tokens. Running every turn at
maxcan quietly multiply your bill. Benchmarklowfirst and escalate only where accuracy demands it. - Broken cache prefix. Any drift in the system prompt or tool list, even reordering, resets the cache and you pay cache-miss rates. Keep the prefix frozen.
- No step budget. A model stuck in a tool-call loop will keep calling forever. Always cap
max_stepsand return a clear failure when it is hit. - Legacy model names. The old aliases
deepseek-chatanddeepseek-reasonerwere retired on July 24, 2026. Usedeepseek-v4-proordeepseek-v4-flash. - Concurrency, not uptime, is the ceiling. V4-Pro allows 500 concurrent requests (2,500 on Flash). If you are throttled, add queueing or a second provider rather than assuming the API is down.
Quick reference
| Item | Value |
|---|---|
| Base URL | https://api.deepseek.com (or /v1) |
| Agentic model | deepseek-v4-pro |
| Cheap/fast model | deepseek-v4-flash |
| reasoning_effort levels | low, high, max (both models, since 0813 GA) |
| Context window | 1M tokens |
| Max output | 384K tokens |
| V4-Pro price (in/out per 1M) | $0.435 miss, $0.003625 hit / $0.87 out |
| Compatible surfaces | OpenAI ChatCompletions, OpenAI Responses, Anthropic |
| Concurrency limit | 500 (Pro), 2,500 (Flash) |
| Retired aliases | deepseek-chat, deepseek-reasoner (gone July 24, 2026) |
| Pricing change | peak/off-peak from 16:00 UTC, Aug 16, 2026 |
Next steps
- Add retry-with-backoff around
createto handle 429s, honoring the Retry-After header. - Give the agent a real tool: a database read, an HTTP call, or a filesystem lookup, and keep the loop identical.
- Try the native OpenAI Responses API surface that shipped with GA if you want server-side conversation state instead of resending history.
- Stream the final turn with
stream=Trueso users see tokens as they arrive on long answers. - Log the effort level and token counts per step, then tune your
effort_forpolicy against real traffic.
The GA release makes V4-Pro a practical, low-cost base for autonomous agents, and the OpenAI-compatible interface means you can ship one this afternoon. The hard part is not the API; it is a solid loop, caching that actually hits, effort you spend deliberately, and failure handling that degrades gracefully. You now have all four.
Comments
Be the first to comment
Found this useful?
Get new AI guides for builders by email. Free.
Join 3,604 newsletter subscribers.