How to configure reasoningEfforts in my agent loop?
how to configure reasoningEfforts in my agent loop?
I'll help you find information about configuring reasoningEffort in an agent loop. Let me search the codebase for relevant code and documentation.
I found many results. Let me look at the specific documentation for configuring call options in agent loops, and also check out the example files that show how to use reasoningEffort in agents.
Let me also read more of the documentation to get the complete picture:
Now I have all the information needed. Here's how to configure reasoningEffort in your agent loop:
##Configuring reasoningEffort in an Agent Loop
You can configure reasoningEffort in your agent loop using call options with the prepareCall callback. This allows you to dynamically set the reasoning effort based on runtime context.
###Basic Example
Here's a complete example from the codebase:
import { openai, OpenAIResponsesProviderOptions } from '@ai-sdk/openai';
import { ToolLoopAgent } from 'ai';
import { z } from 'zod';
const agent = new ToolLoopAgent({
model: openai('gpt-5-mini'),
// 1. Define the schema for your call options
callOptionsSchema: z.object({
reasoningEffort: z.enum(['low', 'medium', 'high']),
}),
// 2. Use prepareCall to configure provider options dynamically
prepareCall: ({ options, ...rest }) => ({
...rest,
providerOptions: {
openai: {
reasoningEffort: options?.reasoningEffort ?? 'medium',
reasoningSummary: 'detailed',
} satisfies OpenAIResponsesProviderOptions,
},
}),
});
// 3. Pass the options at runtime
const result = await agent.generate({
prompt: 'Analyze this complex scenario...',
options: {
reasoningEffort: 'high', // or 'low', 'medium'
},
});
###Pattern: Map Task Difficulty to Reasoning Effort
From the documentation, you can also map a semantic "task difficulty" to the reasoning effort:
import { openai, OpenAIProviderOptions } from '@ai-sdk/openai';
import { ToolLoopAgent } from 'ai';
import { z } from 'zod';
const agent = new ToolLoopAgent({
model: 'openai/o3',
callOptionsSchema: z.object({
taskDifficulty: z.enum(['low', 'medium', 'high']),
}),
prepareCall: ({ options, ...settings }) => ({
...settings,
providerOptions: {
openai: {
reasoningEffort: options.taskDifficulty,
} satisfies OpenAIProviderOptions,
},
}),
});
await agent.generate({
prompt: 'Analyze this complex scenario...',
options: { taskDifficulty: 'high' },
});
###Available reasoningEffort Values by Provider
| Provider | Supported Values |
|---|---|
| OpenAI | 'none', 'minimal', 'low', 'medium', 'high', 'xhigh' |
| Azure | 'low', 'medium', 'high' |
| xAI | 'low', 'medium', 'high' (chat), 'low', 'high' (responses) |
| Groq | 'low', 'medium', 'high', 'none', 'default' |
Note: Some values are model-specific. For example,
'none'is only for OpenAI GPT-5.1 models, and'xhigh'is only for GPT-5.1-Codex-Max.
###Key Points
- Define schema with
callOptionsSchema- Use Zod to define what options your agent accepts - Configure in
prepareCall- Return modified settings includingproviderOptionswithreasoningEffort - Pass at runtime - Provide the options when calling
generate()orstream() - Type safety - TypeScript will enforce correct option types at compile time
END OF POST
Claude Opus 4.5