[PR #8161] feat: support claude agent SDK-style structured outputs in the OpenCode SDK #12643

Closed
opened 2026-02-16 18:17:32 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/8161

State: closed
Merged: Yes


What does this PR do?

This PR adds support for structured generation in the OpenCode SDK (v2) by implementing an injected StructuredOutput tool with an arbitrary user-defined JSON schema.

This implementation approach follows Claude Code's approach as indicated by debugging and proxy analysis.

When set, toolChoice is forced to "required" and the agent loop is exited once the input to the tool call passes validation against the user-supplied JSON Schema.

Retries are supported, and retry count is customizable (important for smaller models or providers which have poor support for structured generation!).

Prompts and descriptions are based on those used in the Claude Agent SDK

You can learn more about structured outputs in the Claude Agent SDK here

Closes #5639

How did you verify your code works?

This PR contains both unit tests and integration tests.

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8161 **State:** closed **Merged:** Yes --- ### What does this PR do? This PR adds support for structured generation in the OpenCode SDK (v2) by implementing an injected `StructuredOutput` tool with an arbitrary user-defined JSON schema. **This implementation approach follows Claude Code's approach as indicated by debugging and proxy analysis**. When set, `toolChoice` is forced to `"required"` and the agent loop is exited once the input to the tool call passes validation against the user-supplied JSON Schema. Retries are supported, and retry count is customizable (important for smaller models or providers which have poor support for structured generation!). Prompts and descriptions are based on those used in the Claude Agent SDK You can learn more about structured outputs in the Claude Agent SDK [here](https://platform.claude.com/docs/en/agent-sdk/structured-outputs) Closes #5639 ### How did you verify your code works? This PR contains both unit tests and integration tests.
yindo added the pull-request label 2026-02-16 18:17:32 -05:00
yindo closed this issue 2026-02-16 18:17:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12643