@@ -5155,6 +5155,35 @@ def foo() -> str:
51555155 assert wrapper_agent .name == 'wrapped'
51565156 assert wrapper_agent .output_type == agent .output_type
51575157 assert wrapper_agent .event_stream_handler == agent .event_stream_handler
5158+ assert wrapper_agent .output_json_schema () == snapshot (
5159+ {
5160+ 'type' : 'object' ,
5161+ 'properties' : {
5162+ 'result' : {
5163+ 'anyOf' : [
5164+ {
5165+ 'type' : 'object' ,
5166+ 'properties' : {
5167+ 'kind' : {'type' : 'string' , 'const' : 'final_result' },
5168+ 'data' : {
5169+ 'properties' : {'a' : {'type' : 'integer' }, 'b' : {'type' : 'string' }},
5170+ 'required' : ['a' , 'b' ],
5171+ 'type' : 'object' ,
5172+ },
5173+ },
5174+ 'required' : ['kind' , 'data' ],
5175+ 'additionalProperties' : False ,
5176+ 'title' : 'final_result' ,
5177+ 'description' : 'The final response which ends this conversation' ,
5178+ }
5179+ ]
5180+ }
5181+ },
5182+ 'required' : ['result' ],
5183+ 'additionalProperties' : False ,
5184+ }
5185+ )
5186+ assert wrapper_agent .output_json_schema (output_type = str ) == snapshot ({'type' : 'string' })
51585187
51595188 bar_toolset = FunctionToolset ()
51605189
@@ -6151,19 +6180,13 @@ def test_message_history_cannot_start_with_model_response():
61516180
61526181
61536182async def test_text_output_json_schema ():
6154- def llm (messages : list [ModelMessage ], info : AgentInfo ) -> ModelResponse :
6155- return ModelResponse (parts = [TextPart ('' )])
6156-
6157- agent = Agent (FunctionModel (llm ))
6183+ agent = Agent ('test' )
61586184 assert agent .output_json_schema () == snapshot ({'type' : 'string' })
61596185
61606186
61616187async def test_tool_output_json_schema ():
6162- def llm (messages : list [ModelMessage ], info : AgentInfo ) -> ModelResponse :
6163- return ModelResponse (parts = [TextPart ('' )])
6164-
61656188 agent = Agent (
6166- FunctionModel ( llm ) ,
6189+ 'test' ,
61676190 output_type = [ToolOutput (bool , name = 'alice' , description = 'Dreaming...' )],
61686191 )
61696192 assert agent .output_json_schema () == snapshot (
@@ -6196,7 +6219,7 @@ def llm(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
61966219 )
61976220
61986221 agent = Agent (
6199- FunctionModel ( llm ) ,
6222+ 'test' ,
62006223 output_type = [ToolOutput (bool , name = 'alice' ), ToolOutput (bool , name = 'bob' )],
62016224 )
62026225 assert agent .output_json_schema () == snapshot (
@@ -6245,11 +6268,8 @@ def llm(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
62456268
62466269
62476270async def test_native_output_json_schema ():
6248- def llm (messages : list [ModelMessage ], info : AgentInfo ) -> ModelResponse :
6249- return ModelResponse (parts = [TextPart ('' )])
6250-
62516271 agent = Agent (
6252- FunctionModel ( llm ) ,
6272+ 'test' ,
62536273 output_type = NativeOutput ([bool ], name = 'native_output_name' , description = 'native_output_description' ),
62546274 )
62556275 assert agent .output_json_schema () == snapshot (
@@ -6258,11 +6278,8 @@ def llm(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
62586278
62596279
62606280async def test_prompted_output_json_schema ():
6261- def llm (messages : list [ModelMessage ], info : AgentInfo ) -> ModelResponse :
6262- return ModelResponse (parts = [TextPart ('' )])
6263-
62646281 agent = Agent (
6265- FunctionModel ( llm ) ,
6282+ 'test' ,
62666283 output_type = PromptedOutput ([bool ], name = 'prompted_output_name' , description = 'prompted_output_description' ),
62676284 )
62686285 assert agent .output_json_schema () == snapshot (
@@ -6271,9 +6288,6 @@ def llm(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
62716288
62726289
62736290async def test_custom_output_json_schema ():
6274- def llm (messages : list [ModelMessage ], info : AgentInfo ) -> ModelResponse :
6275- return ModelResponse (parts = [TextPart ('' )])
6276-
62776291 HumanDict = StructuredDict (
62786292 {
62796293 'type' : 'object' ,
@@ -6283,7 +6297,7 @@ def llm(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
62836297 name = 'Human' ,
62846298 description = 'A human with a name and age' ,
62856299 )
6286- agent = Agent (FunctionModel ( llm ) , output_type = HumanDict )
6300+ agent = Agent ('test' , output_type = HumanDict )
62876301 assert agent .output_json_schema () == snapshot (
62886302 {
62896303 'type' : 'object' ,
@@ -6315,12 +6329,9 @@ def llm(messages: list[ModelMessage], info: AgentInfo) -> ModelResponse:
63156329
63166330
63176331async def test_override_output_json_schema ():
6318- def llm (messages : list [ModelMessage ], info : AgentInfo ) -> ModelResponse :
6319- return ModelResponse (parts = [TextPart ('' )])
6320-
6321- agent = Agent (FunctionModel (llm ))
6332+ agent = Agent ('test' )
63226333 assert agent .output_json_schema () == snapshot ({'type' : 'string' })
6323- output_type = ( [ToolOutput (bool , name = 'alice' , description = 'Dreaming...' )],)
6334+ output_type = [ToolOutput (bool , name = 'alice' , description = 'Dreaming...' )]
63246335 assert agent .output_json_schema (output_type = output_type ) == snapshot (
63256336 {
63266337 'type' : 'object' ,
0 commit comments