Skip to content

Conversation

@g-eoj
Copy link
Contributor

@g-eoj g-eoj commented Nov 17, 2025

This PR adds a method to get the json schema for agent output.

It aims to support all output types, including special ones:

  • text only
  • BinaryImage
  • DeferredToolRequests

Simple example:

agent = Agent('test')
print(agent.output_json_schema())
print(agent.output_json_schema(output_type=bool))
{'type': 'string'}
{'type': 'object', 'properties': {'result': {'anyOf': [{'type': 'object', 'properties': {'kind': {'type': 'string', 'const': 'final_result'}, 'data': {'properties': {'response': {'type': 'boolean'}}, 'required': ['response'], 'type': 'object'}}, 'required': ['kind', 'data'], 'additionalProperties': False, 'title': 'final_result'}]}}, 'required': ['result'], 'additionalProperties': False}

Closes #3225

@g-eoj
Copy link
Contributor Author

g-eoj commented Nov 17, 2025

@DouweM is there a source of truth I can reference for what the schema output should be for tests? I think I will get stuck figuring this out so any guidance will be appreciated.

Edit: I added snapshots of expected output to the tests. Please review them carefully as I'm guessing what they are supposed to be.

@g-eoj g-eoj marked this pull request as ready for review November 17, 2025 21:23
@g-eoj g-eoj changed the title Add output_json_schema property to Agents Add output_json_schema method to Agent class Nov 19, 2025
if isinstance(output, ObjectOutputProcessor):
processor = output
else:
processor = ObjectOutputProcessor(output=output, strict=strict)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did we need to change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modify UnionOutputProcessor so that toolset output processors can be unioned with additional output types (like str, BinaryImage, DeferredToolRequests). Maybe I shouldn't be using toolset.processors?

@g-eoj
Copy link
Contributor Author

g-eoj commented Nov 21, 2025

@DouweM thanks for the reviews so far.

The PR has an issue where it always adds str to the output schema if the AutoOutputSchema is selected. However I think this is due to a bug not caused by the PR. I think it is because

text_processor=processor,
will always set allows_text to True. This doesn't seem right but I'll wait for confirmation.

@g-eoj g-eoj requested a review from DouweM November 21, 2025 23:38
@g-eoj g-eoj marked this pull request as draft November 21, 2025 23:45
@g-eoj g-eoj marked this pull request as ready for review November 22, 2025 00:43
@g-eoj g-eoj marked this pull request as draft November 22, 2025 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add method to get an agent's output JSON schema

2 participants