2020from agentops .semconv .tool import ToolAttributes
2121from agentops .semconv .span_kinds import AgentOpsSpanKindValues
2222
23- from opentelemetry .trace import SpanKind , Status , StatusCode , get_tracer , set_span_in_context , get_current
23+ from opentelemetry .trace import SpanKind , get_tracer , set_span_in_context , get_current
2424
2525logger = logging .getLogger (__name__ )
2626
3030def _create_tool_span (parent_span : Span , tool_call_data : Dict [str , Any ]):
3131 """
3232 Create a distinct span for each tool call.
33-
33+
3434 Args:
3535 parent_span: The parent LLM span
3636 tool_call_data: The tool call data dictionary
3737 """
3838 # Get the tracer for this module
3939 tracer = get_tracer (__name__ )
40-
40+
4141 # Create a child span for the tool call
4242 with tracer .start_as_current_span (
4343 name = f"tool_call.{ tool_call_data ['function' ]['name' ]} " ,
4444 kind = SpanKind .INTERNAL ,
45- context = set_span_in_context (parent_span , get_current ())
45+ context = set_span_in_context (parent_span , get_current ()),
4646 ) as tool_span :
4747 # Set the span kind to TOOL
4848 tool_span .set_attribute ("agentops.span.kind" , AgentOpsSpanKindValues .TOOL )
49-
49+
5050 # Set tool-specific attributes
51- tool_span .set_attribute (ToolAttributes .TOOL_NAME , tool_call_data [' function' ][ ' name' ])
52- tool_span .set_attribute (ToolAttributes .TOOL_PARAMETERS , tool_call_data [' function' ][ ' arguments' ])
53- tool_span .set_attribute ("tool.call.id" , tool_call_data ['id' ])
54- tool_span .set_attribute ("tool.call.type" , tool_call_data [' type' ])
51+ tool_span .set_attribute (ToolAttributes .TOOL_NAME , tool_call_data [" function" ][ " name" ])
52+ tool_span .set_attribute (ToolAttributes .TOOL_PARAMETERS , tool_call_data [" function" ][ " arguments" ])
53+ tool_span .set_attribute ("tool.call.id" , tool_call_data ["id" ])
54+ tool_span .set_attribute ("tool.call.type" , tool_call_data [" type" ])
5555
5656
5757def handle_chat_attributes (
@@ -64,7 +64,7 @@ def handle_chat_attributes(
6464
6565 This function is designed to work with the common wrapper pattern,
6666 extracting attributes from the method arguments and return value.
67-
67+
6868 Args:
6969 args: Method arguments (not used in this implementation)
7070 kwargs: Method keyword arguments
@@ -240,8 +240,8 @@ def handle_chat_attributes(
240240 "type" : tool_call .get ("type" , "function" ),
241241 "function" : {
242242 "name" : function .get ("name" , "" ),
243- "arguments" : function .get ("arguments" , "" )
244- }
243+ "arguments" : function .get ("arguments" , "" ),
244+ },
245245 }
246246 # Create a child span for this tool call
247247 _create_tool_span (span , tool_call_data )
0 commit comments