Speculative programmatic tool calling for code-acting harnesses
- Source
- alexzhang13.github.io
- Author
- alex zhang
- Date

Context
Speculative programmatic lets an AI agent that acts by writing code start its slow tool calls before it has finished writing that code. Alex Zhang of MIT CSAIL describes the technique, which he calls sPTC, in a blog post with published code. In the agents he has in mind, the model's one real tool is a , and everything else, such as a call to another , a sub-agent or a search API, is a function inside that code. Most agent harnesses wait for the model to finish writing a whole block of code before running any of it, so a slow sub-call cannot start until the block is complete, and two independent calls written one after the other also run one after the other.
sPTC reads the code while it is still streaming in. When a tool call's inputs are already known, for example a fixed text prompt, it launches the call in the background and keeps the pending result. When the finished code runs and reaches that call, it gets the stored result instead of starting again. For calls whose inputs depend on earlier variables, a separate copy of the interpreter runs the partial code as it arrives, so the real program state is never touched by unfinished code. To avoid side effects, functions such as file reads are marked unsafe, and any call that depends on one is not started early. Identical calls made several times, such as a majority vote across sub-agents, are tracked as separate instances so one early result is not handed to all of them.
The measured gain is small so far. Zhang ran his recursive language model harness, in which a model writes code that breaks a long input into pieces and calls a language model on each, on two long- tasks from the OOLONG benchmark, using Qwen3-30B-A3B served on eight H100 GPUs with five runs per setting. He reports speed-ups generally on the order of 1 to 1.2 times and says the benefit depends heavily on tool latency, how many tokens the model writes, server load and the path the agent takes. He expects the bigger long-term payoff from overlapping tool calls with the running program itself, and calls the current version already useful, especially for locally run models and agent harnesses.
The idea extends earlier speed-ups for ordinary tool calling that Zhang cites, such as Conveyor, which starts tool work during decoding, and AsyncFC, which lets function calls run concurrently as futures. His argument for code agents is that a single JSON-style tool call leaves little left to generate once it is fully written, while a program can keep going long after its first tool call, leaving more time to overlap. That is a design argument his numbers do not yet show paying off at scale. The costs he names are a copied interpreter in memory and, at worst, extra speculative requests crowding the tool's server.
- tool use — A model's ability to call external functions — run code, search the web, edit files — instead of only generating text.
- Agent code execution — Running model-generated commands or programs under controlled authority.
- Large language model — A model trained on large amounts of data to process and generate language.
- Context and context window — Context is the information available for a generation; the context window is the capacity available to hold it.
Checking sign-in…
Loading comments…


