ZICQ
中 Log in / Sign up
Newsroom Official Agentic #Perplexity #Agent API #Code Mode #MCP #Tool Calling

Perplexity Adds Code Mode to Agent API for Parallel Tool Orchestration

Avatar of Mr.Xu

By Mr.Xu Compiled & Reviewed by Editorial

Published:

中文阅读 (Chinese) English Version
Co-reading Select any sentence in the article to highlight, annotate, or copy a quote card. Join discussion ↓

Summary:Perplexity has added Code Mode to its Agent API. The model writes a JavaScript program that can invoke built-in tools, MCP tools, and custom functions; Perplexity executes the program and returns structured `program` and `program_output` items. A single program can fan out many tool calls in parallel and return only the data needed by the model. The design can reduce model–tool round trips and context bloat by moving aggregation and filtering into executable orchestration. It also introduces th


Perplexity Adds Code Mode to Its Agent API

What Changed

Perplexity has added Code Mode to its Agent API. Instead of splitting every tool interaction into a separate turn, the model writes a JavaScript program that can invoke Perplexity built-in tools, MCP tools, and custom functions. Perplexity executes the program. The response contains a program item and a corresponding program_output item for each program. According to the announcement, one program can make many tool calls in parallel and return only the necessary data to the model.

Enabling the feature is straightforward:

  • Add {"type": "programmatic_tool_calling"} to the request's tools array;
  • Include programmatic in the allowed_callers field of every tool that programs may invoke;
  • Consume the program and program_output items in the response, treating the latter as the execution result.

From Turn-by-Turn Calling to Programmatic Orchestration

Traditional tool calling commonly follows a loop: the model selects a tool, the platform executes it, the result returns to the model, and the model decides what to do next. Code Mode changes this into a different sequence: the model generates a program, Perplexity executes it, the program filters or aggregates the results, and the model receives only the relevant output.

| Dimension | Turn-by-turn tool calling | Code Mode | |---|---|---| | Model output | One tool name and argument set | A JavaScript program composing multiple calls | | Tool execution | Constrained by turn-by-turn orchestration | Multiple calls can run in parallel within one program | | Context flow | Multiple results may separately re-enter the model | The program returns only necessary data | | Dependencies and branching | Model decides over successive turns | Program control flow can organize call order | | Failure granularity | One call fails at a time | Partial success, aggregation failure, or already-executed side effects are possible |

Context and Latency Accounting

Ignoring server-side billing and prompt caching for simplicity, the contextual growth of conventional calling can be approximated as C_legacy ≈ Σ(O_i + I_i), where O_i is the ith tool output and I_i is the intermediate information carried into subsequent inference. Code Mode is closer to C_code ≈ I_program + Σ|F_j(O_j)| + I_final, where F_j represents filtering, transformation, or aggregation performed over raw tool output.

The benefit depends on whether the program compresses results correctly. A faulty filter may reduce context size while silently removing the evidence needed for a correct answer.

Parallelism has a similar boundary. Serial calls take approximately ΣT_i under ideal conditions, while parallel calls approach max(T_i) + T_exec + T_model. This is only an approximation without contention: API rate limits, MCP service queues, shared-resource contention, and retries can all make actual latency substantially worse.

Engineering Trade-offs

1. Latency Gains Have Two Sources

Code Mode can execute independent tool calls concurrently and can eliminate some model–tool–model inference round trips. JavaScript generation, parsing, and scheduling introduce their own overhead, however. For a strictly sequential dependency chain, parallelism offers little benefit and the additional orchestration layer may increase per-step latency.

2. Token Reduction Depends on Correct Data Selection

Returning only necessary data is the central promise of Code Mode, but necessity is not something the runtime can infer reliably in every case. A production implementation should bound the raw result size visible to the program, perform deterministic pagination, field projection, and redaction at the tool layer, and pass compact evidence to the model. This prevents a large input from causing generated code to overlook critical fields.

3. Failure Recovery Is More Complex

