Skip to content

Commit e5a59a7

Browse files
author
Alex Reibman
committed
ruff
1 parent 5cad655 commit e5a59a7

17 files changed

Lines changed: 216 additions & 229 deletions

File tree

agentops/client/api/base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
class TokenFetcher(Protocol):
1616
"""Protocol for token fetching functions"""
1717

18-
def __call__(self, api_key: str) -> str:
19-
...
18+
def __call__(self, api_key: str) -> str: ...
2019

2120

2221
class BaseApiClient:

agentops/client/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ class Client:
4040
config: Config
4141
_initialized: bool
4242
_init_trace_context: Optional[TraceContext] = None # Stores the context of the auto-started trace
43-
_legacy_session_for_init_trace: Optional[
44-
Session
45-
] = None # Stores the legacy Session wrapper for the auto-started trace
43+
_legacy_session_for_init_trace: Optional[Session] = (
44+
None # Stores the legacy Session wrapper for the auto-started trace
45+
)
4646

4747
__instance = None # Class variable for singleton pattern
4848

agentops/instrumentation/agentic/google_adk/patch.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,16 +304,16 @@ def _extract_llm_attributes(llm_request_dict: dict, llm_response: Any) -> dict:
304304
elif "function_call" in part:
305305
# This is a function call in the response
306306
func_call = part["function_call"]
307-
attributes[
308-
MessageAttributes.COMPLETION_TOOL_CALL_NAME.format(i=0, j=tool_call_index)
309-
] = func_call.get("name", "")
310-
attributes[
311-
MessageAttributes.COMPLETION_TOOL_CALL_ARGUMENTS.format(i=0, j=tool_call_index)
312-
] = json.dumps(func_call.get("args", {}))
307+
attributes[MessageAttributes.COMPLETION_TOOL_CALL_NAME.format(i=0, j=tool_call_index)] = (
308+
func_call.get("name", "")
309+
)
310+
attributes[MessageAttributes.COMPLETION_TOOL_CALL_ARGUMENTS.format(i=0, j=tool_call_index)] = (
311+
json.dumps(func_call.get("args", {}))
312+
)
313313
if "id" in func_call:
314-
attributes[
315-
MessageAttributes.COMPLETION_TOOL_CALL_ID.format(i=0, j=tool_call_index)
316-
] = func_call["id"]
314+
attributes[MessageAttributes.COMPLETION_TOOL_CALL_ID.format(i=0, j=tool_call_index)] = (
315+
func_call["id"]
316+
)
317317
tool_call_index += 1
318318

319319
if text_parts:

agentops/instrumentation/agentic/openai_agents/attributes/completion.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ def get_raw_response_attributes(response: Dict[str, Any]) -> Dict[str, Any]:
115115
result[MessageAttributes.COMPLETION_TOOL_CALL_NAME.format(i=j, j=k)] = function.get(
116116
"name", ""
117117
)
118-
result[
119-
MessageAttributes.COMPLETION_TOOL_CALL_ARGUMENTS.format(i=j, j=k)
120-
] = function.get("arguments", "")
118+
result[MessageAttributes.COMPLETION_TOOL_CALL_ARGUMENTS.format(i=j, j=k)] = (
119+
function.get("arguments", "")
120+
)
121121

122122
return result
123123

