Repository navigation
fix(agents): support dict and types.Schema output_schema in task mode - #7966
Closed
shwetangsinha0509 wants to merge 1 commit into
Closed
shwetangsinha0509 wants to merge 1 commit into
shwetangsinha0509 wants to merge 1 commit into
Conversation
Contributor
Author
|
Closing as a duplicate of #7937, which was opened first for the same fix. I missed it before opening this one. |
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.
Fixes #7935
Problem
LlmAgent(mode="task")fails at construction whenoutput_schemais a raw dict or atypes.Schema, althoughSchemaTypedocuments both as supported and they work in the default andsingle_turnmodes.FinishTaskToolpassed the schema toTypeAdapter, which reads a dict as a pydantic core schema (SchemaError: Unknown schema type: "object", orKeyError: 'type'for{}) and cannot generate a schema from atypes.Schemainstance (PydanticSchemaGenerationError). The same failure was fixed forSetModelResponseToolin #5469.Fix
types.Schemaoutput schemas are converted directly to JSON Schema (model_dump(by_alias=True, exclude_none=True)+lowercase_schema_types, asanthropic_llm.pydoes) instead of going throughTypeAdapter.finish_taskarguments are accepted without validation, matching howvalidate_node_dataalready treats these schema types._get_declaration, which pops$defs, so the caller's schema is never mutated.Testing plan
Unit tests
6 new tests in
tests/unittests/agents/llm/task/test_finish_task_tool.py:result_get_declarationcalls ($defshoisting)types.Schemaconverted to lowercase JSON Schemarun_asyncwith a dict schema returns successThe 2 failures are
test_tool_node.py::test_execute_bash_tool_node_runs_command_after_approval[False|True](KeyError: 'returncode'). They fail the same way onmainwithout this change: I ran the suite on Windows, andExecuteBashToolneeds bash. Neither test touchesfinish_task.Manual check
Builds an
LlmAgentwith each schema type in the default mode and in task mode:Before (main):
After (this PR):