Skip to content

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

Refactored to support new db schema

Howard Gil3ecc30aa531e
diff --git a/agentops/client.py b/agentops/client.py
index 98b90657..4e982f93 100644
--- a/agentops/client.py
+++ b/agentops/client.py
@@ -31,7 +31,6 @@ 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.
@@ -42,7 +41,6 @@ class Client:
"""
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,
@@ -56,11 +54,8 @@ 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, org_key, endpoint,
+ self.config = Configuration(api_key, endpoint,
max_wait_time, max_queue_size)
# Store a reference to the instance
diff --git a/agentops/config.py b/agentops/config.py
index 8ac1b3f8..d3a1af85 100644
--- a/agentops/config.py
+++ b/agentops/config.py
@@ -14,17 +14,15 @@ 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, org_key: Optional[str] = None,
+ def __init__(self, api_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_key
self._endpoint = endpoint
self._max_wait_time = max_wait_time
self._max_queue_size = max_queue_size
@@ -48,27 +46,7 @@ class Configuration:
value (str): The new API Key.
"""
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
-
+
@property
def endpoint(self) -> str:
"""
diff --git a/agentops/event.py b/agentops/event.py
index bd7f8cbb..20150c3c 100644
--- a/agentops/event.py
+++ b/agentops/event.py
@@ -22,7 +22,7 @@ class Event:
pattern="^(Success|Fail|Indeterminate)$"),
action_type: Optional[str] = Field("action",
description="Type of action that the user is recording",
- pattern="^(action|api|llm|screenshot)$"),
+ pattern="^(action|api|llm|screenshot|tool|error)$"),
model: Optional[Models] = None,
prompt: Optional[str] = None,
tags: Optional[List[str]] = None,
@@ -55,6 +55,7 @@ class Event:
"model": self.model,
"prompt": self.prompt,
"tags": self.tags,
+ "screenshot": self.screenshot,
"init_timestamp": self.init_timestamp,
"prompt_tokens": self.prompt_tokens,
"completion_tokens": self.completion_tokens,
diff --git a/agentops/http.py b/agentops/http.py
index 022c6f3a..a83b3c73 100644
--- a/agentops/http.py
+++ b/agentops/http.py
@@ -57,7 +57,7 @@ class Response:
class HttpClient:
@staticmethod
- def post(url: str, payload: bytes, api_key: Optional[str] = None, org_key: Optional[str] = None, header=None) -> Response:
+ def post(url: str, payload: bytes, api_key: Optional[str] = None, header=None) -> Response:
result = Response()
try:
# Create request session with retries configured
@@ -67,9 +67,6 @@ 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/langchain_callback_handler.py b/agentops/langchain_callback_handler.py
index b1c53f47..1baf16c9 100644
--- a/agentops/langchain_callback_handler.py
+++ b/agentops/langchain_callback_handler.py
@@ -22,7 +22,6 @@ class LangchainCallbackHandler(BaseCallbackHandler):
"""Callback handler for Langchain agents."""
def __init__(self, api_key: str,
- org_key: Optional[str] = None,
endpoint: Optional[str] = None,
max_wait_time: Optional[int] = None,
max_queue_size: Optional[int] = None,
@@ -30,7 +29,6 @@ class LangchainCallbackHandler(BaseCallbackHandler):
client_params = {
'api_key': api_key,
- 'org_key': org_key,
'endpoint': endpoint,
'max_wait_time': max_wait_time,
'max_queue_size': max_queue_size,
@@ -312,7 +310,6 @@ class AsyncLangchainCallbackHandler(AsyncCallbackHandler):
"""Callback handler for Langchain agents."""
def __init__(self, api_key: str,
- org_key: Optional[str] = None,
endpoint: Optional[str] = None,
max_wait_time: Optional[int] = None,
max_queue_size: Optional[int] = None,
@@ -320,7 +317,6 @@ class AsyncLangchainCallbackHandler(AsyncCallbackHandler):
client_params = {
'api_key': api_key,
- 'org_key': org_key,
'endpoint': endpoint,
'max_wait_time': max_wait_time,
'max_queue_size': max_queue_size,
diff --git a/agentops/worker.py b/agentops/worker.py
index 430807af..4876f2b5 100644
--- a/agentops/worker.py
+++ b/agentops/worker.py
@@ -68,8 +68,7 @@ class Worker:
safe_serialize(payload).encode("utf-8")
HttpClient.post(f'{self.config.endpoint}/events',
serialized_payload,
- self.config.api_key,
- self.config.org_key)
+ self.config.api_key)
def start_session(self, session: Session) -> None:
with self.lock:
@@ -80,8 +79,7 @@ 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.org_key)
+ self.config.api_key)
def end_session(self, session: Session) -> None:
self.stop_flag.set()
@@ -96,8 +94,7 @@ class Worker:
HttpClient.post(f'{self.config.endpoint}/sessions',
json.dumps(filter_unjsonable(
payload)).encode("utf-8"),
- self.config.api_key,
- self.config.org_key)
+ self.config.api_key)
def run(self) -> None:
while not self.stop_flag.is_set():