Let an explicit `output_type=str` override the spec's `output_schema` in `Agent.from_spec` and `Agent.from_file`
- Closes #10952
Agent.from_spec() determined if output_type was passed by checking output_type is not str, so an explicit str was treated as omitted and the spec's output_schema won, contrary to the documented behaviour.
Instead, default output_type to None in from_spec and from_file. Let their overloads without output_type accept None (similar to Agent.run()), and check is not None.
Same as before, I wasn't sure if this was considered 'trivial' or not, so opened an issue first.
[!WARNING]
Compatibility impact: Code that passes output_type=str to Agent.from_spec() or Agent.from_file() with a spec that has an output_schema now gets str output instead of the schema's dict.
Why this can ship in a minor release: The version policy allows bug fixes that break code relying on undocumented behaviour, and the docs say output_type takes precedence over output_schema.
Migration: To keep the schema's dict output, don't pass output_type.
It uses None rather than a dedicated sentinel like _utils.UNSET because None on its own was never a valid output type, and from_spec()'s other keywords that override spec fields already default to None. An explicit output_type=None now means the same as omitting it and is typed Agent[..., str], instead of raising UserError.
from_file() now passes output_type before model when it calls from_spec(). To match the overloads, pyright splits union arguments in order, and it gives up on model's large KnownModelName literal union before reaching output_type.
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver.
- PR title is fit for the release changelog.