@@ -6132,7 +6132,7 @@ def llm(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
61326132 return ModelResponse (parts = [TextPart ('' )])
61336133
61346134 agent = Agent (FunctionModel (llm ))
6135- assert agent .output_json_schema == snapshot ({'type' : 'string' })
6135+ assert agent .output_json_schema () == snapshot ({'type' : 'string' })
61366136
61376137
61386138async def test_tool_output_json_schema ():
@@ -6143,7 +6143,7 @@ def llm(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
61436143 FunctionModel (llm ),
61446144 output_type = [ToolOutput (bool , name = 'alice' , description = 'Dreaming...' )],
61456145 )
6146- assert agent .output_json_schema == snapshot (
6146+ assert agent .output_json_schema () == snapshot (
61476147 {
61486148 'type' : 'object' ,
61496149 'properties' : {
@@ -6176,7 +6176,7 @@ def llm(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
61766176 FunctionModel (llm ),
61776177 output_type = [ToolOutput (bool , name = 'alice' ), ToolOutput (bool , name = 'bob' )],
61786178 )
6179- assert agent .output_json_schema == snapshot (
6179+ assert agent .output_json_schema () == snapshot (
61806180 {
61816181 'type' : 'object' ,
61826182 'properties' : {
@@ -6229,7 +6229,7 @@ def llm(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
62296229 FunctionModel (llm ),
62306230 output_type = NativeOutput ([bool ], name = 'native_output_name' , description = 'native_output_description' ),
62316231 )
6232- assert agent .output_json_schema == snapshot (
6232+ assert agent .output_json_schema () == snapshot (
62336233 {'properties' : {'response' : {'type' : 'boolean' }}, 'required' : ['response' ], 'type' : 'object' }
62346234 )
62356235
@@ -6242,7 +6242,7 @@ def llm(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
62426242 FunctionModel (llm ),
62436243 output_type = PromptedOutput ([bool ], name = 'prompted_output_name' , description = 'prompted_output_description' ),
62446244 )
6245- assert agent .output_json_schema == snapshot (
6245+ assert agent .output_json_schema () == snapshot (
62466246 {'properties' : {'response' : {'type' : 'boolean' }}, 'required' : ['response' ], 'type' : 'object' }
62476247 )
62486248
@@ -6261,7 +6261,7 @@ def llm(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
62616261 description = 'A human with a name and age' ,
62626262 )
62636263 agent = Agent (FunctionModel (llm ), output_type = HumanDict )
6264- assert agent .output_json_schema == snapshot (
6264+ assert agent .output_json_schema () == snapshot (
62656265 {
62666266 'type' : 'object' ,
62676267 'properties' : {
@@ -6289,3 +6289,40 @@ def llm(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
62896289 'additionalProperties' : False ,
62906290 }
62916291 )
6292+
6293+
6294+ async def test_override_output_json_schema ():
6295+ def llm (messages : list [ModelMessage ], info : AgentInfo ) -> ModelResponse :
6296+ return ModelResponse (parts = [TextPart ('' )])
6297+
6298+ agent = Agent (FunctionModel (llm ))
6299+ assert agent .output_json_schema () == snapshot ({'type' : 'string' })
6300+ output_type = ([ToolOutput (bool , name = 'alice' , description = 'Dreaming...' )],)
6301+ assert agent .output_json_schema (output_type = output_type ) == snapshot (
6302+ {
6303+ 'type' : 'object' ,
6304+ 'properties' : {
6305+ 'result' : {
6306+ 'anyOf' : [
6307+ {
6308+ 'type' : 'object' ,
6309+ 'properties' : {
6310+ 'kind' : {'type' : 'string' , 'const' : 'alice' },
6311+ 'data' : {
6312+ 'properties' : {'response' : {'type' : 'boolean' }},
6313+ 'required' : ['response' ],
6314+ 'type' : 'object' ,
6315+ },
6316+ },
6317+ 'required' : ['kind' , 'data' ],
6318+ 'additionalProperties' : False ,
6319+ 'title' : 'alice' ,
6320+ 'description' : 'Dreaming...' ,
6321+ }
6322+ ]
6323+ }
6324+ },
6325+ 'required' : ['result' ],
6326+ 'additionalProperties' : False ,
6327+ }
6328+ )
0 commit comments