Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions agentops/instrumentation/openai_agents/instrumentor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
from 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 the
spans we create here, it's probably easier (or even required) that we incorporate
that here as well.
that here as well.
"""

from typing import Collection
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor # type: ignore
from agentops.logging import logger
Expand Down
24 changes: 9 additions & 15 deletions examples/openai_agents_sdk/customer_service_agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Install dependencies. \n",
"# Install dependencies.\n",
"!pip install -U agentops openai-agents"
]
},
Expand All @@ -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/\")"
]
},
{
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
19 changes: 10 additions & 9 deletions examples/openai_agents_sdk/tool_usage_agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Install dependencies. \n",
"# Install dependencies.\n",
"!pip install -U agentops openai-agents"
]
},
Expand All @@ -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/\")"
]
},
{
Expand All @@ -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",
Expand All @@ -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()"
]
},
{
Expand Down
14 changes: 8 additions & 6 deletions examples/openai_agents_sdk/web_search_agent.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"metadata": {},
"outputs": [],
"source": [
"# Install dependencies. \n",
"# Install dependencies.\n",
"!pip install -U agentops openai-agents"
]
},
Expand All @@ -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/\")"
]
},
{
Expand All @@ -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",
Expand All @@ -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()"
]
},
Expand Down
Loading