Programmatic Tool Calling — Multi-Agent Systems
Programmatic Tool Calling
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
Runnerstreaming, guardrails, approvals, sessions, andRunState- it's a drop-in extension of the existing tool-calling loop, not a separate system.
Invoke registered agent tool functions directly in Python bypassing conversational overhead for deterministic batch workflows.