Next Turn Params

Build encapsulated, context-aware tools with nextTurnParams. Create skills systems, plugins, and adaptive multi-turn agents.

Why nextTurnParams?

Traditional tool execution returns results to the model, but sometimes you need more:

  • Skills/Plugins: Load domain-specific instructions when a skill is activated
  • Progressive Context: Build up context as tools are used
  • Adaptive Behavior: Adjust model parameters based on tool results
  • Clean Separation: Tools manage their own context requirements

With nextTurnParams, tools can modify any callModel parameter for the next turn.

Basic Example

The Claude Code Skills Pattern

This example shows how to recreate Claude Code’s skills system as a single encapsulated tool:

Key Benefits

  1. Encapsulation: Skill loading logic is entirely contained in the tool
  2. Idempotency: Built-in check prevents loading the same skill twice
  3. Clean API: Callers don’t need to know about skill file locations
  4. Composability: Multiple skills can be loaded across turns

Execution Order

Understanding when nextTurnParams runs is crucial:

Available Context

nextTurnParams functions receive two arguments:

params

The validated input parameters that were passed to the tool:

context

The current request context, including:

PropertyTypeDescription
inputOpenResponsesInputCurrent message history
modelstring | undefinedCurrent model selection
modelsstring[] | undefinedModel fallback array
instructionsstring | undefinedCurrent system instructions
temperaturenumber | undefinedCurrent temperature
maxOutputTokensnumber | undefinedCurrent max tokens
topPnumber | undefinedCurrent top-p sampling
topKnumber | undefinedCurrent top-k sampling

Modifiable Parameters

You can modify CallModelInput parameters:

Patterns

Research Context Accumulation

Build up context as research progresses:

Complexity-Based Model Selection

Upgrade to better models when needed:

Multi-Skill Loading

Load multiple skills at once:

Language/Locale Switching

Adapt to user language preferences:

Best Practices

Idempotency Checks

Always check if context was already added:

Type Safety

Use proper typing for context access:

Minimal Modifications

Only modify what’s necessary:

See Also