Skip to content

fix: allow andAgent schema to accept Output.* specs (arrays, choi…#965

Merged
omeraplak merged 1 commit into
mainfrom
fix/and-agent-output
Jan 19, 2026
Merged

fix: allow andAgent schema to accept Output.* specs (arrays, choi…#965
omeraplak merged 1 commit into
mainfrom
fix/and-agent-output

Conversation

@omeraplak

@omeraplak omeraplak commented Jan 19, 2026

Copy link
Copy Markdown
Member

…ces, json, text)

PR Checklist

Please check if your PR fulfills the following requirements:

Bugs / Features

What is the current behavior?

What is the new behavior?

fixes (issue)

Notes for reviewers


Summary by cubic

andAgent now accepts ai-sdk Output.* specs (array, choice, json, text) as schemas, not just Zod objects. This fixes #964 and enables non-object step outputs with correct type inference.

  • Bug Fixes
    • Accept Output.* directly; Zod schemas are wrapped with Output.object automatically.
    • Added AgentOutputSchema, InferAgentOutput, and updated AgentConfig to preserve types across the chain and map.
    • Tests cover non-object outputs; docs include array/choice examples.

Written for commit 087f722. Summary will update on new commits.

Summary by CodeRabbit

  • New Features

    • andAgent now supports Output.* specs (arrays, choices, json, text) alongside Zod schemas, enabling flexible non-object output structures in workflow steps and matching agent.generateText flexibility
  • Documentation

    • Updated andAgent documentation with expanded examples demonstrating arrays, choices, and Output.* specification patterns for structured workflow outputs

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot

changeset-bot Bot commented Jan 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 087f722

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@voltagent/core Patch

Not sure what this means? Click here to learn what changesets are.

[Click here if you're a maintainer who wants to add another changeset to this PR](https://github.com/VoltAgent/voltagent/new/fix/and-agent-output?filename=.changeset/tiny-pans-allow.md&value=---%0A%22%40voltagent%2Fcore%22%3A%20patch%0A---%0A%0Afix%3A%20allow%20%60andAgent%60%20schema%20to%20accept%20%60Output.*%60%20specs%20(arrays%2C%20choi%E2%80%A6%0A)

@coderabbitai

coderabbitai Bot commented Jan 19, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Adds support for Output.* specs from the AI SDK to andAgent, enabling non-object structured outputs (arrays, choices, json, text) alongside Zod schemas. Introduces OutputSpec, AgentOutputSchema, and InferAgentOutput types with a runtime isOutputSpec guard to conditionally wrap schemas.

Changes

Cohort / File(s) Summary
Type System & Core Implementation
packages/core/src/workflow/steps/and-agent.ts
Introduces OutputSpec type, AgentOutputSchema union type (OutputSpec | z.ZodTypeAny), and InferAgentOutput conditional type for unified output type inference. Updates AgentConfig and AgentResultMapper to use AgentOutputSchema. Adds isOutputSpec runtime guard. Updates andAgent generic signature and internal result mapping to support both Output and Zod schemas.
Chain API Surface & Re-exports
packages/core/src/workflow/chain.ts
Re-exports AgentConfig from ./steps/and-agent. Updates 5+ overloads for andAgent and andThen to use AgentOutputSchema instead of z.ZodTypeAny, InferAgentOutput instead of z.infer, and WorkflowInput<INPUT_SCHEMA> for input typing. Broadens API surface to accommodate both schema types.
Type Inference Testing
packages/core/src/workflow/chain.spec-d.ts
Adds new TypeScript type test case verifying andAgent correctly infers output type as string[] when using Output.array schema.
Runtime Test Coverage
packages/core/src/workflow/steps/and-agent.spec.ts
Adds test case validating Output.array({ element: z.string() }) produces correct non-object string array output from mocked agent.
Documentation & Examples
website/docs/workflows/steps/and-agent.md
Clarifies dual schema paths (Zod vs. Output.\*), adds examples for Output.array and Output.choice, documents import requirement, and updates guidance on schema wrapping behavior.
Release Metadata
.changeset/tall-dryers-run.md
Patch-level changeset documenting new Output spec support.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 A schema that hops in many forms—
Zod objects, arrays, choices that swarm!
No longer boxed in by one rigid way,
Workflows now dance with Output.* play! 🎯

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: enabling andAgent to accept Output.* specs in addition to Zod schemas, which is the core feature addition.
Description check ✅ Passed The description covers all required template sections with substantive information, including checklist completion, current/new behavior explanation, issue reference (#964), and comprehensive auto-generated summary of changes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Comment @coderabbitai help to get the list of available commands and usage tips.

@ghost

This comment has been minimized.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying voltagent with  Cloudflare Pages  Cloudflare Pages

Latest commit: 087f722
Status: ✅  Deploy successful!
Preview URL: https://ae51530a.voltagent.pages.dev
Branch Preview URL: https://fix-and-agent-output.voltagent.pages.dev

View logs

@omeraplak
omeraplak merged commit 0feb8b0 into main Jan 19, 2026
23 checks passed
@omeraplak
omeraplak deleted the fix/and-agent-output branch January 19, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT] Align schema parameter with output parameter flexibility in agent and workflow definitions

1 participant