@@ -3672,8 +3672,13 @@ def _handle_batch_response(
36723672 tool_name = tool_call .function .name # type: ignore[union-attr]
36733673 tool_call_id = tool_call .id
36743674 args = json .loads (tool_call .function .arguments ) # type: ignore[union-attr]
3675+ extra_content = getattr (tool_call , 'extra_content' , None )
3676+
36753677 tool_call_request = ToolCallRequest (
3676- tool_name = tool_name , args = args , tool_call_id = tool_call_id
3678+ tool_name = tool_name ,
3679+ args = args ,
3680+ tool_call_id = tool_call_id ,
3681+ extra_content = extra_content ,
36773682 )
36783683 tool_call_requests .append (tool_call_request )
36793684
@@ -3766,7 +3771,12 @@ def _execute_tool(
37663771 logger .warning (f"{ error_msg } with result: { result } " )
37673772
37683773 return self ._record_tool_calling (
3769- func_name , args , result , tool_call_id , mask_output = mask_flag
3774+ func_name ,
3775+ args ,
3776+ result ,
3777+ tool_call_id ,
3778+ mask_output = mask_flag ,
3779+ extra_content = tool_call_request .extra_content ,
37703780 )
37713781
37723782 async def _aexecute_tool (
@@ -3808,7 +3818,13 @@ async def _aexecute_tool(
38083818 error_msg = f"Error executing async tool '{ func_name } ': { e !s} "
38093819 result = f"Tool execution failed: { error_msg } "
38103820 logger .warning (error_msg )
3811- return self ._record_tool_calling (func_name , args , result , tool_call_id )
3821+ return self ._record_tool_calling (
3822+ func_name ,
3823+ args ,
3824+ result ,
3825+ tool_call_id ,
3826+ extra_content = tool_call_request .extra_content ,
3827+ )
38123828
38133829 def _record_tool_calling (
38143830 self ,
@@ -3817,6 +3833,7 @@ def _record_tool_calling(
38173833 result : Any ,
38183834 tool_call_id : str ,
38193835 mask_output : bool = False ,
3836+ extra_content : Optional [Dict [str , Any ]] = None ,
38203837 ):
38213838 r"""Record the tool calling information in the memory, and return the
38223839 tool calling record.
@@ -3829,6 +3846,9 @@ def _record_tool_calling(
38293846 mask_output (bool, optional): Whether to return a sanitized
38303847 placeholder instead of the raw tool output.
38313848 (default: :obj:`False`)
3849+ extra_content (Optional[Dict[str, Any]], optional): Additional
3850+ content associated with the tool call.
3851+ (default: :obj:`None`)
38323852
38333853 Returns:
38343854 ToolCallingRecord: A struct containing information about
@@ -3842,6 +3862,7 @@ def _record_tool_calling(
38423862 func_name = func_name ,
38433863 args = args ,
38443864 tool_call_id = tool_call_id ,
3865+ extra_content = extra_content ,
38453866 )
38463867 func_msg = FunctionCallingMessage (
38473868 role_name = self .role_name ,
@@ -3852,6 +3873,7 @@ def _record_tool_calling(
38523873 result = result ,
38533874 tool_call_id = tool_call_id ,
38543875 mask_output = mask_output ,
3876+ extra_content = extra_content ,
38553877 )
38563878
38573879 # Use precise timestamps to ensure correct ordering
@@ -3986,7 +4008,7 @@ def _stream_response(
39864008 return
39874009
39884010 # Handle streaming response
3989- if isinstance (response , Stream ):
4011+ if isinstance (response , Stream ) or inspect . isgenerator ( response ) :
39904012 (
39914013 stream_completed ,
39924014 tool_calls_complete ,
@@ -4283,6 +4305,7 @@ def _accumulate_tool_calls(
42834305 'id' : '' ,
42844306 'type' : 'function' ,
42854307 'function' : {'name' : '' , 'arguments' : '' },
4308+ 'extra_content' : None ,
42864309 'complete' : False ,
42874310 }
42884311
@@ -4306,6 +4329,14 @@ def _accumulate_tool_calls(
43064329 tool_call_entry ['function' ]['arguments' ] += (
43074330 delta_tool_call .function .arguments
43084331 )
4332+ # Handle extra_content if present
4333+ if (
4334+ hasattr (delta_tool_call , 'extra_content' )
4335+ and delta_tool_call .extra_content
4336+ ):
4337+ tool_call_entry ['extra_content' ] = (
4338+ delta_tool_call .extra_content
4339+ )
43094340
43104341 # Check if any tool calls are complete
43114342 any_complete = False
@@ -4410,6 +4441,7 @@ def _execute_tool_from_stream_data(
44104441 function_name = tool_call_data ['function' ]['name' ]
44114442 args = json .loads (tool_call_data ['function' ]['arguments' ])
44124443 tool_call_id = tool_call_data ['id' ]
4444+ extra_content = tool_call_data .get ('extra_content' )
44134445
44144446 if function_name in self ._internal_tools :
44154447 tool = self ._internal_tools [function_name ]
@@ -4425,6 +4457,7 @@ def _execute_tool_from_stream_data(
44254457 func_name = function_name ,
44264458 args = args ,
44274459 tool_call_id = tool_call_id ,
4460+ extra_content = extra_content ,
44284461 )
44294462
44304463 # Then create the tool response message
@@ -4436,6 +4469,7 @@ def _execute_tool_from_stream_data(
44364469 func_name = function_name ,
44374470 result = result ,
44384471 tool_call_id = tool_call_id ,
4472+ extra_content = extra_content ,
44394473 )
44404474
44414475 # Record both messages with precise timestamps to ensure
@@ -4481,6 +4515,7 @@ def _execute_tool_from_stream_data(
44814515 func_name = function_name ,
44824516 result = result ,
44834517 tool_call_id = tool_call_id ,
4518+ extra_content = extra_content ,
44844519 )
44854520
44864521 self .update_memory (func_msg , OpenAIBackendRole .FUNCTION )
@@ -4512,6 +4547,7 @@ async def _aexecute_tool_from_stream_data(
45124547 function_name = tool_call_data ['function' ]['name' ]
45134548 args = json .loads (tool_call_data ['function' ]['arguments' ])
45144549 tool_call_id = tool_call_data ['id' ]
4550+ extra_content = tool_call_data .get ('extra_content' )
45154551
45164552 if function_name in self ._internal_tools :
45174553 # Create the tool call message
@@ -4523,6 +4559,7 @@ async def _aexecute_tool_from_stream_data(
45234559 func_name = function_name ,
45244560 args = args ,
45254561 tool_call_id = tool_call_id ,
4562+ extra_content = extra_content ,
45264563 )
45274564 assist_ts = time .time_ns () / 1_000_000_000
45284565 self .update_memory (
@@ -4569,6 +4606,7 @@ async def _aexecute_tool_from_stream_data(
45694606 func_name = function_name ,
45704607 result = result ,
45714608 tool_call_id = tool_call_id ,
4609+ extra_content = extra_content ,
45724610 )
45734611 func_ts = time .time_ns () / 1_000_000_000
45744612 self .update_memory (
@@ -4602,6 +4640,7 @@ async def _aexecute_tool_from_stream_data(
46024640 func_name = function_name ,
46034641 result = result ,
46044642 tool_call_id = tool_call_id ,
4643+ extra_content = extra_content ,
46054644 )
46064645 func_ts = time .time_ns () / 1_000_000_000
46074646 self .update_memory (
@@ -4911,6 +4950,11 @@ def _record_assistant_tool_calls_message(
49114950 "arguments" : tool_call_data ["function" ]["arguments" ],
49124951 },
49134952 }
4953+ # Include extra_content if present
4954+ if tool_call_data .get ('extra_content' ):
4955+ tool_call_dict ["extra_content" ] = tool_call_data [
4956+ "extra_content"
4957+ ]
49144958 tool_calls_list .append (tool_call_dict )
49154959
49164960 # Create an assistant message with tool calls
0 commit comments