Repository navigation
feat: support structured output in JSON Schema over A2A DataPart #2890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
191d515
go adk: model providers support
supreme-gg-gg 3ad2baf
crd
supreme-gg-gg 25bc8a0
translator, outputschema validation, agent config and llm generate co…
supreme-gg-gg 32aa3b5
docs and fix crd
supreme-gg-gg 30cd670
a2a executor
supreme-gg-gg 75e80d3
e2e tests for structued output
supreme-gg-gg cd09123
ui changes for structured output
supreme-gg-gg 28a00fc
fixes
supreme-gg-gg 1fc6f69
fix test and lint
supreme-gg-gg 16be966
review comments
supreme-gg-gg 87adb70
function cleanup
supreme-gg-gg 0adb9f8
review comments 2
supreme-gg-gg c1fb364
add ConfigMapKeyReference to replace agenttemplate specific type
supreme-gg-gg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # Structured Output | ||
|
|
||
| An `AgentTemplate` can declare a JSON Schema for its successful terminal | ||
| response. The schema is either written inline in `spec.outputSchema` or stored | ||
| as JSON in a same-namespace ConfigMap selected by `spec.outputSchemaFrom`. The | ||
| two fields are mutually exclusive. | ||
|
|
||
| ```yaml | ||
| apiVersion: kagent.dev/v1alpha3 | ||
| kind: AgentTemplate | ||
| metadata: | ||
| name: data-extractor | ||
| spec: | ||
| modelConfig: | ||
| name: default-model-config | ||
| outputSchema: | ||
| type: object | ||
| properties: | ||
| status: | ||
| type: string | ||
| payload: | ||
| type: object | ||
| required: [status, payload] | ||
| additionalProperties: false | ||
| ``` | ||
|
|
||
| The translator resolves ConfigMap references, validates the portable schema | ||
| profile, and records a canonical schema and digest in the immutable prepared | ||
| revision. Invalid schemas and unsupported Harnesses fail compilation. The | ||
| kagent Harness supports structured output in its Go ADK runtime; | ||
| Codex, Claude, and BYO Harnesses do not currently support it. | ||
|
|
||
| The contract belongs to the public root agent. It is not inherited by local | ||
| child agents or agent tools. If a child template is compiled and invoked as a | ||
| root agent, its own schema applies to that independent revision. | ||
|
|
||
| ## A2A response contract | ||
|
|
||
| The runtime suppresses partial root-answer fragments, validates the complete | ||
| value, and publishes the successful result as one A2A `DataPart` with media | ||
| type `application/json`. The part also carries the canonical schema digest in | ||
| `kagent.dev/a2a/output-schema-sha256`. The generated Agent Card advertises | ||
| `application/json` as its default output mode. | ||
|
|
||
| Progress updates, tool events, approval requests, and input-required messages | ||
| keep their existing representations. Consequently, a streaming client that | ||
| only needs the answer reads the last content-bearing artifact before the Task | ||
| reaches `TASK_STATE_COMPLETED`. The gateway persists and relays these events | ||
| without interpreting the structured payload. | ||
|
|
||
| Structured output has no text fallback. Provider refusal, incomplete output, | ||
| invalid JSON, or schema validation failure fails the Task. Invalid model output | ||
| is not published or included in errors because it may contain sensitive data. | ||
|
|
||
| ## Portable schema profile | ||
|
|
||
| Schemas must have an object root. The portable profile supports primitive JSON | ||
| types, nested objects and arrays, `properties`, `required`, | ||
| `additionalProperties`, `items`, `enum`, `const`, `anyOf`, titles and | ||
| descriptions, and non-recursive local references through `$defs`. | ||
|
|
||
| External or recursive references, conditional schemas, tuple arrays, and other | ||
| unsupported keywords are rejected during compilation rather than silently | ||
| weakened for a provider. A provider or model can still reject structured output | ||
| at runtime; in that case the Task fails. | ||
|
|
||
| The serialized schema is limited to 64 KiB. Conversion to the Go ADK schema is | ||
| also limited to 32 levels and 1,000 expanded schema nodes; these bounds include | ||
| nodes expanded through local `$defs` references. Schemas that exceed any limit | ||
| fail compilation. | ||
|
|
||
| The semantic resolution code is in | ||
| [`go/core/internal/translator/outputschema.go`](../../go/core/internal/translator/outputschema.go). | ||
| Runtime validation and A2A conversion are owned by the Go kagent ADK executor. | ||
|
|
||
| ## References | ||
|
|
||
| - [OpenAI Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs) | ||
| - [Gemini structured outputs](https://ai.google.dev/gemini-api/docs/structured-output) | ||
| - [Claude structured outputs](https://platform.claude.com/docs/en/build-with-claude/structured-outputs) | ||
| - [Amazon Bedrock structured outputs](https://docs.aws.amazon.com/bedrock/latest/userguide/structured-output.html) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#2896 also rewrites this callback, conflicts on merge
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @mesutoezdil can you avoid leaving this type of comments since they're not too constructive. Merge conflicts are natural and authors are expected to rebase on top, this simply adds more noise during reviews. Unless the changes across PRs are going in opposite directions, in which case it might be worthwhile to bring the author's attention to it and drive some discussion, otherwise this type of comment don't add any value, as in the case here and in a few other PRs that you left similar comments before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair point, noted 👍🏽 thx for feedback