Hot AI News

Perplexity’s agents now write one script instead of dozens of tool calls

Code Mode lets models in Perplexity's Agent API script their tool calls in JavaScript, and it is now the default in the high, xhigh and ultra effort levels.

Perplexity’s agents now write one script instead of dozens of tool calls
Image: Perplexity

Perplexity has added Code Mode to its Agent API. With it, a model writes a short JavaScript program that calls its research tools in parallel, instead of calling them one at a time. On Perplexity’s WANDR benchmark, the top setting scored 89.4% at $10.30 per task.

One JavaScript script replaces a chain of round-trips

In standard tool calling, the model runs a full pass after every search, page fetch or API call, and the raw results pile up in its context window. Perplexity says this gets expensive on broad research tasks that need dozens of calls. As the company put it, “The newest models write code well enough to replace those round-trips with one short script.”

WANDR score by Perplexity effort setting
Image: Perplexity, chart by Aiholics

In the API, the feature is called programmatic_tool_calling. The model’s script runs in an embedded QuickJS runtime compiled to WebAssembly, inside the agent loop itself. It reaches tools through a single typed tools.* interface. According to Perplexity, a script can call any tool enabled in the Agent API, including web search, URL fetching, people search, finance search, MCP servers and sandbox file or shell commands. It can run calls side by side, remove duplicate results and write raw data to disk, so only a short summary goes back into context.

Developers turn it on by adding programmatic_tool_calling to the tools list and setting allowed_callers: ["programmatic"] on each tool a script may use. Perplexity says the updated high, xhigh and ultra effort levels already use Code Mode by default. Its example request runs the openai/gpt-6.1-terra model at high effort.

Perplexity co-founder and CEO Aravind Srinivas, wearing a Perplexity sweatshirt, speaks onstage at TechCrunch Disrupt 2024 in San Francisco.
Photo: TechCrunch / Wikimedia Commons, CC BY 2.0

The feature replaces Search as Code, which Perplexity introduced in June. That approach had agents run Python against the pplx_sdk library inside a Linux sandbox container, and it covered retrieval only. Code Mode needs no container to start up and works with every tool, not just search.

A second addition, exec_wait, deals with slow scripts. After 10 seconds, a script hands back partial output and keeps running in the background. Meanwhile the agent can work on other parts of the task, then collect the results later or cancel a stalled script.

Advertisements

Newer models did part of the work before Code Mode

Perplexity tested two changes in sequence on WANDR, its own benchmark for wide and deep research. The first was swapping its November 5 presets for newer reasoning models. That moved xhigh from 76.5% ($7.30 per task) to 78.7% ($5.57), and ultra from 85.9% ($21.71) to 88.5% ($12.12).

Turning on Code Mode came second. It lifted xhigh to 80.5% at $3.85 per task and ultra to 89.4% at $10.30. Perplexity’s headline savings of 47% and 53% compare against the November 5 presets, so they include the model upgrade. Measured against the new models alone, Code Mode added 1.8 points and cut $1.72 per task on xhigh, and added 0.9 points and cut $1.82 on ultra.

On xhigh, Perplexity’s cost per WANDR task fell from $7.30 to $3.85 between the November 5 presets and the new Code Mode setup.

The cheaper high tier is new. Until now, code execution was limited to xhigh and ultra, because earlier tests with mid-tier models gave lower scores at higher cost. Perplexity now reports 47.7% at $0.38 per task on high, 2.9 points above its baseline. In paired runs at the same spend, exec_wait cut median run time from 28.9 to 25.3 minutes and the slowest 5% of runs from 97.3 to 57.5 minutes.

These are Perplexity’s own numbers on its own benchmark. They cover only the first 100 of WANDR’s 500 tasks, scored with a soft-recall metric that gives partial credit. They have not been checked independently. The post gives no per-request pricing changes and does not say how Code Mode affects latency on short, single-question queries.

Perplexity runs the code in WebAssembly, not a container

Perplexity did not invent the idea. In September 2025, Cloudflare published its own Code Mode, which turns MCP tools into a TypeScript API for models to write code against. Cloudflare argued that “LLMs are better at writing code to call MCP, than at calling MCP directly,” and runs each snippet in a fresh V8 isolate. In November 2025, Anthropic released programmatic tool calling for Claude. In that version, Claude writes Python in a code execution environment, and tools opt in through an allowed_callers field. Perplexity’s API uses the same field name. Anthropic reported that average token use on complex research tasks fell from 43,588 to 27,297, a 37% reduction.

Perplexity’s design differs in where the code runs and what it can reach. Instead of a separate sandbox, a small JavaScript engine sits directly in the agent loop. That avoids the container startup that Search as Code needed, and one script can mix search, finance data, MCP servers and shell commands. Speed of execution was never the hard part, though. Perplexity says earlier models made syntax errors, misread tool outputs and wasted steps recovering from failed scripts. That overhead is why Code Mode used to pay off only on top-tier models.

According to Perplexity, that gap with direct tool calling has narrowed with each model generation. The company says it expects more effort levels, and eventually most agent loops, to run in Code Mode by default. It has not given a timeline.

Sign Up for the Daily AI Pulse

One email a day. All the stories that matter.

Alex CarterAI News & Big Tech Correspondent

Alex Carter writes for Aiholics, keeping readers updated on the fast-paced world of AI and Big Tech.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may also like