Skip to content

[BUG] AI_NoOutputGeneratedError when using Agent.generateText with both tools and Output.object #1145

@ouarrho

Description

@ouarrho

Describe the bug

When passing an Output.object({ schema }) to an Agent's generateText method while the Agent also has tools configured, it throws an AI_NoOutputGeneratedError.

It seems that the underlying execution cannot handle tool calling and structured output at the same time, but the error message is vague and it's unclear if this is an intended limitation or a bug in how the model response is parsed.

Steps To Reproduce

Create an Agent with a tool configured.
Call generateText on the Agent, and pass output: Output.object({ schema }) in the options.
Observe the AI_NoOutputGeneratedError error.
Code Snippet:

import { Agent } from '@voltagent/core'
import { Output } from 'ai'
import { z } from 'zod'
const myTool = /* ... valid tool definition ... */
const myAgent = new Agent({
  name: 'Test Agent',
  instructions: 'Use tools and return a structured response.',
  model: /* ... your model (e.g., google('gemini-1.5-flash')) ... */,
  tools: [myTool],
})
const schema = z.object({
  message: z.string(),
})
// This call throws AI_NoOutputGeneratedError
const result = await myAgent.generateText("Hello, do something and return the schema", {
  output: Output.object({ schema }),
})

Expected behavior

The Agent should either:

Successfully use the tools, finish its reasoning, and then return the final payload matching the Zod schema.
OR, if combining tools and Output.object is strictly not supported by design, it should throw a clear, descriptive validation error immediately (e.g., "Cannot use Output.object when tools are enabled. Use a two-step workflow instead.") rather than failing parsing with AI_NoOutputGeneratedError.

Packages

@voltagent/core: 2.6.6
ai version 6.0.111

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions