Skip to main content

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:
Output
The Go tab above is a complete program. The later Go tabs on this page are fragments that go inside func main() and call the sendChat helper below. The helper is a top-level declaration that reuses the imports and the obj alias of the program above. It posts one chat completions request, checks the HTTP status, and returns the assistant message. Raw holds the message as returned, ready to append to messages, and each tool call exposes its ID and Function.Arguments. Names such as fetchUserPreferences, analysisTool, and runAnalysis are application-defined: supply your own.
Go

Function Signature

Parameter functions receive a TurnContext and return the parameter value:

TurnContext

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