@@ -113,6 +113,9 @@ def run(
113113 extra_body : Body | None = None ,
114114 timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
115115 ) -> Union [TaskView , TaskViewWithOutput [BaseModel ]]:
116+ """
117+ Run a new task and return the task view.
118+ """
116119 if structured_output_json is not None and isinstance (structured_output_json , type ):
117120 create_task_res = self .create (
118121 task = task ,
@@ -128,9 +131,9 @@ def run(
128131 timeout = timeout ,
129132 )
130133
131- for msg in self .stream (create_task_res .id , structured_output_json = structured_output_json ):
132- if msg .status == "finished" :
133- return msg
134+ for structured_msg in self .stream (create_task_res .id , structured_output_json = structured_output_json ):
135+ if structured_msg .status == "finished" :
136+ return structured_msg
134137
135138 raise ValueError ("Task did not finish" )
136139
@@ -341,7 +344,7 @@ def retrieve(
341344 extra_query : Query | None = None ,
342345 extra_body : Body | None = None ,
343346 timeout : float | httpx .Timeout | None | NotGiven = NOT_GIVEN ,
344- ) -> TaskView :
347+ ) -> Union [ TaskView , TaskViewWithOutput [ BaseModel ]] :
345348 """
346349 Get detailed information about a specific AI agent task.
347350
@@ -390,14 +393,14 @@ def retrieve(
390393 )
391394
392395 if res .done_output is None :
393- return TaskViewWithOutput [structured_output_json ](
396+ return TaskViewWithOutput [BaseModel ](
394397 ** res .model_dump (),
395398 parsed_output = None ,
396399 )
397400
398401 parsed_output = structured_output_json .model_validate_json (res .done_output )
399402
400- return TaskViewWithOutput [structured_output_json ](
403+ return TaskViewWithOutput [BaseModel ](
401404 ** res .model_dump (),
402405 parsed_output = parsed_output ,
403406 )
@@ -462,14 +465,14 @@ def stream(
462465 ):
463466 if structured_output_json is not None and isinstance (structured_output_json , type ):
464467 if res .done_output is None :
465- yield TaskViewWithOutput [structured_output_json ](
468+ yield TaskViewWithOutput [BaseModel ](
466469 ** res .model_dump (),
467470 parsed_output = None ,
468471 )
469472 else :
470473 parsed_output = structured_output_json .model_validate_json (res .done_output )
471474
472- yield TaskViewWithOutput [structured_output_json ](
475+ yield TaskViewWithOutput [BaseModel ](
473476 ** res .model_dump (),
474477 parsed_output = parsed_output ,
475478 )
0 commit comments