Repository navigation
LCORE-4717: map text.format to the agent output type - #3355
max-svistunov wants to merge 3 commits into
Conversation
text.format is the output contract of a /v1/responses request. On the pydantic-ai path the agent enforces it through output_type, so add OutputSettings next to the other per-request agent settings (design, section 4.8). from_responses_request reads the format: type text or no format is plain text; json_object is a free-form object; json_schema is the client's schema with its name and description. output_type_for wraps the structured type in the output mode the selected model's profile can honor: native when the model supports JSON schema output, tool-based when it supports tools, prompted otherwise; strict reaches the native and tool wrappers. A json_schema format without a schema or a name, or whose schema does not describe an object, is a 422 raised when the settings are built, before any model call. The format type itself is validated by the request model. text.verbosity is not part of the output type. Deferred client function calls join the output type in the next commit.
…ction tools A function tool the client executes itself ends the agent run with a call the client has to answer. pydantic-ai models that as DeferredToolRequests in the output type, so when the request declares function tools OutputSettings records it and output_type_for returns the union of the contract (str or the structured type in its output mode) and DeferredToolRequests. Server-side tools, MCP and file search, run inside the loop and do not change the output type. AgentSettings gains an output field, plain text for a query, so the agent factory can pass the output type to the agent once the Responses adapter builds the settings from a request.
|
No actionable comments were generated in the recent review. WalkthroughThe change adds ChangesResponses output settings
Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Feature Sequence Diagram(s)sequenceDiagram
participant ResponsesRequest
participant OutputSettings
participant ModelProfile
ResponsesRequest->>OutputSettings: parse text.format and validate schema
OutputSettings->>ModelProfile: select structured output contract
ModelProfile-->>OutputSettings: provide model capabilities
Possibly related PRs
Suggested reviewers: Merge Risk:
|
…xplicitly Code scanning flagged the assert that guarded the schema of a json_schema format: an assert is dropped under optimized byte code and is not a contract. from_responses_request never builds such settings, but settings assembled by hand can; they now get the same 422 the request path gives.
Description
LCORE-4717:
OutputSettings, the per-request agent setting that mapstext.formatof a/v1/responsesrequest to the agent'soutput_type(designpai-responses-lcore-rewrite.md, section 4.8). It follows the shape of the other settings insrc/agent/types/settings/(#3204): a dataclass with afrom_responses_requestconstructor, so the Responses input adapter (LCORE-4718) builds it the same way as the rest. Two commits:OutputSettings.from_responses_request(params)andoutput_type_for(profile): typetextor no format isstr;json_objectis aStructuredDictover a free-form object;json_schemais aStructuredDictover the client's schema with its name and description. The structured type is wrapped in the output mode the selected model's profile can honor: native when the model supports JSON schema output, tool-based when it supports tools, prompted otherwise;strictreaches the native and tool wrappers. Ajson_schemaformat without a schema or a name, or whose schema does not describe an object, is a 422 raised when the settings are built, before any model call. The format type itself is validated by the request model.text.verbosityis not part of the output type.DeferredToolRequestsjoins the output type so a function call can end the run; server-side tools (MCP, file search) run inside the loop and do not.AgentSettingsgains anoutputfield, plain text for a query.The agent factory does not read the field yet; passing the output type to the agent is one line there once the adapter (LCORE-4718) fills it. No API or configuration change.
Type of change
pyproject.toml+uv.lock]requirements.*.txtfor Konflux]Tools used to create PR
Identify any AI code assistants used in this PR (for transparency and review context)
Related Tickets & Documents
Checklist before requesting a review
Testing
Run the mapper's tests:
20 tests: text and absent formats, the free-form
json_objectschema, a client schema with name and description,strict, the three output modes by profile and the fallback for an unknown profile, four incomplete or invalid schemas rejected with 422 and a cause naming what is missing, and the deferred-tools union (text and structured, server tools excluded, and a pydantic-aiAgentaccepting the produced union), and the plain-text default onAgentSettings.ruff, black, pydocstyle, mypy, pyright and pylint (10.00) are clean on the touched files; the settings tests of #3204 still pass. No stack run: the function has no caller yet.
Summary by CodeRabbit