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
Refactor notebook examples for linitng (#980)
Dwija3d41f3aa1d7
diff --git a/agentops/instrumentation/openai_agents/instrumentor.py b/agentops/instrumentation/openai_agents/instrumentor.pyindex 60941dfa..2684bb50 100644--- a/agentops/instrumentation/openai_agents/instrumentor.py+++ b/agentops/instrumentation/openai_agents/instrumentor.py@@ -14,11 +14,12 @@ more data than we already have, since the `Response` object is always passed tofrom the `agents.tracing` module.TODO Calls to the OpenAI API are not available in this tracing context, so we may-need to monkey-patch the `openai` from here to get that data. While we do have-separate instrumentation for the OpenAI API, in order to get it to nest with the+need to monkey-patch the `openai` from here to get that data. While we do have+separate instrumentation for the OpenAI API, in order to get it to nest with thespans we create here, it's probably easier (or even required) that we incorporate-that here as well.+that here as well."""+from typing import Collectionfrom opentelemetry.instrumentation.instrumentor import BaseInstrumentor # type: ignorefrom agentops.logging import loggerdiff --git a/examples/openai_agents_sdk/customer_service_agent.ipynb b/examples/openai_agents_sdk/customer_service_agent.ipynbindex 53b84b95..1d1a5f10 100644--- a/examples/openai_agents_sdk/customer_service_agent.ipynb+++ b/examples/openai_agents_sdk/customer_service_agent.ipynb@@ -6,7 +6,7 @@"metadata": {},"outputs": [],"source": [- "# Install dependencies. \n",+ "# Install dependencies.\n","!pip install -U agentops openai-agents"]},@@ -19,13 +19,13 @@"# Set the API keys for your AgentOps and OpenAI accounts.\n","import os\n","\n",- "os.environ[\"OPENAI_API_KEY\"] = ''\n",- "os.environ[\"AGENTOPS_API_KEY\"] = ''\n",+ "os.environ[\"OPENAI_API_KEY\"] = \"\"\n",+ "os.environ[\"AGENTOPS_API_KEY\"] = \"\"\n","\n",- "if os.environ[\"OPENAI_API_KEY\"] == '':\n",+ "if os.environ[\"OPENAI_API_KEY\"] == \"\":\n"," raise ValueError(\"OPENAI_API_KEY is not set. You can get one at https://platform.openai.com/api-keys\")\n",- "if os.environ[\"AGENTOPS_API_KEY\"] == '':\n",- " raise ValueError(\"AGENTOPS_API_KEY is not set. You can get one at https://app.agentops.ai/\")\n"+ "if os.environ[\"AGENTOPS_API_KEY\"] == \"\":\n",+ " raise ValueError(\"AGENTOPS_API_KEY is not set. You can get one at https://app.agentops.ai/\")"]},{@@ -73,9 +73,7 @@"### TOOLS\n","\n","\n",- "@function_tool(\n",- " name_override=\"faq_lookup_tool\", description_override=\"Lookup frequently asked questions.\"\n",- ")\n",+ "@function_tool(name_override=\"faq_lookup_tool\", description_override=\"Lookup frequently asked questions.\")\n","async def faq_lookup_tool(question: str) -> str:\n"," if \"bag\" in question or \"baggage\" in question:\n"," return (\n",@@ -95,9 +93,7 @@"\n","\n","@function_tool\n",- "async def update_seat(\n",- " context: RunContextWrapper[AirlineAgentContext], confirmation_number: str, new_seat: str\n",- ") -> str:\n",+ "async def update_seat(context: RunContextWrapper[AirlineAgentContext], confirmation_number: str, new_seat: str) -> str:\n"," \"\"\"\n"," Update the seat for a given confirmation number.\n","\n",@@ -190,9 +186,7 @@" if isinstance(new_item, MessageOutputItem):\n"," print(f\"{agent_name}: {ItemHelpers.text_message_output(new_item)}\")\n"," elif isinstance(new_item, HandoffOutputItem):\n",- " print(\n",- " f\"Handed off from {new_item.source_agent.name} to {new_item.target_agent.name}\"\n",- " )\n",+ " print(f\"Handed off from {new_item.source_agent.name} to {new_item.target_agent.name}\")\n"," elif isinstance(new_item, ToolCallItem):\n"," print(f\"{agent_name}: Calling a tool\")\n"," elif isinstance(new_item, ToolCallOutputItem):\n",diff --git a/examples/openai_agents_sdk/tool_usage_agent.ipynb b/examples/openai_agents_sdk/tool_usage_agent.ipynbindex 73a0f04c..37c5ac27 100644--- a/examples/openai_agents_sdk/tool_usage_agent.ipynb+++ b/examples/openai_agents_sdk/tool_usage_agent.ipynb@@ -6,7 +6,7 @@"metadata": {},"outputs": [],"source": [- "# Install dependencies. \n",+ "# Install dependencies.\n","!pip install -U agentops openai-agents"]},@@ -19,13 +19,13 @@"# Set the API keys for your AgentOps and OpenAI accounts.\n","import os\n","\n",- "os.environ[\"OPENAI_API_KEY\"] = ''\n",- "os.environ[\"AGENTOPS_API_KEY\"] = ''\n",+ "os.environ[\"OPENAI_API_KEY\"] = \"\"\n",+ "os.environ[\"AGENTOPS_API_KEY\"] = \"\"\n","\n",- "if os.environ[\"OPENAI_API_KEY\"] == '':\n",+ "if os.environ[\"OPENAI_API_KEY\"] == \"\":\n"," raise ValueError(\"OPENAI_API_KEY is not set. You can get one at https://platform.openai.com/api-keys\")\n",- "if os.environ[\"AGENTOPS_API_KEY\"] == '':\n",- " raise ValueError(\"AGENTOPS_API_KEY is not set. You can get one at https://app.agentops.ai/\")\n"+ "if os.environ[\"AGENTOPS_API_KEY\"] == \"\":\n",+ " raise ValueError(\"AGENTOPS_API_KEY is not set. You can get one at https://app.agentops.ai/\")"]},{@@ -40,6 +40,7 @@"# AgentOps automatically reads the API key from the environment variable\n","agentops.init(tags=[\"weather-checker\", \"agentops-example\"])\n","\n",+ "\n","@function_tool\n","def get_weather(city: str) -> str:\n"," return f\"The weather in {city} is sunny.\"\n",@@ -54,12 +55,12 @@"\n","async def main():\n"," print(\"Starting agent...\")\n",- " result = await Runner.run(agent, \n",- " input=\"What's the weather in San Francisco?\")\n",+ " result = await Runner.run(agent, input=\"What's the weather in San Francisco?\")\n"," print(result.final_output)\n"," # The weather in San Francisco is sunny.\n","\n",- "await main()\n"+ "\n",+ "await main()"]},{diff --git a/examples/openai_agents_sdk/web_search_agent.ipynb b/examples/openai_agents_sdk/web_search_agent.ipynbindex 54d90e21..be9528b1 100644--- a/examples/openai_agents_sdk/web_search_agent.ipynb+++ b/examples/openai_agents_sdk/web_search_agent.ipynb@@ -6,7 +6,7 @@"metadata": {},"outputs": [],"source": [- "# Install dependencies. \n",+ "# Install dependencies.\n","!pip install -U agentops openai-agents"]},@@ -19,13 +19,13 @@"# Set the API keys for your AgentOps and OpenAI accounts.\n","import os\n","\n",- "os.environ[\"OPENAI_API_KEY\"] = ''\n",- "os.environ[\"AGENTOPS_API_KEY\"] = ''\n",+ "os.environ[\"OPENAI_API_KEY\"] = \"\"\n",+ "os.environ[\"AGENTOPS_API_KEY\"] = \"\"\n","\n",- "if os.environ[\"OPENAI_API_KEY\"] == '':\n",+ "if os.environ[\"OPENAI_API_KEY\"] == \"\":\n"," raise ValueError(\"OPENAI_API_KEY is not set. You can get one at https://platform.openai.com/api-keys\")\n",- "if os.environ[\"AGENTOPS_API_KEY\"] == '':\n",- " raise ValueError(\"AGENTOPS_API_KEY is not set. You can get one at https://app.agentops.ai/\")\n"+ "if os.environ[\"AGENTOPS_API_KEY\"] == \"\":\n",+ " raise ValueError(\"AGENTOPS_API_KEY is not set. You can get one at https://app.agentops.ai/\")"]},{@@ -40,6 +40,7 @@"# AgentOps automatically reads the API key from the environment variable\n","agentops.init(tags=[\"web-search-agent\", \"agentops-example\"])\n","\n",+ "\n","async def main():\n"," agent = Agent(\n"," name=\"Web searcher\",\n",@@ -55,6 +56,7 @@" print(result.final_output)\n"," # The New York Giants are reportedly pursuing quarterback Aaron Rodgers after his ...\n","\n",+ "\n","await main()"]},