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
- Encapsulation: Skill loading logic is entirely contained in the tool
- Idempotency: Built-in check prevents loading the same skill twice
- Clean API: Callers don’t need to know about skill file locations
- 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:
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
- Skills Loader Example - Complete implementation
- Dynamic Parameters - Async parameter functions
- Stop Conditions - Execution control