Skip to content

ToolLoopAgent: prepareCall types also omit toolChoice, maxRetries, prepareStep, and repairToolCall present at runtime #18518

Description

@hyamero

Description

Follow-up to #18478: the fix in #18482 added 'reasoning' to the two prepareCall Pick lists in packages/ai/src/agent/tool-loop-agent-settings.ts, but the same mismatch exists for other settings keys. The runtime contract is unchanged: prepareCall receives { ...settingsWithoutCallbacks, ...options } where only the ten on* callbacks are stripped, and its return value is spread wholesale into the generateText/streamText call. So every non-callback settings key is present on the input and honored on the return, yet these are missing from both Pick lists:

  • toolChoice: reading settings.toolChoice is TS2339 while the runtime value is there, and returning an override works (a returned toolChoice: 'none' reaches doGenerate as { type: 'none' }). Forcing or disabling tools based on call options is a core prepareCall use case.
  • maxRetries: same shape; the settings value is present at runtime and generateText accepts a returned override.
  • prepareStep: same; returning a per-call step configuration is a natural pattern for agents whose behavior varies per call.
  • repairToolCall (and the deprecated experimental_repairToolCall): same.

Expected: these keys added to both Pick lists, as #18482 did for reasoning. Happy to open a PR.

Related, in case it should be handled in the same pass: the input type is Omit<AgentCallParameters<...>, 'onStepEnd' | 'onStepFinish'> & Pick<...>, so it still advertises abortSignal, onStart, onEnd, and the other call-level callbacks. Those are destructured out before prepareCall is invoked and can never be present; they are optional so this compiles, but e.g. reading options.abortSignal to wire up cancellation silently yields undefined forever. Widening the Omit would make the input type match the runtime in both directions.

Reproduction

import { ToolLoopAgent } from 'ai';

new ToolLoopAgent({
  model: 'openai/gpt-5.2',
  toolChoice: 'auto', // OK: the constructor accepts all four
  maxRetries: 5,
  prepareStep: () => undefined,
  repairToolCall: async () => null,
  prepareCall: settings => ({
    ...settings,
    toolChoice: settings.toolChoice, // TS2339, runtime value: 'auto'
    maxRetries: settings.maxRetries, // TS2339, runtime value: 5
    prepareStep: settings.prepareStep, // TS2339
    repairToolCall: settings.repairToolCall, // TS2339
    reasoning: settings.reasoning, // OK since #18482
  }),
});

AI SDK Version

  • ai: 7.0.55 (Pick lists unchanged on current main)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions