@@ -3692,8 +3692,13 @@ def _handle_batch_response(
36923692 tool_name = tool_call .function .name # type: ignore[union-attr]
36933693 tool_call_id = tool_call .id
36943694 args = json .loads (tool_call .function .arguments ) # type: ignore[union-attr]
3695+ extra_content = getattr (tool_call , 'extra_content' , None )
3696+
36953697 tool_call_request = ToolCallRequest (
3696- tool_name = tool_name , args = args , tool_call_id = tool_call_id
3698+ tool_name = tool_name ,
3699+ args = args ,
3700+ tool_call_id = tool_call_id ,
3701+ extra_content = extra_content ,
36973702 )
36983703 tool_call_requests .append (tool_call_request )
36993704
@@ -3786,7 +3791,12 @@ def _execute_tool(
37863791 logger .warning (f"{ error_msg } with result: { result } " )
37873792
37883793 return self ._record_tool_calling (
3789- func_name , args , result , tool_call_id , mask_output = mask_flag
3794+ func_name ,
3795+ args ,
3796+ result ,
3797+ tool_call_id ,
3798+ mask_output = mask_flag ,
3799+ extra_content = tool_call_request .extra_content ,
37903800 )
37913801
37923802 async def _aexecute_tool (
@@ -3828,7 +3838,13 @@ async def _aexecute_tool(
38283838 error_msg = f"Error executing async tool '{ func_name } ': { e !s} "
38293839 result = f"Tool execution failed: { error_msg } "
38303840 logger .warning (error_msg )
3831- return self ._record_tool_calling (func_name , args , result , tool_call_id )
3841+ return self ._record_tool_calling (
3842+ func_name ,
3843+ args ,
3844+ result ,
3845+ tool_call_id ,
3846+ extra_content = tool_call_request .extra_content ,
3847+ )
38323848
38333849 def _record_tool_calling (
38343850 self ,
@@ -3837,6 +3853,7 @@ def _record_tool_calling(
38373853 result : Any ,
38383854 tool_call_id : str ,
38393855 mask_output : bool = False ,
3856+ extra_content : Optional [Dict [str , Any ]] = None ,
38403857 ):
38413858 r"""Record the tool calling information in the memory, and return the
38423859 tool calling record.
@@ -3849,6 +3866,9 @@ def _record_tool_calling(
38493866 mask_output (bool, optional): Whether to return a sanitized
38503867 placeholder instead of the raw tool output.
38513868 (default: :obj:`False`)
3869+ extra_content (Optional[Dict[str, Any]], optional): Additional
3870+ content associated with the tool call.
3871+ (default: :obj:`None`)
38523872
38533873 Returns:
38543874 ToolCallingRecord: A struct containing information about
@@ -3862,6 +3882,7 @@ def _record_tool_calling(
38623882 func_name = func_name ,
38633883 args = args ,
38643884 tool_call_id = tool_call_id ,
3885+ extra_content = extra_content ,
38653886 )
38663887 func_msg = FunctionCallingMessage (
38673888 role_name = self .role_name ,
@@ -3872,6 +3893,7 @@ def _record_tool_calling(
38723893 result = result ,
38733894 tool_call_id = tool_call_id ,
38743895 mask_output = mask_output ,
3896+ extra_content = extra_content ,
38753897 )
38763898
38773899 # Use precise timestamps to ensure correct ordering
@@ -4006,7 +4028,7 @@ def _stream_response(
40064028 return
40074029
40084030 # Handle streaming response
4009- if isinstance (response , Stream ):
4031+ if isinstance (response , Stream ) or inspect . isgenerator ( response ) :
40104032 (
40114033 stream_completed ,
40124034 tool_calls_complete ,
@@ -4346,6 +4368,7 @@ def _accumulate_tool_calls(
43464368 'id' : '' ,
43474369 'type' : 'function' ,
43484370 'function' : {'name' : '' , 'arguments' : '' },
4371+ 'extra_content' : None ,
43494372 'complete' : False ,
43504373 }
43514374
@@ -4369,6 +4392,14 @@ def _accumulate_tool_calls(
43694392 tool_call_entry ['function' ]['arguments' ] += (
43704393 delta_tool_call .function .arguments
43714394 )
4395+ # Handle extra_content if present
4396+ if (
4397+ hasattr (delta_tool_call , 'extra_content' )
4398+ and delta_tool_call .extra_content
4399+ ):
4400+ tool_call_entry ['extra_content' ] = (
4401+ delta_tool_call .extra_content
4402+ )
43724403
43734404 # Check if any tool calls are complete
43744405 any_complete = False
@@ -4473,6 +4504,7 @@ def _execute_tool_from_stream_data(
44734504 function_name = tool_call_data ['function' ]['name' ]
44744505 args = json .loads (tool_call_data ['function' ]['arguments' ])
44754506 tool_call_id = tool_call_data ['id' ]
4507+ extra_content = tool_call_data .get ('extra_content' )
44764508
44774509 if function_name in self ._internal_tools :
44784510 tool = self ._internal_tools [function_name ]
@@ -4488,6 +4520,7 @@ def _execute_tool_from_stream_data(
44884520 func_name = function_name ,
44894521 args = args ,
44904522 tool_call_id = tool_call_id ,
4523+ extra_content = extra_content ,
44914524 )
44924525
44934526 # Then create the tool response message
@@ -4499,6 +4532,7 @@ def _execute_tool_from_stream_data(
44994532 func_name = function_name ,
45004533 result = result ,
45014534 tool_call_id = tool_call_id ,
4535+ extra_content = extra_content ,
45024536 )
45034537
45044538 # Record both messages with precise timestamps to ensure
@@ -4544,6 +4578,7 @@ def _execute_tool_from_stream_data(
45444578 func_name = function_name ,
45454579 result = result ,
45464580 tool_call_id = tool_call_id ,
4581+ extra_content = extra_content ,
45474582 )
45484583
45494584 self .update_memory (func_msg , OpenAIBackendRole .FUNCTION )
@@ -4575,6 +4610,7 @@ async def _aexecute_tool_from_stream_data(
45754610 function_name = tool_call_data ['function' ]['name' ]
45764611 args = json .loads (tool_call_data ['function' ]['arguments' ])
45774612 tool_call_id = tool_call_data ['id' ]
4613+ extra_content = tool_call_data .get ('extra_content' )
45784614
45794615 if function_name in self ._internal_tools :
45804616 # Create the tool call message
@@ -4586,6 +4622,7 @@ async def _aexecute_tool_from_stream_data(
45864622 func_name = function_name ,
45874623 args = args ,
45884624 tool_call_id = tool_call_id ,
4625+ extra_content = extra_content ,
45894626 )
45904627 assist_ts = time .time_ns () / 1_000_000_000
45914628 self .update_memory (
@@ -4632,6 +4669,7 @@ async def _aexecute_tool_from_stream_data(
46324669 func_name = function_name ,
46334670 result = result ,
46344671 tool_call_id = tool_call_id ,
4672+ extra_content = extra_content ,
46354673 )
46364674 func_ts = time .time_ns () / 1_000_000_000
46374675 self .update_memory (
@@ -4665,6 +4703,7 @@ async def _aexecute_tool_from_stream_data(
46654703 func_name = function_name ,
46664704 result = result ,
46674705 tool_call_id = tool_call_id ,
4706+ extra_content = extra_content ,
46684707 )
46694708 func_ts = time .time_ns () / 1_000_000_000
46704709 self .update_memory (
@@ -4979,6 +5018,11 @@ def _record_assistant_tool_calls_message(
49795018 "arguments" : tool_call_data ["function" ]["arguments" ],
49805019 },
49815020 }
5021+ # Include extra_content if present
5022+ if tool_call_data .get ('extra_content' ):
5023+ tool_call_dict ["extra_content" ] = tool_call_data [
5024+ "extra_content"
5025+ ]
49825026 tool_calls_list .append (tool_call_dict )
49835027
49845028 # Create an assistant message with tool calls
0 commit comments