ProductHot

Perplexity Code Mode Turns Agent Tool Calls Into One Script

Perplexity's fix for expensive agents is to stop letting the model chat with tools one at a time. It writes a small program instead, and the bill drops on Perplexity's own benchmark.

Emily CarterEmily Carter
Heat: 760
Abstract illustration of one program branching into four parallel tool calls with a compact output

Dek: Perplexity's fix for expensive agents is to stop letting the model chat with tools one at a time. It writes a small program instead, and the bill drops on Perplexity's own benchmark.

What Perplexity Code Mode changes in the Agent API

Perplexity introduced Code Mode in its Agent API on 2 December. The mode, identified in requests as programmatic_tool_calling, replaces repeated tool-call round trips with JavaScript programs that run inside the agent loop. Perplexity reports benchmark cost reductions of up to 53% against its earlier presets.

The claim is easy to misread. That's a ceiling on Perplexity's test setup, not a discount every workload will see. The useful unit is cost per completed task.

For anyone paying for an AI agent, the unit that matters isn't the token. It's the finished job. A cheap agent that needs three attempts costs more than an expensive one that gets there once.

How programmatic tool calling works inside QuickJS

The mechanism is simpler than the name. The model writes one program. That program calls many tools at once, branches on what comes back, drops duplicates, and returns only the compact result the model needs to read.

Everything runs in an embedded QuickJS WebAssembly runtime, inside the agent loop. Enabled tools appear through a single typed tools.* interface that covers web search, URL fetching, people and finance search, MCP servers, and sandbox file or shell tools.

The design extends Perplexity's earlier Search as Code system, which ran Python against pplx_sdk inside a Linux sandbox container before any of this existed. Code Mode no longer boots that container, and it no longer needs a separate Python search library.

Why does that matter for latency? A tool call is a round trip, and each round trip puts the model back in charge of deciding what to do next. Ten calls mean ten decisions. One program means one decision and ten parallel branches.

The WANDR benchmark numbers behind the AI agent cost claim

Perplexity tested the change on the first 100 of 500 WANDR tasks. WANDR stands for Wide ANd Deep Research, and its grader re-fetches the pages an agent cites and checks whether each page and excerpt actually supports the claim. Soft recall, the score in the table, measures how much of the needed evidence survives that check.

At the ultra effort level, the November preset scored 85.9% at $21.71 per task, while Opus 5.5 plus three Sol-6.2 runs reached 88.5% at $12.12. Adding Code Mode to that same setup reached 89.4% at $10.30, without a hand-built research workflow.

Configuration at ultra effort

Soft recall

Cost per task

November preset

85.9%

$21.71

Opus 5.5 plus three Sol-6.2

88.5%

$12.12

Same models plus Code Mode

89.4%

$10.30

The lower tiers tell a similar story. At xhigh effort, the November preset hit 76.5% at $7.30, Sol-6.2 hit 78.7% at $5.57, and Sol-6.2 with Code Mode hit 80.5% at $3.85. At high effort, Code Mode reached 47.7% at $0.38 per task, which Perplexity says is 2.9 points above its baseline.

What latency looks like when a script runs in the background

Cost is half the pitch. The other half is time, and the numbers here are easier to trust because they compare the same work at the same spend.

The exec call returns partial output after 10 seconds while the script keeps running, and the agent can collect the rest with exec_wait or cancel a script that stalls. A long job produces something visible early instead of a spinner.

In paired WANDR runs, median duration fell 12.5%, from 28.9 minutes to 25.3, while the 95th percentile dropped from 97.3 minutes to 57.5. That second figure is a 40.9% cut. Maximum duration fell 56.6%, from 174.2 minutes down to 75.6 minutes.

The tail is the interesting part. Cutting the worst case by more than half changes how long someone waits before deciding an agent has failed, and a median gain of two minutes changes almost nothing.

Perplexity Code Mode limits: no imports, no state, no types

The honest limits start with the earlier attempts. Perplexity says lower-effort versions of Code Mode scored worse and cost more, because models made syntax mistakes and burned steps recovering from them. The feature works at high effort and above. Below that, it can be a regression.

Programs aren't general JavaScript. They can't import modules, use process or fetch, or reach outside data except through tools, and variables don't persist between runs. Identical requests can produce different programs, which makes a bug harder to reproduce than a failed API call.

Real constraints, not edge cases.

Approval flows have a rough edge. Programmatic-only MCP tools that need approval require defer_loading set to true, or the approval request returns HTTP 400. A program error can leave the overall response marked complete while program_output is incomplete, so a client that only checks for errors will miss a partial result.

Tooling lags the feature. Version 0.50.0 of the Python library and 0.45.0 of the TypeScript library lack Code Mode types, so the documentation falls back to raw HTTP. For a team that already imports those libraries, that's a step backwards before it's a step forwards.

What would make Perplexity Code Mode stick

The benchmark is a controlled course. Real agents mix search, internal databases, custom functions and human approvals, and those are the conditions that decide whether a 53% ceiling turns into a 10% saving.

Watch two numbers over the next quarter. The first is how often a program fails and has to be re-run, since a retry eats the gain. The second is how many teams keep Code Mode on after the novelty wears off, because an agent API is only cheaper when the cheaper path is also the default one.

Share This Story

Sources

Related AI News

Abstract illustration of a bright dot field with concentric signal arcs around an active core
Product

OpenAI Gives ChatGPT Plus Users a Dot and Rebuilds the Mobile App

OpenAI's always-on agents just moved from Pro to Plus, and the mobile app got a new shape to hold them. What a $20 subscriber actually gets this week is narrower than the announcement suggests.

Heat: 900
Abstract illustration of a small round AI pendant with a glowing ring on a soft gradient
Product

Meta's $299 Muse Charm Goes on Sale, and You Order It Through the Agent

Meta is selling a stopwatch-sized screen you talk to instead of reaching for your phone, and the only way to buy one online is to ask its assistant to order it. Both facts tell you what this product is.

Heat: 840
Abstract illustration of a toggle switch interrupting a timeline of activity dots
Product

Google Search Will Let You Keep Your History and Skip AI Training

Google is splitting one decision into two. You can keep your Search history and still tell the company not to train its models on what you do next.

Heat: 810
Abstract illustration of three stacked document panels with an AI cursor and live data points
Product

AWS Launches Quick Docs, Quick Sheets and Quick Slides, an Office Suite Built for Agents

Amazon is selling three file types that expect an agent to do part of the typing, not a Word clone with a chat box on the side. The preview calendar decides who gets to try that first.

Heat: 890