Only some calls in a parallel program may succeed. Developers must distinguish retryable network failures from non-retryable argument errors and from writes that already took effect. The latter require idempotency keys, compensating transactions, or human confirmation. Retrying an entire program without such controls can duplicate resource creation, charges, or outbound messages.

4. allowed_callers Is Not a Complete Security Boundary

allowed_callers controls which caller category may invoke a tool, but it does not replace least privilege, short-lived credentials, timeouts, rate limits, or auditing. Tools with write or external-communication capabilities still need independent authorization, parameter validation, and confirmation for sensitive operations. MCP servers may expose untrusted data; their output should remain a potential prompt-injection input even after program-level aggregation.

5. Observability Must Cover Programs and Individual Calls

Production systems should record the generated program, every tool invocation, latency, retries, payload sizes, and the final data returned to the model. Logging only the final answer cannot distinguish delays caused by code execution, tool queueing, or model inference. Logging all raw tool payloads, on the other hand, may expose sensitive data.

Evaluation Status and Test Matrix

The announcement confirms programmatic invocation, parallel execution, result filtering, and the program/program_output response structure. It does not publish end-to-end latency, token consumption, task success rate, unit cost, or a direct comparison with native tool calling. Code Mode's mechanism is therefore verifiable, but a deterministic performance improvement cannot yet be claimed.

At minimum, production evaluation should cover:

| Scenario | Primary validation targets | |---|---| | Parallel read-only queries | p50/p95 latency, rate-limit behavior, stable result ordering | | Dependency-bound call chains | Added orchestration overhead, error propagation, retry cost | | Very large tool responses | Preservation of critical fields, context tokens, storage cost | | Partial tool failure | Timeouts, circuit breaking, idempotent retries, partial-success handling | | Write operations | Duplicate execution, privilege boundaries, transaction consistency, human approval | | External MCP services | Untrusted output, prompt injection, service outages, credential isolation |

Core metrics should include total tool calls, model round trips, input and output tokens, end-to-end latency, task success rate, cost per task, and recovery attempts. The comparison should use the same model, tools, workloads, and success criteria for both orchestration modes.

Production Deployment Guidance

  1. Start with read-only tools: validate program orchestration against search, query, and metadata tools before exposing write operations.
  2. Tighten tool contracts: define stable schemas for inputs, outputs, and errors; avoid exposing unrestricted raw results to generated code.
  3. Bound execution resources: set concurrency limits, timeouts, maximum output size, loop limits, and retry budgets to prevent runaway call graphs.
  4. Make side effects idempotent: use idempotency keys, and route operations that cannot be safely retried into human approval or a compensation flow.
  5. Minimize MCP permissions: give every MCP Server separate credentials and directory scopes, and never reuse read-only credentials for write interfaces.
  6. Preserve end-to-end traces: correlate the model request, program, program_output, and individual calls to calculate actual cost and diagnose failures.

Practical Boundary

Code Mode is best suited to fan-out queries, cross-tool retrieval, result filtering and aggregation, and workflows that benefit from expressing several steps as one executable program. It does not automatically solve tool reliability, prompt injection, or transactional consistency. For side-effect-heavy workflows, programmatic orchestration provides a new control point rather than a security guarantee.

Architecturally, the important change is that the Agent API moves from message-level tool interaction to program-level orchestration: the model generates an execution plan, Perplexity runs it, and compact results return to the model. Its real value must be demonstrated with matched latency, token, cost, and success-rate measurements rather than inferred solely from parallelism and data reduction.


Source: Perplexity Changelog (2026-12-01)

— END —

Tags: #Perplexity #Agent API #Code Mode #MCP #Tool Calling

Editorial & Fact-Checking Note: This article is compiled from primary research, official release documentation, and source papers by the ZICQ Newsroom pipeline with automated entity verification and human editorial review. If you notice any technical inaccuracy, please submit a correction via our corrections policy or email our editorial desk directly.

What's your take on this story?
Explore & Submit Works

Community Comments

Loading live comments and annotations…