Dev48
Language
  • About
  • Services
  • Industries
  • Technologies
  • Articles
  • Contacts
Book a call
    Home/Articles/Introducing code mode in the agent api
Dev48
info@dev48.org+375 29 320-40-96WhatsApp@isky_by

© 2026 · All rights reserved.

Introducing Code Mode in the Agent API

Source: Perplexity AI•December 2, 2026 at 08:44 PM

Introducing Code Mode in the Agent API

Code Mode in the Agent API replaces tool-call round-trips with one parallel script, raising WANDR scores at lower cost.

Agents do research by calling tools, and a wide task can take dozens of calls. Standard tool calling forces a full model round-trip after every search, fetch, or API call, pulling raw payloads into the context window along the way. The newest models write code well enough to replace those round-trips with one short script.

Today we're introducing Code Mode (programmatic_tool_calling) in the Agent API. With Code Mode, the model writes a script that calls its tools directly, runs the calls in parallel, and keeps only the results that matter. It ships in our updated high, xhigh, and ultra effort levels and is available directly in custom requests.

Code Mode builds on Search as Code, which we introduced in June for retrieval: agents ran Python against pplx_sdk inside a Linux sandbox container to fan out queries and filter results in code. Unlike pplx_sdk, Code Mode doesn't require booting a sandbox container or staying inside a separate Python search library. Scripts run as JavaScript inside an embedded QuickJS WebAssembly runtime directly in the agent loop.

That preserves every advantage of pplx_sdk (parallel fan-out, branching, deduplication, and filtering raw payloads outside the context window) while letting the model call any enabled Agent API tool natively through one typed tools.* interface: web_search, fetch_url, people_search, finance_search, MCP servers, and sandbox file or shell tools. It’s all composable in a single script with non-blocking yielding via exec_wait.

Moving the WANDR frontier: new models, then Code Mode

WANDR is Perplexity’s benchmark and evaluation harness for wide and deep research. We measured two changes on it, sequentially.

First, we upgraded from our November 5 presets to newer reasoning models. This raised the score and lowered the cost per task for both top effort levels. Sol-6.2 moved xhigh from 76.5% ($7.30) to 78.7% ($5.57), and Opus 5.5 + 3 Sol-6.2 moved ultra from 85.9% ($21.71) to 88.5% ($12.12).

Then, we turned on Code Mode. Turning this on with those same models pushed the frontier further: Sol-6.2 + Code Mode reached 80.5% at $3.85/task (47% less than the November 5 xhigh), and Opus 5.5 + 3 Sol-6.2 + Code Mode reached 89.4% at $10.30/task (53% less than the November 5 ultra).

Bringing Code Mode to high

Until now, code execution was limited to xhigh and ultra, our two most powerful effort levels. Earlier experiments in high and lower levels didn't pay off: mid-tier models scored lower and cost more than with direct tool calling. With newer mid-tier models, high + Code Mode reaches 47.7% at $0.38/task (+2.9 pts over baseline) without any hand-crafted research workflows or prompts. Given only programmatic tools and a workspace, the model builds its own multi-stage pipelines: fanning out searches in parallel, deduplicating results in JavaScript, and saving raw payloads to disk.

javascript

const regions = ["Ernakulam", "Thrissur", "Kozhikode", "Kottayam"]; const searches = await Promise.all(regions.map((region) => tools.search_web({ query: `NABH accredited hospitals in ${region}`, limit: 5 }) )); const urls = new Set(searches.flat().map((hit) => hit.url)); const pages = await tools.fetch_url({ urls: Array.from(urls).slice(0, 8) }); await tools.write({ file_path: "/tmp/hospitals.json", content: JSON.stringify(pages) }); text(pages.map(({ url, title, content }) => ({ url, title, chars: content.length })));

Code Mode supports multiple tools

Code Mode isn’t limited to web search. Any tool with allowed_callers: ["programmatic"], including structured finance_search tools, sandbox commands, or MCP servers, can be called from the same script. Instead of streaming megabytes of raw filings into context, the model batches calls, saves raw payloads to disk, and emits only a compact summary.

javascript

const tickers = ["AMKR", "PLAB", "CLS", "ASX", "FN", "ONTO"]; await Promise.all(tickers.map(async (ticker) => { const [segments, transcript] = await Promise.all([ tools.finance_segments({ ticker_symbols: [ticker], period_type: "quarterly", limit: 2 }), tools.finance_earnings_transcript({ ticker_symbol: ticker, query: "revenue guidance and CapEx" }), ]); const file_path = `/tmp/${ticker}.json`; await tools.write({ file_path, content: JSON.stringify({ segments, transcript }) }); text({ ticker, saved: file_path }); }));

