[ ABORT TO HUD ]
SEQ. 1
SEQ. 2
SEQ. 3
SEQ. 4
SEQ. 5
SEQ. 6
SEQ. 7
SEQ. 8

Programmatic Tool Calling

👥 Multi-Agent Systems10 min100 BASE XP

Letting the Model Write the Orchestration Code

The OpenAI Agents SDK's Programmatic Tool Calling (added in v0.19.0) changes how a model coordinates multiple tools. Instead of the usual back-and-forth - model calls one tool, waits for the result, decides the next call, repeats - a supported OpenAI Responses model can generate a short JavaScript program that calls several eligible tools directly, with loops or conditional logic, in a single turn.

Why It Matters

Classic sequential tool calling burns one round-trip (and one set of tokens) per tool invocation. For a task like "fetch these 20 records, then filter and sum them," that means 20+ back-and-forth turns. Programmatic Tool Calling lets the model express that as one small program instead - the SDK executes it and returns a single structured result.

from agents import Agent, Runner
from agents.tool import ProgrammaticToolCallingTool

# Eligible function tools become callable from generated code
agent = Agent(
    name="DataAnalyst",
    tools=[fetch_record, compute_stats],
    # Enables the model to write code that orchestrates the tools above
    tool_use_behavior=ProgrammaticToolCallingTool(allowed_callers=["fetch_record", "compute_stats"]),
)

result = await Runner.run(agent, "Fetch records 1-20 and give me the average of the 'score' field")
# The model may generate one program that loops fetch_record() 20x,
# then calls compute_stats() once - instead of 21 separate tool-call turns.

What's Included

  • Per-tool allowed_callers: You control exactly which tools are callable from generated code.
  • Structured function-tool outputs: Results keep their typed shape, not just raw strings.
  • Full integration: Works with Runner streaming, guardrails, approvals, sessions, and RunState - it's a drop-in extension of the existing tool-calling loop, not a separate system.
🎯 Pro Tip: Reach for Programmatic Tool Calling when a task is naturally a loop or pipeline over your existing tools (batch fetch-and-aggregate, multi-step filtering). For a single tool call, the classic one-call-per-turn pattern is simpler and easier to trace.
SYNAPSE VERIFICATION
QUERY 1 // 3
What does Programmatic Tool Calling let a supported OpenAI Responses model do?
Call only one tool per conversation
Generate a short program (e.g. with loops/conditionals) that coordinates several eligible tools in a single turn
Write its own system prompt
Bypass guardrails