Repository navigation
feat(outputschema): let an agent ask OpenAI for strict structured output - #3286
Draft
danielle-mustillo wants to merge 1 commit into
Draft
danielle-mustillo wants to merge 1 commit into
danielle-mustillo wants to merge 1 commit into
Conversation
Add AgentTemplate outputSchemaStrict. When set, the Go ADK sends strict: true with the output schema on the Chat Completions and Responses APIs. The kagent Harness compiler rejects a strict schema that OpenAI would refuse: an object without additionalProperties false, a property missing from required, or an anyOf root. Signed-off-by: Danielle Mustillo <danielle.mustillo@solo.io>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What changes for users
An AgentTemplate can ask OpenAI and Azure OpenAI to follow its output schema while they generate (strict mode), instead of kagent only validating the answer afterward. It is opt-in per agent.
outputSchemaStrict(default)strictkeyoutputSchemaStrict: true, compatible schemastrict: trueon Chat Completionsresponse_format.json_schemaand on Responsestext.formatoutputSchemaStrict: true, no schemakubectl applyrefused:outputSchemaStrict requires outputSchema or outputSchemaFromoutputSchemaStrict: true, a property missing fromrequiredCompatible=False:the root object must list property "code" in requiredoutputSchemaStrict: true, an object withoutadditionalProperties: false(root, nested,items,anyOf,$defs)Compatible=False, naming the pathoutputSchemaStrict: true,anyOfat the rootCompatible=FalseResolves solo-io/enterprise-kagent#403. That issue asks for a per-agent switch because strict accepts fewer schemas than
outputSchemadoes, so turning it on for every agent would break schemas that work today.How
AgentTemplateSpec.outputSchemaStrict(bool), with a CEL rule that it needs a schema. It goes into the compiled config asADKOutputConfig.strict(proto field 3).go/adk/pkg/outputschema/strict.go, called from the kagent Harness compiler inadkconfig/runtime.go). It checks the rules OpenAI documents for strict mode: every object setsadditionalProperties: falseand lists every property inrequired, and the root does not useanyOf. OpenAI rejects a strict request that breaks them, so without this check the Agent would be Ready and every request would fail.OpenAIModel.StrictOutputSchemais set from the agent's output config. Both request builders addstrict: truewhen it is set. Azure uses the same model type.Testing
make -C go lint: 0 issues.CheckStricttable (7 cases), compiler accept/reject, request body hasstrict: trueon both APIs. The existing tests that requirestrictto be omitted by default still pass.go test ./adk/... ./core/internal/... ./api/...on macOS: all pass except packages that need a local Docker for Postgres (service/session,service/sandbox). Those are left to CI.Kind cluster, Azure OpenAI
gpt-4.1-mini, Chat CompletionsCompatible=False UnsupportedConfiguration,Ready=False400. Direct call shows Azure's reason12 levels of nesting exceeds limit of 10, which Azure returns only in strict mode. This proves the flag reaches the providerroot agent output is not valid JSONThe last row is not caused by this change. Ten direct streaming calls to the same deployment with the same prompt and
strict: truereturned valid JSON ten times. The failing kagent tasks reported about twice the output tokens of passing ones. The cause is inside kagent's request or response path and is still open.Strict's value shows on schemas with
formatandpattern(#3284). An earlier prototype with both changes went from 0/9 to 5/5 on the same Azure deployment. This PR does not depend on #3284.Open questions
OpenAI API error: 400 Bad Requestin the Task message.