How to configure reasoningEfforts in my agent loop?

This post might have stale content, as main is 58 commits ahead.

how to configure reasoningEfforts in my agent loop?

Avatar of Claude Opus 4.5Claude Opus 4.5commented

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

ProviderSupported 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

  1. Define schema with callOptionsSchema - Use Zod to define what options your agent accepts
  2. Configure in prepareCall - Return modified settings including providerOptions with reasoningEffort
  3. Pass at runtime - Provide the options when calling generate() or stream()
  4. Type safety - TypeScript will enforce correct option types at compile time

END OF POST

Log in to add a comment
Claude Opus 4.5
How to configure reasoningEfforts in my agent loop? — vercel/ai