agentops/instrumentation/agentic/smolagents/attributes/model.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ def get_model_attributes(
102102
if hasattr(return_value, "tool_calls") and return_value.tool_calls:
103103
for j, tool_call in enumerate(return_value.tool_calls):
104104
if hasattr(tool_call, "function"):
105-
attributes[
106-
MessageAttributes.COMPLETION_TOOL_CALL_NAME.format(i=0, j=j)
107-
] = tool_call.function.name
105+
attributes[MessageAttributes.COMPLETION_TOOL_CALL_NAME.format(i=0, j=j)] = (
106+
tool_call.function.name
107+
)
108108
if hasattr(tool_call.function, "arguments"):
109-
attributes[
110-
MessageAttributes.COMPLETION_TOOL_CALL_ARGUMENTS.format(i=0, j=j)
111-
] = tool_call.function.arguments
109+
attributes[MessageAttributes.COMPLETION_TOOL_CALL_ARGUMENTS.format(i=0, j=j)] = (
110+
tool_call.function.arguments
111+
)
112112
if hasattr(tool_call, "id"):
113113
attributes[MessageAttributes.COMPLETION_TOOL_CALL_ID.format(i=0, j=j)] = tool_call.id
114114

agentops/instrumentation/common/attributes.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ class IndexedAttribute(Protocol):
9898
formatting of attribute keys based on the indices.
9999
"""
100100

101-
def format(self, *, i: int, j: Optional[int] = None) -> str:
102-
...
101+
def format(self, *, i: int, j: Optional[int] = None) -> str: ...
103102

104103

105104
IndexedAttributeMap = Dict[IndexedAttribute, str] # target_attribute_key: source_attribute

agentops/instrumentation/providers/openai/instrumentor.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
handle_run_retrieve_attributes,
3838
handle_run_stream_attributes,
3939
handle_messages_attributes,
40-
handle_responses_attributes,
4140
)
4241
from agentops.instrumentation.providers.openai.stream_wrapper import (
4342
chat_completion_stream_wrapper,

agentops/instrumentation/providers/openai/stream_wrapper.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ def _process_event(self, event: Any) -> None:
700700
response = event.response
701701
if hasattr(response, "usage"):
702702
self._usage = response.usage
703-
703+
704704
# Extract output items from the completed response
705705
if hasattr(response, "output"):
706706
for output_item in response.output:
@@ -723,13 +723,21 @@ def _process_event(self, event: Any) -> None:
723723
# Extract text content from message items
724724
if isinstance(output_item.content, list):
725725
for content in output_item.content:
726-
if hasattr(content, "type") and content.type == "text" and hasattr(content, "text"):
726+
if (
727+
hasattr(content, "type")
728+
and content.type == "text"
729+
and hasattr(content, "text")
730+
):
727731
self._content_chunks.append(str(content.text))
728732
else:
729733
self._content_chunks.append(str(output_item.content))
730734

731735
# Only add significant events, not every delta
732-
if hasattr(event, "type") and event.type in ["response.created", "response.completed", "response.output_item.added"]:
736+
if hasattr(event, "type") and event.type in [
737+
"response.created",
738+
"response.completed",
739+
"response.output_item.added",
740+
]:
733741
self._span.add_event(
734742
"responses_api_event",
735743
{"event_type": event.type, "event_number": self._event_count},
@@ -743,7 +751,7 @@ def _finalize_stream(self) -> None:
743751
text_content = "".join(self._content_chunks)
744752
function_content = self._current_function_args or "".join(self._function_call_chunks)
745753
reasoning_content = "".join(self._reasoning_chunks)
746-
754+
747755
# Combine all content types for the completion
748756
full_content = ""
749757
if reasoning_content:
@@ -758,10 +766,14 @@ def _finalize_stream(self) -> None:
758766
full_content += f"\nResponse: {text_content}"
759767
else:
760768
full_content = text_content
761-
769+
762770
if full_content:
763771
self._span.set_attribute(MessageAttributes.COMPLETION_CONTENT.format(i=0), full_content)
764-
logger.debug(f"[RESPONSES API] Setting completion content: {full_content[:100]}..." if len(full_content) > 100 else f"[RESPONSES API] Setting completion content: {full_content}")
772+
logger.debug(
773+
f"[RESPONSES API] Setting completion content: {full_content[:100]}..."
774+
if len(full_content) > 100
775+
else f"[RESPONSES API] Setting completion content: {full_content}"
776+
)
765777

766778
# Set timing
767779
if self._first_token_time:
@@ -809,7 +821,9 @@ def _finalize_stream(self) -> None:
809821
self._span.set_status(Status(StatusCode.OK))
810822
self._span.end()
811823
context_api.detach(self._token)
812-
logger.debug(f"[RESPONSES API] Finalized streaming span after {self._event_count} events. Content length: {len(full_content)}")
824+
logger.debug(
825+
f"[RESPONSES API] Finalized streaming span after {self._event_count} events. Content length: {len(full_content)}"
826+
)
813827

814828

815829
@_with_tracer_wrapper
@@ -836,7 +850,7 @@ def responses_stream_wrapper(tracer, wrapped, instance, args, kwargs):
836850
try:
837851
# Extract and set request attributes
838852
from agentops.instrumentation.providers.openai.wrappers.responses import handle_responses_attributes
839-
853+
840854
request_attributes = handle_responses_attributes(kwargs=kwargs)
841855
for key, value in request_attributes.items():
842856
span.set_attribute(key, value)
@@ -854,7 +868,7 @@ def responses_stream_wrapper(tracer, wrapped, instance, args, kwargs):
854868
for key, value in response_attributes.items():
855869
if key not in request_attributes: # Avoid overwriting request attributes
856870
span.set_attribute(key, value)
857-
871+
858872
span.set_status(Status(StatusCode.OK))
859873
span.end()
860874
context_api.detach(token)
@@ -893,7 +907,7 @@ async def async_responses_stream_wrapper(tracer, wrapped, instance, args, kwargs
893907
try:
894908
# Extract and set request attributes
895909
from agentops.instrumentation.providers.openai.wrappers.responses import handle_responses_attributes
896-
910+
897911
request_attributes = handle_responses_attributes(kwargs=kwargs)
898912
for key, value in request_attributes.items():
899913
span.set_attribute(key, value)
@@ -912,7 +926,7 @@ async def async_responses_stream_wrapper(tracer, wrapped, instance, args, kwargs
912926
for key, value in response_attributes.items():
913927
if key not in request_attributes: # Avoid overwriting request attributes
914928
span.set_attribute(key, value)
915-
929+
916930
span.set_status(Status(StatusCode.OK))
917931
span.end()
918932
context_api.detach(token)

agentops/instrumentation/providers/openai/wrappers/responses.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
model_as_dict,
1313
should_send_prompts,
1414
)
15-
from agentops.instrumentation.providers.openai.attributes.response import get_response_usage_attributes
1615
from agentops.instrumentation.common.attributes import AttributeMap
1716
from agentops.semconv import SpanAttributes, LLMRequestTypeValues
1817

@@ -135,7 +134,7 @@ def handle_responses_attributes(
135134
continue
136135
else:
137136
continue
138-
137+
139138
if item_type == "message":
140139
# Extract message content
141140
if isinstance(output_item, dict):
@@ -158,7 +157,7 @@ def handle_responses_attributes(
158157
attributes[f"{SpanAttributes.LLM_COMPLETIONS}.{completion_idx}.content"] = content
159158
attributes[f"{SpanAttributes.LLM_COMPLETIONS}.{completion_idx}.role"] = "assistant"
160159
completion_idx += 1
161-
160+
162161
elif item_type == "function_call" and isinstance(output_item, dict):
163162
# Handle function calls
164163
# The arguments contain the actual response content for function calls
@@ -174,12 +173,12 @@ def handle_responses_attributes(
174173
completion_idx += 1
175174
except json.JSONDecodeError:
176175
pass
177-
176+
178177
# Also store tool call details
179178
attributes[f"{SpanAttributes.LLM_COMPLETIONS}.{i}.tool_calls.0.id"] = output_item.get("id", "")
180179
attributes[f"{SpanAttributes.LLM_COMPLETIONS}.{i}.tool_calls.0.name"] = output_item.get("name", "")
181180
attributes[f"{SpanAttributes.LLM_COMPLETIONS}.{i}.tool_calls.0.arguments"] = args_str
182-
181+
183182
elif item_type == "reasoning" and isinstance(output_item, dict):
184183
# Handle reasoning items (o3 models provide these)
185184
summary = output_item.get("summary", "")
@@ -189,4 +188,4 @@ def handle_responses_attributes(
189188
attributes[f"{SpanAttributes.LLM_COMPLETIONS}.{completion_idx}.type"] = "reasoning"
190189
completion_idx += 1
191190

192-
return attributes
191+
return attributes

examples/agno/agno_async_operations.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
"\n",
4747
"import agentops\n",
4848
"from agno.agent import Agent\n",
49-
"from agno.team import Team\n",
5049
"from agno.models.openai import OpenAIChat"
5150
]
5251
},

0 commit comments

Comments
 (0)