Skip to content

feat(ai): structured output for ai/chat & ai/agent (ADR-0030) - #95

Merged
gustavobertoi merged 1 commit into
feat/agent-context-policyfrom
feat/agent-structured-output
Jun 4, 2026
Merged

gustavobertoi merged 1 commit into
feat/agent-context-policyfrom
feat/agent-structured-output

Conversation

@gustavobertoi

Copy link
Copy Markdown
Collaborator

Third "finish the agents" leaf PR. ADR-0030 tool-forced structured output.

Stacked on #94 (which is on #93). Merge order: #93 → #94 → this. Retargets to main after.

What

Opt-in: an outputSchema input (a list of {name,type,required,description} fields) makes ai/chat
and ai/agent return a validated object instead of free-form text (backward compatible — absent
= unchanged).

How

A single forced respond tool carries the schema (ParameterSchemaToJSONSchema) with
ToolChoice: "required"; the tool-call arguments are parsed and validated against the schema, with
one bounded repair retry, then FunctionError. Works on every provider (all support tool
calling — verified both openaicompat and anthropic map ToolChoice:"required"). The agent runs its
normal reasoning loop, then coerces the final answer. Logic in
internal/packages/functions/ai/structured.go.

Scope

Provider-native response_format/json_schema (Option B optimization, with a per-provider
capability map) is deferred. ADR-0030 Proposed → Accepted.

Verify

make lint 0 · make build ok · make test 710 pass · make swagger ok. Tests cover the
forced-respond happy path, validation (required/type), parse fallbacks, and the ai/chat structured
path end-to-end.

This completes the three leaf agent capabilities (0028/0029/0030). The orchestrator (0026) +
async-tools (0027) pair stays Proposed for reassessment.

🤖 Generated with Claude Code

…spond (ADR-0030)

Opt-in: an outputSchema input (list of {name,type,required,description}) makes the
node return a validated object instead of free-form text. A single forced
"respond" tool carries the schema (ParameterSchemaToJSONSchema) with
ToolChoice=required; the tool-call args are parsed and validated, with one
bounded repair retry. Works on every provider (all support tool calling). The
agent runs its normal loop then coerces the final answer. Absent outputSchema =
unchanged.

Provider-native response_format (Option B) deferred. ADR-0030 Proposed -> Accepted.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@gustavobertoi
gustavobertoi merged commit 44cec15 into feat/agent-context-policy Jun 4, 2026
1 check passed
@gustavobertoi
gustavobertoi deleted the feat/agent-structured-output branch June 4, 2026 06:19
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.

1 participant