Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI
Python agentagentopsagents-sdkaianthropicautogencost-estimationcrewaievalsevaluation-metricsgroqlangchainllmmistralollamaopenaiopenai-agents
replaced tags with List[str] (#13)
Alex Reibman1336dafb576e
diff --git a/agentops/agentops.py b/agentops/agentops.pyindex f7410c07..0f3bef70 100644--- a/agentops/agentops.py+++ b/agentops/agentops.py@@ -9,7 +9,7 @@ from .config import Configurationfrom .event import Session, Event, EventStatefrom .worker import Workerfrom uuid import uuid4-from typing import Optional, Dict+from typing import Optional, Listimport functoolsimport inspectimport atexit@@ -21,7 +21,7 @@ class AgentOps:Args:api_key (str): API Key for AgentOps services.- tags (Dict[str, str], optional): Tags for the sessions that can be used for grouping or sorting later (e.g. {"llm": "GPT-4"}).+ tags (List[str], optional): Tags for the sessions that can be used for grouping or sorting later (e.g. ["GPT-4"]).config (Configuration, optional): A Configuration object for AgentOps services. If not provided, a default Configuration object will be used.Attributes:@@ -29,7 +29,7 @@ class AgentOps:config (Configuration): A Configuration object for AgentOps services."""- def __init__(self, api_key: str, tags: Optional[Dict[str, str]] = None, config: Configuration = Configuration()):+ def __init__(self, api_key: str, tags: Optional[List[str]] = None, config: Configuration = Configuration()):self.config: Configuration = configself.config.api_key = api_keyself.start_session(tags)@@ -53,12 +53,12 @@ class AgentOps:print("This event was not recorded because the previous session has been ended. Start a new session to record again")print(event.__dict__)- def record_action(self, event_name: str, tags: Optional[Dict[str, str]] = None):+ def record_action(self, event_name: str, tags: Optional[List[str]] = None):"""Decorator to record an event before and after a function call.Args:event_name (str): The name of the event to record.- tags (dict, optional): Any tags associated with the event. Defaults to None.+ tags (List[str], optional): Any tags associated with the event. Defaults to None."""def decorator(func):@functools.wraps(func)@@ -94,12 +94,12 @@ class AgentOps:return decorator- def start_session(self, tags: Optional[Dict[str, str]] = None):+ def start_session(self, tags: Optional[List[str]] = None):"""Start a new session for recording events.Args:- tags (Dict[str, str], optional): Tags that can be used for grouping or sorting later. Examples could be {"llm": "GPT-4"}.+ tags (List[str], optional): Tags that can be used for grouping or sorting later. Examples could be ["GPT-4"]."""self.session = Session(str(uuid4()), tags)self.worker = Worker(self.config)diff --git a/agentops/event.py b/agentops/event.pyindex bc4cd623..612ae92c 100644--- a/agentops/event.py+++ b/agentops/event.py@@ -6,7 +6,7 @@ Classes:Session: Represents a session of events, with a start and end state."""from .helpers import get_ISO_time-from typing import Optional, Dict+from typing import Optional, Listclass EventState:@@ -30,7 +30,7 @@ class Event:params (str, optional): The parameters passed to the operation.returns (str, optional): The output of the operation.result (str, optional): Result of the operation, e.g., "Success", "Fail", "Indeterminate".- tags (Dict[str, str], optional): Tags that can be used for grouping or sorting later. e.g. {"llm": "GPT-4"}.+ tags (List[str], optional): Tags that can be used for grouping or sorting later. e.g. ["GPT-4"].Attributes:@@ -41,7 +41,7 @@ class Event:params: Optional[str] = None,returns: Optional[str] = None,result: EventState = EventState.INDETERMINATE,- tags: Optional[Dict[str, str]] = None+ tags: Optional[List[str]] = None):self.event_type = event_typeself.params = params@@ -57,7 +57,7 @@ class Session:Args:session_id (str): The session id is used to record particular runs.- tags (Dict[str, str], optional): Tags that can be used for grouping or sorting later. Examples could be {"llm": "GPT-4"}.+ tags (List[str], optional): Tags that can be used for grouping or sorting later. Examples could be ["GPT-4"].Attributes:init_timestamp (float): The timestamp for when the session started, represented as seconds since the epoch.@@ -67,7 +67,7 @@ class Session:"""- def __init__(self, session_id: str, tags: Optional[Dict[str, str]] = None):+ def __init__(self, session_id: str, tags: Optional[List[str]] = None):self.session_id = session_idself.init_timestamp = get_ISO_time()self.tags = tagsdiff --git a/tests/test_session.py b/tests/test_session.pyindex b1a86e29..d0b79714 100644--- a/tests/test_session.py+++ b/tests/test_session.py@@ -56,7 +56,7 @@ class TestSessions:def test_tags(self, mock_req):# Arrange- tags = {'llm': 'GPT-4'}+ tags = ['GPT-4']config = Configuration(max_wait_time=5)client = AgentOps(api_key=self.api_key, config=config, tags=tags)@@ -96,7 +96,7 @@ class TestRecordAction:self.client.end_session(end_state=EventState.SUCCESS)def test_record_action_decorator(self, mock_req):- @self.client.record_action(event_name=self.event_type, tags={'foo': 'bar'})+ @self.client.record_action(event_name=self.event_type, tags=['foo', 'bar'])def dummy_func(x, y):return x + y@@ -112,11 +112,11 @@ class TestRecordAction:'args': [3, 4], 'kwargs': {}}assert request_json['event']['returns'] == 7assert request_json['event']['result'] == EventState.SUCCESS- assert request_json['event']['tags'] == {'foo': 'bar'}+ assert request_json['event']['tags'] == ['foo', 'bar']def test_record_action_decorator(self, mock_req):# Arrange- @self.client.record_action(event_name=self.event_type, tags={'foo': 'bar'})+ @self.client.record_action(event_name=self.event_type, tags=['foo', 'bar'])def dummy_func(x, y):return x + y@@ -132,4 +132,4 @@ class TestRecordAction:assert request_json['events'][0]['params'] == {'x': 3, 'y': 4}assert request_json['events'][0]['returns'] == 7assert request_json['events'][0]['result'] == EventState.SUCCESS- assert request_json['events'][0]['tags'] == {'foo': 'bar'}+ assert request_json['events'][0]['tags'] == ['foo', 'bar']