Skip to main content
Code mode and tool search keep the model’s context small when an agent has many tools. Code mode keeps intermediate tool results out of the context, and tool search keeps the definitions of deferred tools out of each request until the model searches for them.

Code mode

Code mode is on by default. When the agent has a tool that a program can call, the run adds the built-in run_program tool, which lets the model write one JavaScript program that calls several tools. Only the program’s result is added to the model’s context. Programs run in a QuickJS sandbox without network or file system access. Their tool calls go through the same guardrails and approvals as direct calls, and count toward the agent’s maxToolCalls. To limit which tools a program can call, add a programTool from @restatedev/harness/program. It replaces the built-in run_program. Set codeMode: false to turn code mode off:
While code mode adds run_program to a run, no other tool can have that name: run throws a TypeError when it starts, and Restate retries the invocation. Tool search is on by default. A tool with deferred: true isn’t listed in the model request until the model finds it with the built-in search_tools tool. Tools from an MCP server are deferred by default. To list deferred tools from the start, set toolSearch: false:
While tool search adds search_tools to a run, which it does when a tool is deferred, no other tool can have that name: run throws a TypeError when it starts, and Restate retries the invocation.