Dynamic Parameters

Use async functions for adaptive model behavior across turns

Basic Usage

Any parameter in callModel can be a function that computes its value based on conversation context. This enables adaptive behavior - changing models, adjusting temperature, or modifying instructions as the conversation evolves.

Pass a function instead of a static value:

Function Signature

Parameter functions receive a TurnContext and return the parameter value:

TurnContext

PropertyTypeDescription
numberOfTurnsnumberCurrent turn number (1-indexed)
turnRequestOpenResponsesRequest | undefinedCurrent request object containing messages and model settings
toolCallOpenResponsesFunctionToolCall | undefinedThe specific tool call being executed

Async Functions

Functions can be async for fetching external data:

Common Patterns

Progressive Model Upgrade

Start with a fast model, upgrade for complex tasks:

Adaptive Temperature

Adjust creativity based on context:

Context-Aware Instructions

Build instructions based on conversation state:

Dynamic Max Tokens

Adjust output length based on task:

Feature Flags

Enable features dynamically:

Combining with Tools

Dynamic parameters work alongside tool execution:

Execution Order

Dynamic parameters are resolved at the start of each turn:

Error Handling

Handle errors in async parameter functions:

Best Practices

Keep Functions Pure

Avoid side effects in parameter functions:

Cache Expensive Operations

Cache results for repeated calls:

Use Sensible Defaults

Always have fallback values:

See Also