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
Add support for org keys (#53)
Shawn Qiuf7b91519a194
diff --git a/agentops/client.py b/agentops/client.pyindex a843a9ae..4acb2055 100644--- a/agentops/client.py+++ b/agentops/client.py@@ -30,6 +30,7 @@ class Client:Args:api_key (str, optional): API Key for AgentOps services. If none is provided, key will be read from the AGENTOPS_API_KEY environment variable.+ org_key (str, optional): Allows sessions/events analytics to be tracked by the owners of the organization key.tags (List[str], optional): Tags for the sessions that can be used for grouping or sorting later (e.g. ["GPT-4"]).endpoint (str, optional): The endpoint for the AgentOps service. Defaults to 'https://agentops-server-v2.fly.dev'.max_wait_time (int, optional): The maximum time to wait in milliseconds before flushing the queue. Defaults to 1000.@@ -38,7 +39,9 @@ class Client:session (Session, optional): A Session is a grouping of events (e.g. a run of your agent)."""- def __init__(self, api_key: Optional[str] = None, tags: Optional[List[str]] = None,+ def __init__(self, api_key: Optional[str] = None,+ org_key: Optional[str] = None,+ tags: Optional[List[str]] = None,endpoint: Optional[str] = 'https://agentops-server-v2.fly.dev',max_wait_time: Optional[int] = 1000,max_queue_size: Optional[int] = 100):@@ -50,8 +53,11 @@ class Client:if api_key is None:print("AgentOps API key not provided. Session data will not be recorded.")+ if org_key is None:+ org_key = environ.get('AGENTOPS_ORG_KEY')+# Create a worker config- self.config = Configuration(api_key, endpoint,+ self.config = Configuration(api_key, org_key, endpoint,max_wait_time, max_queue_size)# Store a reference to the instancediff --git a/agentops/config.py b/agentops/config.pyindex 16f2f266..8ac1b3f8 100644--- a/agentops/config.py+++ b/agentops/config.py@@ -14,14 +14,17 @@ class Configuration:Args:api_key (str, optional): API Key for AgentOps services+ org_key (str, optional): Allows sessions/events analytics to be tracked by the owners of the organization key.endpoint (str, optional): The endpoint for the AgentOps service. Defaults to 'https://agentops-server-v2.fly.dev'.max_wait_time (int, optional): The maximum time to wait in milliseconds before flushing the queue. Defaults to 1000.max_queue_size (int, optional): The maximum size of the event queue. Defaults to 100."""- def __init__(self, api_key: Optional[str] = None, endpoint: Optional[str] = 'https://agentops-server-v2.fly.dev',+ def __init__(self, api_key: Optional[str] = None, org_key: Optional[str] = None,+ endpoint: Optional[str] = 'https://agentops-server-v2.fly.dev',max_wait_time: Optional[int] = 1000, max_queue_size: Optional[int] = 100):self._api_key: str | None = api_key+ self._org_key: str | None = org_keyself._endpoint = endpointself._max_wait_time = max_wait_timeself._max_queue_size = max_queue_size@@ -46,6 +49,26 @@ class Configuration:"""self._api_key = value+ @property+ def org_key(self) -> str:+ """+ Get the API Key for AgentOps services.++ Returns:+ str: The API Key for AgentOps services.+ """+ return self._org_key++ @org_key.setter+ def org_key(self, value: str):+ """+ Set the API Key for AgentOps services.++ Args:+ value (str): The new API Key.+ """+ self._org_key = value+@propertydef endpoint(self) -> str:"""diff --git a/agentops/http.py b/agentops/http.pyindex c8abda75..685355b6 100644--- a/agentops/http.py+++ b/agentops/http.py@@ -58,7 +58,7 @@ class Response:class HttpClient:@staticmethod- def post(url: str, payload: bytes, api_key: str = None, header=None) -> Response:+ def post(url: str, payload: bytes, api_key: str = None, org_key: Optional[str] = None, header=None) -> Response:result = Response()try:# Create request session with retries configured@@ -68,6 +68,9 @@ class HttpClient:if api_key != None:JSON_HEADER["X-Agentops-Auth"] = api_key+ if org_key != None:+ JSON_HEADER["X-Agentops-Org"] = org_key+res = request_session.post(url, data=payload,headers=JSON_HEADER, timeout=20)diff --git a/agentops/worker.py b/agentops/worker.pyindex f41d01d2..618bf5b5 100644--- a/agentops/worker.py+++ b/agentops/worker.py@@ -62,7 +62,8 @@ class Worker:safe_serialize(payload).encode("utf-8")HttpClient.post(f'{self.config.endpoint}/events',serialized_payload,- self.config.api_key)+ self.config.api_key,+ self.config.org_key)def start_session(self, session: Session) -> None:with self.lock:@@ -73,7 +74,8 @@ class Worker:json.dumps(filter_unjsonable(payload)).encode("utf-8")HttpClient.post(f'{self.config.endpoint}/sessions',serialized_payload,- self.config.api_key)+ self.config.api_key,+ self.config.org_key)def end_session(self, session: Session) -> None:self.stop_flag.set()@@ -88,7 +90,8 @@ class Worker:HttpClient.post(f'{self.config.endpoint}/sessions',json.dumps(filter_unjsonable(payload)).encode("utf-8"),- self.config.api_key)+ self.config.api_key,+ self.config.org_key)def run(self) -> None:while not self.stop_flag.is_set():