Models are getting better at Code Mode

Code Mode used to carry a noticeable overhead: earlier models made syntax mistakes, misread tool outputs, or spent extra steps recovering from script errors, which meant it only paid off on top-tier models and broad research tasks. As models have gotten better at writing code, that overhead has shrunk. Code Mode now improves our mid-tier high effort level where earlier attempts regressed. The chart below shows the remaining gap against direct tool calling narrowing across consecutive model generations.

As that overhead keeps dropping for newer, smaller models, we expect more of our effort levels, and eventually most agent loops, to run in Code Mode by default.

Shortening slowest runs with exec_wait

Fan-out or sandbox jobs block the entire agent loop and take a while. Instead, exec returns partial output after 10 seconds while the script keeps running in the background. The main agent can then continue its research on other branches of the task instead of sitting idle. When it is ready for the results, it collects them with exec_wait or cancels a stalled script. This pays off most on broad, multi-step research tasks like WANDR, where the agent always has other work to do while finishing long scripts.

In paired WANDR runs at identical spend, exec_wait cut median duration by 12.5% (28.9 → 25.3 min), p95 by 40.9% (97.3 → 57.5 min), and max duration by 56.6% (174.2 → 75.6 min).

json

{ "model": "openai/gpt-6.1-terra" "effort": "high", "tools": [ { "type": "programmatic_tool_calling" }, { "type": "web_search", "allowed_callers": ["programmatic"] }, { "type": "fetch_url", "allowed_callers": ["programmatic"] }, { "type": "finance_search", "allowed_callers": ["programmatic"] }, { "type": "sandbox", "allowed_callers": ["programmatic"] } ], "input": "Compare quarterly revenue, CapEx, and guidance across AMKR, PLAB, CLS, ASX, FN, and ONTO." }

Methodology

Every experiment holds the prompt, agent harness, search backend, and grading pipeline fixed, varying only the single factor under evaluation: model generation, execution mode (direct tool calling vs. Code Mode), or cell scheduling (synchronous exec vs. yielding exec + exec_wait).

Benchmarks and grading

  • WANDR. We evaluate on the first 100 of the 500 tasks in WANDR (Wide ANd Deep Research), using the public evaluation harness and its standard fetch, judge, and scoring pipeline. We report soft recall: quality-adjusted completion against the requested volume, with partial credit for incomplete records and any shortfall counted as zero. See the WANDR post for the full methodology.
  • Costs are average cost per task under each configuration.

Using Code Mode in the Agent API

To enable Code Mode for a request, add programmatic_tool_calling to tools and set allowed_callers on each tool that a script can call. The latest high, xhigh, and ultra effort levels use Code Mode by default.

Try Code Mode on your own workloads and compare score, cost, and latency against direct tool calling. Setup details are in the Agent API documentation, and the effort guide covers what each level includes.

← All articles

What this article says

More in AI & Machine Learning

All →
AWS is making Anthropic Claude available on-premises for the first timeПресса
Claude

AWS is making Anthropic Claude available on-premises for the first time

Perplexity caught an autonomous AI hacker trying to steal tokensПресса
Perplexity

Perplexity caught an autonomous AI hacker trying to steal tokens

Introducing the Modal Cyber Defense Program
Modal

Introducing the Modal Cyber Defense Program

Amazon Leo invests nearly $2 billion in satellite production and R&D facilities in Washington state
Amazon

Amazon Leo invests nearly $2 billion in satellite production and R&D facilities in Washington state

8 intelligent PTZ camera features | Including explanatory videos
Axis Communications

8 intelligent PTZ camera features | Including explanatory videos

DeepSeek V4.1 Flash 1017 Ultra-fast is now generally available on Fireworks
Fireworks AI

DeepSeek V4.1 Flash 1017 Ultra-fast is now generally available on Fireworks

More from Perplexity

Perplexity caught an autonomous AI hacker trying to steal tokensПресса
Perplexity

Perplexity caught an autonomous AI hacker trying to steal tokens

AI tokens explained: the cost of every AI prompt
Perplexity

AI tokens explained: the cost of every AI prompt

How Perplexity defended against an autonomous AI attacker
Perplexity

How Perplexity defended against an autonomous AI attacker

Comet Browser vs. Chrome: Key Differences & Comparison
Perplexity

Comet Browser vs. Chrome: Key Differences & Comparison

MCP vs. Skills: Key Differences & When to Use Each
Perplexity

MCP vs. Skills: Key Differences & When to Use Each

Perplexity Pro now includes weekly Computer usage
Perplexity

Perplexity Pro now includes weekly Computer usage