Skip to main content
Pass a function instead of a fixed value when a later model turn should depend on application context or earlier results. The runtime calls it before every model request with the turn number, step index, messages, and context. Rust has no per-turn callbacks; it sets the model per run.

Change settings every turn

What you can change per turn

TypeScript, Python, PHP, and Ruby take a function in place of the fixed field. Go, C#, and Java use separate callback fields next to the fixed Model and Instructions. In TypeScript, tools left out of activeTools stay callable, so earlier calls still resolve. The turn argument has the same four values in every language: In Python, a model or preset passed to run() replaces the definition’s model for every turn.

Update application context from a tool

A tool can replace the application context that later turns read: context.setContext() in TypeScript, runtime.set_context() in Python, and the equivalents in Tools. Keep context small and serializable when you save runs and continue them later.

Override only the next turn

Set next-turn parameters on a tool to change the request that immediately follows it, without changing the agent definition. They win over the per-turn functions for that one turn.
Next-turn parameters accept the model, instructions, temperature, top-p, max output tokens, and tools, named in each language’s casing. In Python they are the only way to change the tool list between turns. If the tool waits for approval, its overrides are saved with the paused run and applied to the turn after you continue: Use per-turn functions for policy you want recalculated every turn, and next-turn parameters for a one-off handoff from a specific tool.

Set the model per run in Rust

Rust’s phaseo-agent 0.2 has no per-turn callbacks, context updates from tools, or next-turn parameters. Set the model, step limit, and application context per run with RunOptions:
Last modified on November 5, 2026