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

notebook 1 (#978)

Alex Reibman614eb37364ea
diff --git a/examples/openai_agents_sdk/tool_usage_agent.ipynb b/examples/openai_agents_sdk/tool_usage_agent.ipynb
new file mode 100644
index 00000000..73a0f04c
--- /dev/null
+++ b/examples/openai_agents_sdk/tool_usage_agent.ipynb
@@ -0,0 +1,101 @@
+{
+ "cells": [
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Install dependencies. \n",
+ "!pip install -U agentops openai-agents"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# 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",
+ "\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"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from agents import Agent, Runner, function_tool\n",
+ "import agentops\n",
+ "\n",
+ "# AgentOps automatically reads the API key from the environment variable\n",
+ "agentops.init(tags=[\"weather-checker\", \"agentops-example\"])\n",
+ "\n",
+ "@function_tool\n",
+ "def get_weather(city: str) -> str:\n",
+ " return f\"The weather in {city} is sunny.\"\n",
+ "\n",
+ "\n",
+ "agent = Agent(\n",
+ " name=\"Weather checker\",\n",
+ " instructions=\"You are a helpful agent that checks the weather in a given city.\",\n",
+ " tools=[get_weather],\n",
+ ")\n",
+ "\n",
+ "\n",
+ "async def main():\n",
+ " print(\"Starting agent...\")\n",
+ " result = await Runner.run(agent, \n",
+ " 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"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "You can check the trace in the AgentOps UI: https://app.agentops.ai/traces"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "base",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.12.7"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 2
+}