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

use init with singleton

Braelyn Boyntona3054cbbf0c5
diff --git a/agentops/__init__.py b/agentops/__init__.py
index 40ffa69d..6f60a1b3 100755
--- a/agentops/__init__.py
+++ b/agentops/__init__.py
@@ -5,3 +5,19 @@ from .event import ActionEvent, LLMEvent, ToolEvent, ErrorEvent
from .logger import AgentOpsLogger
from .enums import Models, LLMMessageFormat
from .decorators import record_function
+
+
+def init(*args, **kwargs):
+ Client(*args, **kwargs)
+
+
+def end_session(*args, **kwargs):
+ Client().end_session(*args, **kwargs)
+
+
+def start_session(*args, **kwargs):
+ Client().start_session(*args, **kwargs)
+
+
+def record(*args, **kwargs):
+ Client().record(*args, **kwargs)
\ No newline at end of file
diff --git a/examples/multi_agent_example.ipynb b/examples/multi_agent_example.ipynb
index e1ed0ec0..920bc15c 100644
--- a/examples/multi_agent_example.ipynb
+++ b/examples/multi_agent_example.ipynb
@@ -49,7 +49,7 @@
"cell_type": "code",
"outputs": [],
"source": [
- "ao_client = agentops.Client(AGENTOPS_API_KEY)\n",
+ "agentops.init(AGENTOPS_API_KEY)\n",
"openai_client = openai.Client()"
],
"metadata": {
diff --git a/examples/openai-gpt.ipynb b/examples/openai-gpt.ipynb
index 7e59b64f..5ee44ad4 100644
--- a/examples/openai-gpt.ipynb
+++ b/examples/openai-gpt.ipynb
@@ -13,13 +13,9 @@
},
{
"cell_type": "code",
- "execution_count": 1,
+ "execution_count": null,
"id": "c51dcbda80eb8c53",
"metadata": {
- "ExecuteTime": {
- "end_time": "2023-12-15T21:33:47.472626Z",
- "start_time": "2023-12-15T21:33:47.448868Z"
- },
"collapsed": false
},
"outputs": [],
@@ -42,13 +38,9 @@
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": null,
"id": "cbc5d13679e269dc",
"metadata": {
- "ExecuteTime": {
- "end_time": "2023-12-15T21:33:47.473321Z",
- "start_time": "2023-12-15T21:33:47.460144Z"
- },
"collapsed": false
},
"outputs": [],
@@ -70,19 +62,15 @@
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": null,
"id": "fe8116d5969f1d23",
"metadata": {
- "ExecuteTime": {
- "end_time": "2023-12-15T21:33:48.179508Z",
- "start_time": "2023-12-15T21:33:47.463468Z"
- },
"collapsed": false
},
"outputs": [],
"source": [
"openai = OpenAI(api_key=OPENAI_API_KEY)\n",
- "ao_client = agentops.Client(AGENTOPS_API_KEY)\n"
+ "agentops.init(AGENTOPS_API_KEY)\n"
]
},
{
@@ -110,10 +98,6 @@
"execution_count": null,
"id": "9cd47d3fa1e252e1",
"metadata": {
- "ExecuteTime": {
- "end_time": "2023-12-15T21:33:49.022014Z",
- "start_time": "2023-12-15T21:33:48.181090Z"
- },
"collapsed": false
},
"outputs": [],
@@ -138,15 +122,11 @@
"execution_count": null,
"id": "f59fe80a7e00e6e8",
"metadata": {
- "ExecuteTime": {
- "end_time": "2023-12-15T21:33:50.619934Z",
- "start_time": "2023-12-15T21:33:49.021089Z"
- },
"collapsed": false
},
"outputs": [],
"source": [
- "ao_client.end_session('Success')"
+ "agentops.end_session('Success')"
]
},
{
@@ -176,16 +156,12 @@
"execution_count": null,
"id": "f5a1a63ff4ecf127",
"metadata": {
- "ExecuteTime": {
- "end_time": "2023-12-15T21:33:50.914863Z",
- "start_time": "2023-12-15T21:33:50.620442Z"
- },
"collapsed": false
},
"outputs": [],
"source": [
"# Create new session\n",
- "ao_client.start_session()\n",
+ "agentops.start_session()\n",
"\n",
"# Optionally, we can add tags to the session\n",
"# ao_client.start_session(['Hello Tracker'])"
@@ -201,27 +177,12 @@
},
{
"cell_type": "code",
- "execution_count": 4,
+ "execution_count": null,
"id": "b45754a57148eed1",
"metadata": {
- "ExecuteTime": {
- "end_time": "2023-12-15T21:34:24.301681Z",
- "start_time": "2023-12-15T21:34:24.297258Z"
- },
"collapsed": false
},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "6"
- ]
- },
- "execution_count": 4,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"from agentops import record_function\n",
"\n",
@@ -254,7 +215,7 @@
" model='gpt-3.5-turbo', messages=message, temperature=0.5)\n",
"\n",
"if \"hello\" in str(response.choices[0].message.content).lower():\n",
- " ao_client.record(ActionEvent(action_type=\"Agent says hello\", params=str(message), returns=str(response.choices[0].message.content) ))"
+ " agentops.record(ActionEvent(action_type=\"Agent says hello\", params=str(message), returns=str(response.choices[0].message.content) ))"
]
},
{
@@ -262,15 +223,11 @@
"execution_count": null,
"id": "4ca2b49fc06adddb",
"metadata": {
- "ExecuteTime": {
- "end_time": "2023-12-15T21:34:26.439101Z",
- "start_time": "2023-12-15T21:34:26.436252Z"
- },
"collapsed": false
},
"outputs": [],
"source": [
- "ao_client.end_session('Success')"
+ "agentops.end_session('Success')"
]
}
],