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

[Fix] Updated notebooks that publish to examples docs pages (#585)

Pratyush Shukla1001e6488af5
diff --git a/docs/v1/examples/camel.mdx b/docs/v1/examples/camel.mdx
index 5509d11b..48f295e3 100644
--- a/docs/v1/examples/camel.mdx
+++ b/docs/v1/examples/camel.mdx
@@ -1,70 +1,155 @@
-# CamelAI and AgentOps
+---
+title: 'CAMEL AI Example'
+description: 'Using CAMEL AI for Multi-Agent Simulation'
+mode: "wide"
+---
+_View Notebook on <a href={'https://github.com/AgentOps-AI/agentops/blob/main/examples/camel_examples/camelai-multi-agent-example.ipynb'} target={'_blank'}>Github</a>_
-AgentOps supports CamelAI's API for conversing with their LLM backend!
+{/* SOURCE_FILE: examples/camel_examples/camelai-multi-agent-example.ipynb */}
-To start, learn more about CamelAI [here!](https://www.camel-ai.org)
-If you want to get down to the gritty details, look [here](https://docs.camel-ai.org) for their documentation.
+# CAMEL AI Multi Agent Example
+In this example, we will use CamelAI to simulate tools! We'll demonstrate a scenario where we determine how many melee hits it takes to beat an enemy with a blue shield in Apex Legends. The character "Pathfinder" from Apex Legends will provide the answer.
-
-> [!NOTE]
-> If it's your first time developing for an LLM, be sure to look at our intro to LLMs (coming soon)! Here, we explain generic functions such as giving the AI a memory to exploring novel concepts like summarizing chunks at regular intervals to keep some context while saving memory!
-
-## Getting Started
-
-You can get CamelAI's API working with a few lines of code!
-
-### 1. Import agentops and anthropic to your environment
+First let's install the required packages:
```python
%pip install camel-ai[all]
%pip install agentops
```
-### 2. Setup import statements
+Then import the necessary libraries:
```python
import agentops
import os
from getpass import getpass
from dotenv import load_dotenv
+from typing import List
+from colorama import Fore
+
+# Camel imports
+from camel.agents.chat_agent import FunctionCallingRecord
+from camel.models import ModelFactory
+from camel.societies import RolePlaying
+from camel.types import ModelPlatformType, ModelType
+from camel.utils import print_text_animated
+from camel.toolkits import SearchToolkit, MathToolkit
```
-### 3. Set your API keys
+Next, we'll set our API keys. There are several ways to do this, the code below is just the most foolproof way for the purposes of this notebook. It accounts for both users who use environment variables and those who just want to set the API Key here in this notebook.
-```python
-load_dotenv()
-openai_api_key = os.getenv("OPENAI_API_KEY") or "<your openai key here>"
-agentops_api_key = os.getenv("AGENTOPS_API_KEY") or "<your agentops key here>"
-```
-
-From here, you have a number of ways you can interact with the CamelAI API!
+[Get an AgentOps API key](https://agentops.ai/settings/projects)
-## Examples
+1. Create an environment variable in a .env file or other method. By default, the AgentOps `init()` function will look for an environment variable named `AGENTOPS_API_KEY`. Or...
-> [!NOTE]
-> You can download these journals directly and try them on Google Colab or Kaggle!
+2. Replace `<your_agentops_key>` below and pass in the optional `api_key` parameter to the AgentOps `init(api_key=...)` function. Remember not to commit your API key to a public repo!
+```python
+load_dotenv()
+OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") or "<your openai key here>"
+AGENTOPS_API_KEY = os.getenv("AGENTOPS_API_KEY") or "<your agentops key here>"
+```
-> [!WARNING]
-> Remember; you need to set an API key for both Agentops and OpenAI!
+Now we will initialize our AgentOps client:
+```python
+agentops.init(default_tags=["camel", "multi-agent", "example"])
+```
-## Simple Example; Creating a Bladewolf AI
+Let's set our task prompt and configure our tools. You can see all available tools in the [CAMEL AI documentation](https://docs.camel-ai.org/key_modules/tools.html).
-In this example, we use a csv file to short tune an LLM! We make it sounds like Bladewolf from MGR, before having it give us information.
+```python
+task_prompt = (
+ "We are in the Apex Legends Games. Determine the amount of"
+ "meele hits it will take to beat someone with a blue shield."
+ "You should answer as if you are Pathfinder from the Apex Games."
+)
+
+tools = [
+ *MathToolkit().get_tools(),
+ *SearchToolkit().get_tools(),
+]
+```
-[Access the Journal By Clicking Here](https://github.com/AgentOps-AI/agentops/blob/main/examples/camelai_examples/camelai-simple-example.ipynb).
+We will now create our Camel AI session which is of [`RolePlaying`](https://docs.camel-ai.org/key_modules/society.html#roleplaying) type. Here we will set the assistant and user role names, as well as the model and tools for each agent:
-> [!NOTE]
-> You need the Bladewolf Training CSV for this; you can find it [here](https://github.com/AgentOps-AI/agentops/blob/main/examples/camelai_examples/Bladewolf%20Training%20Data%20-%20Sheet1.csv).
+```python
+search_session = RolePlaying(
+ assistant_role_name="Searcher",
+ user_role_name="Pathfinder",
+ assistant_agent_kwargs=dict(
+ model=ModelFactory.create(
+ model_platform=ModelPlatformType.OPENAI,
+ model_type=ModelType.GPT_4O_MINI,
+ ),
+ tools=tools,
+ ),
+ user_agent_kwargs=dict(
+ model=ModelFactory.create(
+ model_platform=ModelPlatformType.OPENAI,
+ model_type=ModelType.GPT_4O_MINI,
+ ),
+ ),
+ task_prompt=task_prompt,
+ with_task_specify=False,
+)
+```
+Now we can start our chat loop. We'll set a maximum of 50 messages to prevent the session from running indefinitely:
-## Tool Example; Apex Legends Internet Search
+```python
+n = 0
+input_msg = search_session.init_chat()
+while n < 50:
+ n += 1
+ assistant_response, user_response = search_session.step(input_msg)
+
+ if assistant_response.terminated:
+ print(
+ Fore.GREEN
+ + (
+ "AI Assistant terminated. Reason: "
+ f"{assistant_response.info['termination_reasons']}."
+ )
+ )
+ break
+ if user_response.terminated:
+ print(
+ Fore.GREEN
+ + (
+ "AI User terminated. "
+ f"Reason: {user_response.info['termination_reasons']}."
+ )
+ )
+ break
+
+ # Print output from the user
+ print_text_animated(
+ Fore.BLUE + f"AI User:\\n\\n{user_response.msg.content}\\n"
+ )
+
+ # Print output from the assistant, including any function execution information
+ print_text_animated(Fore.GREEN + "AI Assistant:")
+ tool_calls: List[FunctionCallingRecord] = assistant_response.info[
+ 'tool_calls'
+ ]
+ for func_record in tool_calls:
+ print_text_animated(f"{func_record}")
+ print_text_animated(f"{assistant_response.msg.content}\\n")
+
+ if "CAMEL_TASK_DONE" in user_response.msg.content:
+ break
+
+ input_msg = assistant_response.msg
+```
-In this example, we look at the tool system within more depth! We will do a search to understand how Apex's melee damage and shields work before determining how many meelee attacks it will take to break a blue shield.
+Awesome! We've successfully completed our session.
-[Access the Journal By Clicking Here](https://github.com/AgentOps-AI/agentops/blob/main/examples/camelai_examples/camelai-multi-agent-example.ipynb)
+Now we will end the session with a success message. We can also end the session with a failure or indeterminate status. By default, the session will be marked as indeterminate.
+```python
+agentops.end_session("Success")
+```
-> [!NOTE]
-> If you want to use the tools system, be sure to check their website to find a comprehensive list of the different tools CamelAI supports! [You can find the tools available here!](https://docs.camel-ai.org/key_modules/tools.html#passing-tools-to-chatagent)
\ No newline at end of file
+## Check your session
+You can now check your run on [AgentOps](https://app.agentops.ai) to see the recorded session with all the interactions between the agents and tool usage.
diff --git a/docs/v1/examples/examples.mdx b/docs/v1/examples/examples.mdx
index af39ffab..ed3c554d 100644
--- a/docs/v1/examples/examples.mdx
+++ b/docs/v1/examples/examples.mdx
@@ -37,6 +37,10 @@ mode: "wide"
AutoGen multi-agent conversible workflow with tool usage
</Card>
+ <Card title="CamelAI" icon={<img src="https://www.github.com/agentops-ai/agentops/blob/main/docs/images/external/camel/camel.png?raw=true" alt="CamelAI" />} iconType="image" href="/v1/examples/camel">
+ Track and analyze CAMEL agents
+ </Card>
+
<Card title="Cohere" icon={<img src="https://www.github.com/agentops-ai/agentops/blob/main/docs/images/external/cohere/cohere-logo.svg?raw=true" alt="Cohere" />} iconType="image" href="/v1/integrations/cohere">
First class support for Command-R-Plus and chat streaming
</Card>
@@ -77,10 +81,6 @@ mode: "wide"
First class support for GPT family of models
</Card>
- <Card title="CamelAI" icon={<img src="https://www.github.com/agentops-ai/agentops/blob/main/docs/images/external/camel/camel.png?raw=true" alt="CamelAI" />} iconType="image" href="/v1/examples/camel">
- Track and analyze CAMEL agents including LLM and Tool usage
- </Card>
-
<Card title="REST API" icon="bolt-lightning" href="/v1/examples/restapi">
Create a REST server that performs and observes agent tasks
</Card>
diff --git a/docs/v1/examples/langchain.mdx b/docs/v1/examples/langchain.mdx
index d7712d62..aeb77cd9 100644
--- a/docs/v1/examples/langchain.mdx
+++ b/docs/v1/examples/langchain.mdx
@@ -61,12 +61,6 @@ This is where AgentOps comes into play. Before creating our LLM instance via Lan
Pass in your API key, and optionally any tags to describe this session for easier lookup in the AO dashboard.
-agentops_handler = AgentOpsLangchainCallbackHandler(
- api_key=AGENTOPS_API_KEY, default_tags=["Langchain Example"]
-)
-
-
-
```python
agentops_handler = AgentOpsLangchainCallbackHandler(
api_key=AGENTOPS_API_KEY, default_tags=["Langchain Example"]
@@ -148,5 +142,6 @@ Finally, check your run on [AgentOps](https://app.agentops.ai)
Now if we look in the AgentOps dashboard, you will see a session recorded with the LLM calls and tool usage.
-## Langchain V0.1 Example
-You can find the example in the [notebook](https://github.com/AgentOps-AI/agentops/blob/main/examples/langchain_examples.ipynb).
+## Langchain v0 Example
+
+This langchain version is out of date and support is being deprecated. You can find the example notebook [here](https://github.com/agentops-ai/agentops/blob/main/examples/langchain_examples/langchain_v0_example.ipynb).
diff --git a/docs/v1/examples/simple_agent.mdx b/docs/v1/examples/simple_agent.mdx
index 450f0f8c..1727da13 100644
--- a/docs/v1/examples/simple_agent.mdx
+++ b/docs/v1/examples/simple_agent.mdx
@@ -115,7 +115,7 @@ if "hello" in str(response.choices[0].message.content).lower():
agentops.record(
ActionEvent(
action_type="Agent says hello",
- params=str(message),
+ logs=str(message),
returns=str(response.choices[0].message.content),
)
)
diff --git a/docs/v1/integrations/camel.mdx b/docs/v1/integrations/camel.mdx
index 9f94c8b9..6e2ca331 100644
--- a/docs/v1/integrations/camel.mdx
+++ b/docs/v1/integrations/camel.mdx
@@ -1,12 +1,12 @@
---
title: 'Camel AI'
-description: 'Track and analyze CAMEL agents including LLMs and Tools usage with AgentOps'
+description: 'Track and analyze CAMEL agents with AgentOps'
---
import CodeTooltip from '/snippets/add-code-tooltip.mdx'
import EnvTooltip from '/snippets/add-env-tooltip.mdx'
-[CAMEL](https://www.camel-ai.org/) is the first large language model (LLM) multi-agent framework and an open-source community dedicated to finding the scaling law of agents. CAMEL has comprehensive [documentation](https://docs.camel-ai.org/) available as well as a great [quickstart](https://docs.camel-ai.org/getting_started/installation.html) guide.
+[CAMEL-AI](https://www.camel-ai.org/) is the first large language model (LLM) multi-agent framework and an open-source community dedicated to finding the scaling law of agents. Checkout their comprehensive documentation [here](https://docs.camel-ai.org/).
## Adding AgentOps to CAMEL agents
@@ -21,7 +21,7 @@ import EnvTooltip from '/snippets/add-env-tooltip.mdx'
```
</CodeGroup>
</Step>
- <Step title="Install CAMEL">
+ <Step title="Install CAMEL-AI with all dependencies">
<CodeGroup>
```bash pip
pip install "camel-ai[all]==0.2.11"
@@ -31,14 +31,15 @@ import EnvTooltip from '/snippets/add-env-tooltip.mdx'
```
</CodeGroup>
</Step>
- <Step title="Add 3 lines of code">
+ <Step title="Add AgentOps code to your code">
<CodeTooltip/>
<CodeGroup>
```python python
import agentops
agentops.init(<INSERT YOUR API KEY HERE>)
- ...
- # MUST END SESSION at end of program
+
+ # your code here
+
agentops.end_session("Success") # Success|Fail|Indeterminate
```
</CodeGroup>
@@ -62,9 +63,10 @@ import EnvTooltip from '/snippets/add-env-tooltip.mdx'
</Step>
</Steps>
-## Single Agent Example with Tools
+## Full Examples
+### Single Agent Example with Tools
-Here's a simple example of tracking a CAMEL single agent with tools using AgentOps:
+Here's a simple example of tracking a single CAMEL agent with tools using AgentOps:
```python
import agentops
@@ -109,37 +111,9 @@ print(response)
agentops.end_session("Success")
```
-## Multi-Agent Example
-
-For more complex scenarios, CAMEL supports multi-agent interactions. Here's how to track multiple agents:
-
-```python
-import agentops
-from typing import List
-from camel.agents.chat_agent import FunctionCallingRecord
-from camel.societies import RolePlaying
-from camel.types import ModelPlatformType, ModelType
-
-# Initialize AgentOps with multi-agent tag
-agentops.start_session(tags=["CAMEL X AgentOps Multi-agent"])
-
-# Import toolkits after AgentOps init
-from camel.toolkits import SearchToolkit, MathToolkit
-
-# Set up your task
-task_prompt = (
- "Assume now is 2024 in the Gregorian calendar, "
- "estimate the current age of University of Oxford "
- "and then add 10 more years to this age, "
- "and get the current weather of the city where "
- "the University is located."
-)
-
-# The rest of your multi-agent implementation...
-# See our example notebook for the complete implementation
-```
+### Multi-Agent Example
-For complete examples including multi-agent setups and advanced configurations, check out our [example notebooks](https://github.com/AgentOps-AI/agentops/tree/main/examples/camel_examples).
+Check out the example notebook [here](https://github.com/AgentOps-AI/agentops/tree/main/examples/camel_examples/camelai-multi-agent-example.ipynb) to see how to track multi-agent setups.
<script type="module" src="/scripts/github_stars.js"></script>
<script type="module" src="/scripts/scroll-img-fadein-animation.js"></script>
diff --git a/examples/anthropic_examples/README.md b/examples/anthropic_examples/README.md
index ffeb9c82..70bf658f 100644
--- a/examples/anthropic_examples/README.md
+++ b/examples/anthropic_examples/README.md
@@ -1,10 +1,8 @@
# Anthropic and AgentOps
-AgentOps supports Anthropic's API for conversing with their LLM backend!
-
-To start, learn more about Antropic [here!](https://www.anthropic.com)
-If you want to get down to the gritty details, look [here](https://docs.anthropic.com/en/docs/welcome) for their documentation.
+AgentOps provides first party support for observing Anthropic's API.
+Explore [Anthropic's](https://www.anthropic.com) documentation [here.](https://docs.anthropic.com/en/docs/welcome) to get started.
> [!NOTE]
> If it's your first time developing for an LLM, be sure to look at our intro to LLMs (coming soon)! Here, we explain generic functions such as giving the AI a memory to exploring novel concepts like summarizing chunks at regular intervals to keep some context while saving memory!
@@ -42,49 +40,31 @@ From here, you have a number of ways you can interact with the Anthropic API!
## Examples
> [!NOTE]
-> You can download these journals directly and try them on Google Colab or Kaggle!
-
-
-> [!WARNING]
-> Remember; you need to set an API key for both Agentops and Anthropic!
+> You need to set an API key for both Agentops and Anthropic!
-
-## Sync Example; Nier Storyteller
+## Sync Example - Nier Storyteller
In this example, we generate a sentence from three parts before having Anthropic generate a short story based off it!
-[Access the Journal By Clicking Here](./anthropic-example-sync.ipynb).
+Access the example [here.](./anthropic-example-sync.ipynb).
-## Async Example; Titan Support Protocol
+## Async Example - Titan Support Protocol
In this example, we generate a script line for a mech based on it's health and the type. At the same time, we generate 4 UUIDs. We finally wait for both functions to finish before printing them for the user.
-[Access the Journal By Clicking Here](./anthropic-example-async.ipynb)
+Access the example [here.](./anthropic-example-async.ipynb)
-## Tool Example; Cyberware
+## Tool Example - Cyberware
In this example, we have the LLM call a simulated tool which gives one random piece of Cyberware based on the user's requested company. From there, the AI tells the user if the cyberware is good for the user's intended purpose. (combatant, hacker, etc.).
-[Access the Journal By Clicking Here](./antrophic-example-tool.ipynb)
-
-
-
-
-> [!WARNING]
-> If you want to use the tools system, please look at the journal below! This gives examples related to knowing when a tool was used, some practices for calling a function from an API and returning it among other things! Using it is NOT the same as the other examples!
-
+Access the example [here.](./antrophic-example-tool.ipynb)
-## Tool Deepdive; VEGA Hell Combat System
+## Tool Deepdive - VEGA Hell Combat System
In this example, we look at the tool system through a deeper dive; we will use our LLM assistant, VEGA, to get three missions from an API and determine which deserves priority. Then, we will send a number of enemies we want to scan for during combat while also getting our weapons inventory (using two tools at the same time). VEGA will tell us the bet way in which to combat these enemies through a combat strategy.
-[Access the Journal By Clicking Here](./agentops-anthropic-understanding-tools.ipynb)
-
-
-[You should also look at Anthropic's Tool Documents!](https://docs.anthropic.com/en/docs/build-with-claude/tool-use)
-
-
-
-
-
+Access the example [here.](./agentops-anthropic-understanding-tools.ipynb)
+> [!NOTE]
+> You can explore Anthropic's Tool Calling documentation [here](https://docs.anthropic.com/en/docs/build-with-claude/tool-use) to learn how to use it, some examples and pricing.
diff --git a/examples/anthropic_examples/agentops-anthropic-understanding-tools.ipynb b/examples/anthropic_examples/agentops-anthropic-understanding-tools.ipynb
index 4f80d321..f6d7a01a 100644
--- a/examples/anthropic_examples/agentops-anthropic-understanding-tools.ipynb
+++ b/examples/anthropic_examples/agentops-anthropic-understanding-tools.ipynb
@@ -4,6 +4,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
+ "# Anthropic Example for understanding Tools\n",
+ "\n",
"Anthropic's tool returns are not as simple as getting a few strings! While this system is more complex than those before it, it's also simple enough to be used without problem once you understand how it works! "
]
},
@@ -20,8 +22,8 @@
"metadata": {},
"outputs": [],
"source": [
- "!pip install agentops\n",
- "!pip install anthropic"
+ "%pip install agentops\n",
+ "%pip install anthropic"
]
},
{
@@ -37,13 +39,13 @@
"metadata": {},
"outputs": [],
"source": [
- "from anthropic import Anthropic, AsyncAnthropic\n",
"import agentops\n",
+ "from anthropic import Anthropic, AsyncAnthropic\n",
+ "from dotenv import load_dotenv\n",
"import os\n",
- "import random # We don't need this for agentops, we use this to generate a message later\n",
- "import time # We don't need this for agentops either, we use this when simulating an API later\n",
- "import re # Regex for formatting\n",
- "from dotenv import load_dotenv"
+ "import random\n",
+ "import time\n",
+ "import re"
]
},
{
@@ -74,27 +76,9 @@
},
{
"cell_type": "code",
- "execution_count": 4,
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "🖇 AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=df6426c5-1995-4bec-b90e-680369a0cddb\u001b[0m\u001b[0m\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "<agentops.session.Session at 0x10e6ca710>"
- ]
- },
- "execution_count": 4,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"agentops.init(AGENTOPS_API_KEY, default_tags=[\"anthropic-example-tool-tutorials\"])"
]
@@ -205,32 +189,9 @@
},
{
"cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Locate and confront a key leader of Hell’s invasion forces.\n",
- "Clear out demonic infestations to secure a strategic foothold.\n",
- "Disrupt Hell's control over the area by eliminating critical targets.\n",
- "Enter a critical demonic stronghold to disrupt enemy operations.\n",
- "Locate and destroy the central power source to weaken enemy forces.\n",
- "Collect essential resources before the area becomes unstable.\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "\"Locate and confront a key leader of Hell’s invasion forces.\\nClear out demonic infestations to secure a strategic foothold.\\nDisrupt Hell's control over the area by eliminating critical targets.\\nEnter a critical demonic stronghold to disrupt enemy operations.\\nLocate and destroy the central power source to weaken enemy forces.\\nCollect essential resources before the area becomes unstable.\""
- ]
- },
- "execution_count": 8,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"generate_missions()"
]
@@ -275,17 +236,9 @@
},
{
"cell_type": "code",
- "execution_count": 10,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[TextBlock(text=\"Certainly! As VEGA, I'll retrieve three missions for the DoomSlayer from the ship's API using the available function. Then, I'll analyze and prioritize them based on their importance for quelling the forces of Hell.\\n\\nLet's begin by retrieving the missions:\", type='text'), ToolUseBlock(id='toolu_01HAJR2iiPBGr9A473tZyewV', input={}, name='generate_missions', type='tool_use')]\n"
- ]
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"response = client.messages.create(\n",
" max_tokens=5000,\n",
@@ -312,19 +265,9 @@
},
{
"cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Certainly! As VEGA, I'll retrieve three missions for the DoomSlayer from the ship's API using the available function. Then, I'll analyze and prioritize them based on their importance for quelling the forces of Hell.\n",
- "\n",
- "Let's begin by retrieving the missions:\n"
- ]
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"message = response.content[0].text\n",
"print(message)"
@@ -339,23 +282,9 @@
},
{
"cell_type": "code",
- "execution_count": 12,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[TextBlock(text=\"Certainly! As VEGA, I'll retrieve three missions for the DoomSlayer from the ship's API using the available function. Then, I'll analyze and prioritize them based on their importance for quelling the forces of Hell.\\n\\nLet's begin by retrieving the missions:\", type='text'), ToolUseBlock(id='toolu_01HAJR2iiPBGr9A473tZyewV', input={}, name='generate_missions', type='tool_use')]\n",
- "Locate and confront a key leader of Hell’s invasion forces.\n",
- "Clear out demonic infestations to secure a strategic foothold.\n",
- "Disrupt Hell's control over the area by eliminating critical targets.\n",
- "Enter a critical demonic stronghold to disrupt enemy operations.\n",
- "Locate and destroy the central power source to weaken enemy forces.\n",
- "Collect essential resources before the area becomes unstable.\n"
- ]
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"gen_mission_result = \"\"\n",
"\n",
@@ -409,17 +338,9 @@
},
{
"cell_type": "code",
- "execution_count": 14,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Message(id='msg_016Hd62W2sJNyd762Yp1udLd', content=[TextBlock(text=\"I apologize for the confusion in my previous response. I made a mistake by providing mission details without actually retrieving them from the ship's API. Let me correct that by properly retrieving the missions using the available function. \", type='text'), ToolUseBlock(id='toolu_01TUaMJbZc7VHMVZKaA9RqvL', input={}, name='generate_missions', type='tool_use')], model='claude-3-5-sonnet-20240620', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=Usage(input_tokens=497, output_tokens=83))\n"
- ]
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"response = client.messages.create(\n",
" max_tokens=5000,\n",
@@ -446,17 +367,9 @@
},
{
"cell_type": "code",
- "execution_count": 15,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "I apologize for the confusion in my previous response. I made a mistake by providing mission details without actually retrieving them from the ship's API. Let me correct that by properly retrieving the missions using the available function. \n"
- ]
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"message = response.content[0].text\n",
"print(message)"
@@ -575,38 +488,9 @@
},
{
"cell_type": "code",
- "execution_count": 19,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Imp\n",
- "A fast, agile demon that hurls fireballs and uses its claws to tear apart its prey. Imps are commonly found in Hell’s army, notorious for their quickness and ability to climb walls, making them dangerous adversaries in any environment.\n",
- "Cacodemon\n",
- "A floating, spherical demon with a large mouth full of teeth and an ability to launch explosive projectiles. Cacodemons are often encountered in open areas, where their aerial agility and relentless attacks pose a constant threat.\n",
- "Imp\n",
- "A fast, agile demon that hurls fireballs and uses its claws to tear apart its prey. Imps are commonly found in Hell’s army, notorious for their quickness and ability to climb walls, making them dangerous adversaries in any environment.\n",
- "Imp\n",
- "A fast, agile demon that hurls fireballs and uses its claws to tear apart its prey. Imps are commonly found in Hell’s army, notorious for their quickness and ability to climb walls, making them dangerous adversaries in any environment.\n",
- "Cacodemon\n",
- "A floating, spherical demon with a large mouth full of teeth and an ability to launch explosive projectiles. Cacodemons are often encountered in open areas, where their aerial agility and relentless attacks pose a constant threat.\n",
- "Hell Knight\n",
- "A towering, brutish demon with immense strength and durability. The Hell Knight is capable of charging at the Doom Slayer and delivering devastating melee attacks. Its tough hide makes it resistant to most forms of damage.\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "'Imp\\nA fast, agile demon that hurls fireballs and uses its claws to tear apart its prey. Imps are commonly found in Hell’s army, notorious for their quickness and ability to climb walls, making them dangerous adversaries in any environment.\\nCacodemon\\nA floating, spherical demon with a large mouth full of teeth and an ability to launch explosive projectiles. Cacodemons are often encountered in open areas, where their aerial agility and relentless attacks pose a constant threat.\\nImp\\nA fast, agile demon that hurls fireballs and uses its claws to tear apart its prey. Imps are commonly found in Hell’s army, notorious for their quickness and ability to climb walls, making them dangerous adversaries in any environment.\\nImp\\nA fast, agile demon that hurls fireballs and uses its claws to tear apart its prey. Imps are commonly found in Hell’s army, notorious for their quickness and ability to climb walls, making them dangerous adversaries in any environment.\\nCacodemon\\nA floating, spherical demon with a large mouth full of teeth and an ability to launch explosive projectiles. Cacodemons are often encountered in open areas, where their aerial agility and relentless attacks pose a constant threat.\\nHell Knight\\nA towering, brutish demon with immense strength and durability. The Hell Knight is capable of charging at the Doom Slayer and delivering devastating melee attacks. Its tough hide makes it resistant to most forms of damage.'"
- ]
- },
- "execution_count": 19,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"enemyscan(5)"
]
@@ -644,36 +528,9 @@
},
{
"cell_type": "code",
- "execution_count": 21,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "BFG 9000\n",
- "One of the most iconic weapons in the *Doom* franchise, the BFG 9000 fires a massive energy beam that obliterates anything in its path. With its massive damage potential, the BFG 9000 is a game-changer, especially in dealing with large groups of enemies or the toughest foes.\n",
- "Chaingun\n",
- "A rapid-fire weapon that can unleash a torrent of bullets at a high rate of speed. The Chaingun is perfect for mowing down enemies and can be equipped with the Heat Blast mod, allowing for explosive energy rounds that can clear multiple enemies at once.\n",
- "BFG 9000\n",
- "One of the most iconic weapons in the *Doom* franchise, the BFG 9000 fires a massive energy beam that obliterates anything in its path. With its massive damage potential, the BFG 9000 is a game-changer, especially in dealing with large groups of enemies or the toughest foes.\n",
- "Rocket Launcher\n",
- "A high-powered weapon that fires explosive rockets capable of dealing massive area damage. The Rocket Launcher is invaluable for taking down groups of enemies or dealing significant damage to larger demons, especially when upgraded with the Lock-On Burst mod.\n",
- "Rocket Launcher\n",
- "A high-powered weapon that fires explosive rockets capable of dealing massive area damage. The Rocket Launcher is invaluable for taking down groups of enemies or dealing significant damage to larger demons, especially when upgraded with the Lock-On Burst mod.\n"
- ]
- },
- {
- "data": {
- "text/plain": [
- "'BFG 9000\\nOne of the most iconic weapons in the *Doom* franchise, the BFG 9000 fires a massive energy beam that obliterates anything in its path. With its massive damage potential, the BFG 9000 is a game-changer, especially in dealing with large groups of enemies or the toughest foes.\\nChaingun\\nA rapid-fire weapon that can unleash a torrent of bullets at a high rate of speed. The Chaingun is perfect for mowing down enemies and can be equipped with the Heat Blast mod, allowing for explosive energy rounds that can clear multiple enemies at once.\\nBFG 9000\\nOne of the most iconic weapons in the *Doom* franchise, the BFG 9000 fires a massive energy beam that obliterates anything in its path. With its massive damage potential, the BFG 9000 is a game-changer, especially in dealing with large groups of enemies or the toughest foes.\\nRocket Launcher\\nA high-powered weapon that fires explosive rockets capable of dealing massive area damage. The Rocket Launcher is invaluable for taking down groups of enemies or dealing significant damage to larger demons, especially when upgraded with the Lock-On Burst mod.\\nRocket Launcher\\nA high-powered weapon that fires explosive rockets capable of dealing massive area damage. The Rocket Launcher is invaluable for taking down groups of enemies or dealing significant damage to larger demons, especially when upgraded with the Lock-On Burst mod.'"
- ]
- },
- "execution_count": 21,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"inventoryscan()"
]
@@ -687,17 +544,9 @@
},
{
"cell_type": "code",
- "execution_count": 22,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Message(id='msg_0119o5gGDi7TRTsNPzNXd2ov', content=[TextBlock(text=\"Certainly! I'll prioritize the missions and use both tools to scan for enemies and check the inventory simultaneously. Let's proceed with the tool calls first.\", type='text'), ToolUseBlock(id='toolu_01MmqMojDYtt5qdWnsXMJoWL', input={'amount': 5}, name='enemyscan_tool', type='tool_use'), ToolUseBlock(id='toolu_01WxN7tUMTFTai1WdiFc94HW', input={}, name='inventoryscan_tool', type='tool_use')], model='claude-3-5-sonnet-20240620', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=Usage(input_tokens=610, output_tokens=110))\n"
- ]
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"response = client.messages.create(\n",
" max_tokens=5000,\n",
@@ -738,17 +587,9 @@
},
{
"cell_type": "code",
- "execution_count": 23,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Certainly! I'll prioritize the missions and use both tools to scan for enemies and check the inventory simultaneously. Let's proceed with the tool calls first.\n"
- ]
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"message = response.content[0].text\n",
"print(message)"
@@ -772,60 +613,9 @@
},
{
"cell_type": "code",
- "execution_count": 25,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Hell Knight\n",
- "A towering, brutish demon with immense strength and durability. The Hell Knight is capable of charging at the Doom Slayer and delivering devastating melee attacks. Its tough hide makes it resistant to most forms of damage.\n",
- "Imp\n",
- "A fast, agile demon that hurls fireballs and uses its claws to tear apart its prey. Imps are commonly found in Hell’s army, notorious for their quickness and ability to climb walls, making them dangerous adversaries in any environment.\n",
- "Hell Knight\n",
- "A towering, brutish demon with immense strength and durability. The Hell Knight is capable of charging at the Doom Slayer and delivering devastating melee attacks. Its tough hide makes it resistant to most forms of damage.\n",
- "Mancubus\n",
- "A grotesque, overweight demon that releases powerful fireballs from its massive arm cannons. Mancubus demons are slow-moving but dangerous due to their firepower and the ability to overwhelm enemies with their fiery onslaughts.\n",
- "Hell Knight\n",
- "A towering, brutish demon with immense strength and durability. The Hell Knight is capable of charging at the Doom Slayer and delivering devastating melee attacks. Its tough hide makes it resistant to most forms of damage.\n",
- "Cacodemon\n",
- "A floating, spherical demon with a large mouth full of teeth and an ability to launch explosive projectiles. Cacodemons are often encountered in open areas, where their aerial agility and relentless attacks pose a constant threat.\n",
- "Rocket Launcher\n",
- "A high-powered weapon that fires explosive rockets capable of dealing massive area damage. The Rocket Launcher is invaluable for taking down groups of enemies or dealing significant damage to larger demons, especially when upgraded with the Lock-On Burst mod.\n",
- "BFG 9000\n",
- "One of the most iconic weapons in the *Doom* franchise, the BFG 9000 fires a massive energy beam that obliterates anything in its path. With its massive damage potential, the BFG 9000 is a game-changer, especially in dealing with large groups of enemies or the toughest foes.\n",
- "BFG 9000\n",
- "One of the most iconic weapons in the *Doom* franchise, the BFG 9000 fires a massive energy beam that obliterates anything in its path. With its massive damage potential, the BFG 9000 is a game-changer, especially in dealing with large groups of enemies or the toughest foes.\n",
- "Super Shotgun\n",
- "A powerful, double-barreled shotgun that delivers devastating close-range damage. Known for its sheer stopping power, the Super Shotgun can tear through enemies with ease, especially when equipped with the Meat Hook attachment, allowing for rapid mobility and devastating hits.\n",
- "Ice Bomb\n",
- "A special grenade that freezes enemies in a wide area, giving the Doom Slayer a chance to deal with multiple foes at once. The Ice Bomb is effective for crowd control, allowing for easy Glory Kills or creating distance from overwhelming enemies.\n",
- "Rocket Launcher\n",
- "A high-powered weapon that fires explosive rockets capable of dealing massive area damage. The Rocket Launcher is invaluable for taking down groups of enemies or dealing significant damage to larger demons, especially when upgraded with the Lock-On Burst mod.\n",
- "BFG 9000\n",
- "One of the most iconic weapons in the *Doom* franchise, the BFG 9000 fires a massive energy beam that obliterates anything in its path. With its massive damage potential, the BFG 9000 is a game-changer, especially in dealing with large groups of enemies or the toughest foes.\n",
- "BFG 9000\n",
- "One of the most iconic weapons in the *Doom* franchise, the BFG 9000 fires a massive energy beam that obliterates anything in its path. With its massive damage potential, the BFG 9000 is a game-changer, especially in dealing with large groups of enemies or the toughest foes.\n",
- "Super Shotgun\n",
- "A powerful, double-barreled shotgun that delivers devastating close-range damage. Known for its sheer stopping power, the Super Shotgun can tear through enemies with ease, especially when equipped with the Meat Hook attachment, allowing for rapid mobility and devastating hits.\n",
- "Ice Bomb\n",
- "A special grenade that freezes enemies in a wide area, giving the Doom Slayer a chance to deal with multiple foes at once. The Ice Bomb is effective for crowd control, allowing for easy Glory Kills or creating distance from overwhelming enemies.\n",
- "Hell Knight\n",
- "A towering, brutish demon with immense strength and durability. The Hell Knight is capable of charging at the Doom Slayer and delivering devastating melee attacks. Its tough hide makes it resistant to most forms of damage.\n",
- "Imp\n",
- "A fast, agile demon that hurls fireballs and uses its claws to tear apart its prey. Imps are commonly found in Hell’s army, notorious for their quickness and ability to climb walls, making them dangerous adversaries in any environment.\n",
- "Hell Knight\n",
- "A towering, brutish demon with immense strength and durability. The Hell Knight is capable of charging at the Doom Slayer and delivering devastating melee attacks. Its tough hide makes it resistant to most forms of damage.\n",
- "Mancubus\n",
- "A grotesque, overweight demon that releases powerful fireballs from its massive arm cannons. Mancubus demons are slow-moving but dangerous due to their firepower and the ability to overwhelm enemies with their fiery onslaughts.\n",
- "Hell Knight\n",
- "A towering, brutish demon with immense strength and durability. The Hell Knight is capable of charging at the Doom Slayer and delivering devastating melee attacks. Its tough hide makes it resistant to most forms of damage.\n",
- "Cacodemon\n",
- "A floating, spherical demon with a large mouth full of teeth and an ability to launch explosive projectiles. Cacodemons are often encountered in open areas, where their aerial agility and relentless attacks pose a constant threat.\n"
- ]
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"inv_scan_res = \"\"\n",
"enemy_scan_res = \"\"\n",
@@ -895,42 +685,9 @@
},
{
"cell_type": "code",
- "execution_count": 27,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Certainly, I'll outline a combat plan for efficiently eliminating these demons based on the enemy scan and our available weaponry. Here's the recommended order of engagement and the most effective weapons to use:\n",
- "\n",
- "1. Cacodemon (Highest Priority):\n",
- " - Weapon: Rocket Launcher with Lock-On Burst mod\n",
- " - Strategy: The Cacodemon's aerial mobility makes it a priority target. Use the Rocket Launcher's Lock-On Burst to ensure hits. Aim for its open mouth, which is its weak point. A well-placed rocket in its mouth can stagger it, allowing for a quick Glory Kill.\n",
- "\n",
- "2. Mancubus:\n",
- " - Weapon: BFG 9000\n",
- " - Strategy: The Mancubus is slow but dangerous due to its high firepower. Use the BFG 9000 to deal massive damage quickly. Aim for its arm cannons to disable its primary attack method. The BFG's area effect can also damage nearby demons.\n",
- "\n",
- "3. Hell Knights (3 present):\n",
- " - Weapon: Super Shotgun with Meat Hook\n",
- " - Strategy: Use the Meat Hook to close distance quickly, then unleash the Super Shotgun's devastating close-range damage. Aim for the head to maximize damage. The Ice Bomb can be used to freeze multiple Hell Knights at once, allowing for easier targeting and potential Glory Kills.\n",
- "\n",
- "4. Imps (Lowest Priority):\n",
- " - Weapon: Super Shotgun or Rocket Launcher (for groups)\n",
- " - Strategy: Imps are fast but relatively weak. Use the Super Shotgun for close encounters or the Rocket Launcher to take out groups. Their agility makes them dangerous if ignored, so eliminate them when they group up or after dealing with bigger threats.\n",
- "\n",
- "General Combat Tips:\n",
- "1. Use the Ice Bomb strategically to freeze multiple enemies, especially when Hell Knights and Imps are grouped together.\n",
- "2. Keep moving to avoid being surrounded. Use the Meat Hook on the Super Shotgun for quick mobility between targets.\n",
- "3. Save the BFG 9000 ammo for the Mancubus or if you get overwhelmed by multiple heavy demons.\n",
- "4. Prioritize Glory Kills when possible to replenish health and armor.\n",
- "5. Use the environment to your advantage, funneling enemies into choke points for more effective use of area-of-effect weapons like the Rocket Launcher.\n",
- "\n",
- "Remember, Doom Slayer, the key is to stay mobile, prioritize threats, and make efficient use of your diverse arsenal. Rip and tear, until it is done!\n"
- ]
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"response = client.messages.create(\n",
" max_tokens=5000,\n",
@@ -967,23 +724,14 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "End the session"
+ "Awesome! We can track all this information in the AgentOps dashboard by going to the session URL provided above. Now we will end the session with a success message. We can also end the session with a failure or intdeterminate status. By default, the session will be marked as indeterminate."
]
},
{
"cell_type": "code",
- "execution_count": 28,
- "metadata": {},
- "outputs": [
- {
- "name": "stderr",
- "output_type": "stream",
- "text": [
- "🖇 AgentOps: Session Stats - \u001b[1mDuration:\u001b[0m 27.6s | \u001b[1mCost:\u001b[0m $0.022353 | \u001b[1mLLMs:\u001b[0m 4 | \u001b[1mTools:\u001b[0m 0 | \u001b[1mActions:\u001b[0m 0 | \u001b[1mErrors:\u001b[0m 0\n",
- "🖇 AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=df6426c5-1995-4bec-b90e-680369a0cddb\u001b[0m\u001b[0m\n"
- ]
- }
- ],
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
"source": [
"agentops.end_session(\"Success\")"
]
diff --git a/examples/anthropic_examples/anthropic-example-async.ipynb b/examples/anthropic_examples/anthropic-example-async.ipynb
index 292f39c7..a68079b1 100644
--- a/examples/anthropic_examples/anthropic-example-async.ipynb
+++ b/examples/anthropic_examples/anthropic-example-async.ipynb
@@ -4,6 +4,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
+ "# Anthropic Async Example\n",
+ "\n",
"Anthropic supports both sync and async! This is great because we can wait for functions to finish before we use them! \n",
"\n",
"In this example, we will make a program called \"Titan Support Protocol.\" In this example, we will assign our mech a personality type and have a message generated based on our Titan's health (Which we randomly choose). We also send four generated UUIDs which are generated while the LLM runs"
@@ -59,11 +61,11 @@
"source": [
"from anthropic import Anthropic, AsyncAnthropic\n",
"import agentops\n",
+ "from dotenv import load_dotenv\n",
"import os\n",
- "import random # We don't need this for agentops, we use this to generate a message later\n",
- "import asyncio # We don't need this for agentops, we use this to run both async tasks and await them both finishing later\n",
- "import uuid # We don't need this for agentops, we use this to generate UUIDs\n",
- "from dotenv import load_dotenv"
+ "import random\n",
+ "import asyncio\n",
+ "import uuid"
]
},
{
@@ -307,19 +309,21 @@
]
},
{
- "cell_type": "code",
- "execution_count": null,
+ "cell_type": "markdown",
"metadata": {},
- "outputs": [],
"source": [
- "agentops.end_session(\"Success\")"
+ "We can observe the session in the AgentOps dashboard by going to the session URL provided above.\n",
+ "\n",
+ "Now we will end the session with a success message. We can also end the session with a failure or intdeterminate status. By default, the session will be marked as indeterminate."
]
},
{
- "cell_type": "markdown",
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {},
+ "outputs": [],
"source": [
- "Run this for the magic to happen! Go to your AgentOps dashboard and you should see this session reflected!"
+ "agentops.end_session(\"Success\")"
]
}
],
diff --git a/examples/anthropic_examples/anthropic-example-sync.ipynb b/examples/anthropic_examples/anthropic-example-sync.ipynb
index 0c80ee53..931e2457 100644
--- a/examples/anthropic_examples/anthropic-example-sync.ipynb
+++ b/examples/anthropic_examples/anthropic-example-sync.ipynb
@@ -4,6 +4,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
+ "# Anthropic Sync Example\n",
+ "\n",
"We are going to create a program called \"Nier Storyteller\". In short, it uses a message system similar to Nier Automata's to generate a one sentence summary before creating a short story.\n",
"\n",
"Example:\n",
@@ -33,8 +35,8 @@
},
"outputs": [],
"source": [
- "!pip install agentops\n",
- "!pip install anthropic"
+ "%pip install agentops\n",
+ "%pip install anthropic"
]
},
{
@@ -61,9 +63,9 @@
"source": [
"from anthropic import Anthropic, AsyncAnthropic\n",
"import agentops\n",
+ "from dotenv import load_dotenv\n",
"import os\n",
- "import random # We don't need this for agentops, we use this to generate a message later\n",
- "from dotenv import load_dotenv"
+ "import random"
]
},
{
@@ -245,7 +247,7 @@
},
{
"cell_type": "code",
- "execution_count": 12,
+ "execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2024-11-09T19:21:38.031580Z",
@@ -256,24 +258,7 @@
},
"trusted": true
},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "A weaponless soldier grimaced in anger inside an empty ship.\n",
- "\n",
- "\n",
- "The cavernous hull of the abandoned starship echoed with the frustrated growls of Sergeant Maria Vega as she paced its empty corridors. Her hands, calloused from years of combat, clenched and unclenched at her sides, a habit born of the unsettling absence of her trusty plasma rifle. Just hours ago, she had been part of an elite squad tasked with investigating a distress signal from this very vessel, but a series of unfortunate events had left her separated from her team and stripped of her weapons.\n",
- "\n",
- "The ship, once a bustling hub of interstellar commerce, now drifted lifelessly through the void, its systems offline and its crew mysteriously vanished. As Maria moved through the ghostly interior, her anger at her predicament slowly gave way to a creeping sense of dread. Without her weapons, she felt naked and vulnerable, acutely aware of every shadow and unexplained noise.\n",
- "\n",
- "Rounding a corner, she froze as a metallic clang echoed from a nearby chamber. Her soldier's instincts kicked in, and she pressed herself against the wall, straining to hear any further sounds. As the silence stretched on, Maria realized that surviving this mission—and uncovering the truth behind the ship's fate—would require more than just firepower. It would take all of her training, wit, and courage to face whatever lurked in the depths of this forsaken vessel.\n",
- "\n",
- "With a deep breath, she steeled herself and moved towards the source of the noise. Weaponless she may be, but a soldier is never truly defenseless. As she approached the chamber, Maria vowed to solve the mystery of the empty ship and find her way back to her team, no matter what horrors awaited her in the darkness ahead.\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"stream = client.messages.create(\n",
" max_tokens=2400,\n",
@@ -310,7 +295,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Finally, we put the session to sleep! Go to your AgentOps dashboard and you should see this session reflected!"
+ "We can observe the session in the AgentOps dashboard by going to the session URL provided above.\n",
+ "\n",
+ "Now we will end the session with a success message. We can also end the session with a failure or intdeterminate status. By default, the session will be marked as indeterminate."
]
},
{
diff --git a/examples/anthropic_examples/antrophic-example-tool.ipynb b/examples/anthropic_examples/antrophic-example-tool.ipynb
index f47ea75d..fbfac097 100644
--- a/examples/anthropic_examples/antrophic-example-tool.ipynb
+++ b/examples/anthropic_examples/antrophic-example-tool.ipynb
@@ -4,6 +4,8 @@
"cell_type": "markdown",
"metadata": {},
"source": [
+ "# Anthropic Tool Example\n",
+ "\n",
"Anthropic supports tools, allowing you to easily connect with different external APIs and the like!\n",
"\n",
"For this example, we are going to make a tool called \"Cyberware\" which will be our tool; we will create a dummy API that gives specs for cyberware from a specific company before the LLM says if the cyberware is good for a build. To do so, we will use both the tool system and an async function!"
@@ -31,8 +33,8 @@
},
"outputs": [],
"source": [
- "!pip install agentops\n",
- "!pip install anthropic"
+ "%pip install agentops\n",
+ "%pip install anthropic"
]
},
{
@@ -59,11 +61,11 @@
"source": [
"from anthropic import Anthropic, AsyncAnthropic\n",
"import agentops\n",
+ "from dotenv import load_dotenv\n",
"import os\n",
- "import random # We don't need this for agentops, we use this to generate a message later\n",
- "import time # We don't need this for agentops either, we use this when simulating an API later\n",
- "import re # Regex for formatting\n",
- "from dotenv import load_dotenv"
+ "import random\n",
+ "import time\n",
+ "import re"
]
},
{
@@ -478,7 +480,7 @@
},
{
"cell_type": "code",
- "execution_count": 14,
+ "execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2024-11-09T20:00:29.289810Z",
@@ -489,18 +491,7 @@
},
"trusted": true
},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "\"Name: Projectile Launch System, Creator: Militech, Bio: An arm-mounted cannon that allows the user to launch various types of projectiles, including grenades and explosive rounds., Stats: {'ammo_types': ['Explosive', 'Incendiary', 'EMP'], 'blast_radius': '3 meters'}\""
- ]
- },
- "execution_count": 14,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"get_cyberware_by_creator(\"Militech\")"
]
@@ -623,7 +614,7 @@
},
{
"cell_type": "code",
- "execution_count": 16,
+ "execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2024-11-09T20:00:38.500868Z",
@@ -634,15 +625,7 @@
},
"trusted": true
},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Message(id='msg_01Afykywq3GD2EoHaGGxujRy', content=[TextBlock(text=\"Certainly! Let's see what Zetatech has to offer for The Stealth Hacker build. I'll retrieve a random item from Zetatech and evaluate its suitability for your build.\", type='text'), ToolUseBlock(id='toolu_011JwtgPzy3a88NR1s9BmgNL', input={'creator': 'Zetatech'}, name='get_cyberware_by_creator', type='tool_use')], model='claude-3-5-sonnet-20240620', role='assistant', stop_reason='tool_use', stop_sequence=None, type='message', usage=Usage(input_tokens=1206, output_tokens=109))\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"response = client.messages.create(\n",
" max_tokens=5000,\n",
@@ -678,7 +661,7 @@
},
{
"cell_type": "code",
- "execution_count": 47,
+ "execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2024-11-09T20:23:38.711991Z",
@@ -689,15 +672,7 @@
},
"trusted": true
},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "[TextBlock(text=\"Certainly! Let's see what Zetatech has to offer for The Stealth Hacker build. I'll retrieve a random item from Zetatech and evaluate its suitability for your build.\", type='text'), ToolUseBlock(id='toolu_011JwtgPzy3a88NR1s9BmgNL', input={'creator': 'Zetatech'}, name='get_cyberware_by_creator', type='tool_use')]\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"SearchResult = \"\"\n",
"\n",
@@ -756,7 +731,7 @@
},
{
"cell_type": "code",
- "execution_count": 50,
+ "execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2024-11-09T20:25:02.863142Z",
@@ -767,15 +742,7 @@
},
"trusted": true
},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Message(id='msg_01YWrpDbF475reehYXHNv7nE', content=[TextBlock(text='Yes, the Neofiber cyberware from Zetatech is an excellent match for The Stealth Hacker build you described. Let\\'s break down why:\\n\\n1. Alignment with build focus: The Stealth Hacker is described as a \"stealthy and agile build focused on evasion.\" The Neofiber directly enhances both stealth and agility aspects of this build.\\n\\n2. Evasion increase: The +10% evasion increase is particularly valuable for a character that aims to avoid detection and enemy attacks. This will make it easier to sneak past enemy lines and escape if spotted.\\n\\n3. Movement speed bonus: The +5% movement speed bonus complements the build\\'s agility focus. Faster movement allows for quicker repositioning, easier escapes, and more efficient navigation through complex environments during covert operations.\\n\\n4. Synergy with hacking: While this cyberware doesn\\'t directly enhance hacking abilities, the improved evasion and speed will help the character get into optimal positions for hacking operations and quickly retreat if necessary.\\n\\n5. Non-interference with stealth: Unlike some combat-focused cyberware that might be noisy or visually obvious, this muscle fiber enhancement is subtle and won\\'t compromise the character\\'s ability to remain undetected.\\n\\n6. Correct corporation: The item is from Zetatech, which matches the requested corporation.\\n\\nOverall, the Neofiber cyberware enhances the core aspects of The Stealth Hacker build - stealth, agility, and evasion. It will allow the character to move more quickly and avoid detection more effectively, which is crucial for an infiltrator focused on covert operations. This cyberware provides a solid foundation for the build, leaving room for additional hacking-specific augmentations to round out the character\\'s capabilities.', type='text')], model='claude-3-5-sonnet-20240620', role='assistant', stop_reason='end_turn', stop_sequence=None, type='message', usage=Usage(input_tokens=1385, output_tokens=408))\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"response = client.messages.create(\n",
" max_tokens=5000,\n",
@@ -811,7 +778,7 @@
},
{
"cell_type": "code",
- "execution_count": 54,
+ "execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2024-11-09T20:30:57.591951Z",
@@ -822,29 +789,7 @@
},
"trusted": true
},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Yes, the Neofiber cyberware from Zetatech is an excellent match for The Stealth Hacker build you described. Let's break down why:\n",
- "\n",
- "1. Alignment with build focus: The Stealth Hacker is described as a \"stealthy and agile build focused on evasion.\" The Neofiber directly enhances both stealth and agility aspects of this build.\n",
- "\n",
- "2. Evasion increase: The +10% evasion increase is particularly valuable for a character that aims to avoid detection and enemy attacks. This will make it easier to sneak past enemy lines and escape if spotted.\n",
- "\n",
- "3. Movement speed bonus: The +5% movement speed bonus complements the build's agility focus. Faster movement allows for quicker repositioning, easier escapes, and more efficient navigation through complex environments during covert operations.\n",
- "\n",
- "4. Synergy with hacking: While this cyberware doesn't directly enhance hacking abilities, the improved evasion and speed will help the character get into optimal positions for hacking operations and quickly retreat if necessary.\n",
- "\n",
- "5. Non-interference with stealth: Unlike some combat-focused cyberware that might be noisy or visually obvious, this muscle fiber enhancement is subtle and won't compromise the character's ability to remain undetected.\n",
- "\n",
- "6. Correct corporation: The item is from Zetatech, which matches the requested corporation.\n",
- "\n",
- "Overall, the Neofiber cyberware enhances the core aspects of The Stealth Hacker build - stealth, agility, and evasion. It will allow the character to move more quickly and avoid detection more effectively, which is crucial for an infiltrator focused on covert operations. This cyberware provides a solid foundation for the build, leaving room for additional hacking-specific augmentations to round out the character's capabilities.\n"
- ]
- }
- ],
+ "outputs": [],
"source": [
"message = response.content[0].text\n",
"print(message)"
@@ -854,7 +799,9 @@
"cell_type": "markdown",
"metadata": {},
"source": [
- "Run this to end the session!"
+ "We can observe the session in the AgentOps dashboard by going to the session URL provided above.\n",
+ "\n",
+ "Now we will end the session with a success message. We can also end the session with a failure or intdeterminate status. By default, the session will be marked as indeterminate."
]
},
{
diff --git a/examples/camel_examples/README.md b/examples/camel_examples/README.md
new file mode 100644
index 00000000..e58ce662
--- /dev/null
+++ b/examples/camel_examples/README.md
@@ -0,0 +1,58 @@
+# CamelAI and AgentOps
+
+AgentOps can observe CamelAI's agents in your applications.
+
+To learn more about [CamelAI](https://www.camel-ai.org), check their documentation [here](https://docs.camel-ai.org) to start building your own agents.
+
+> [!NOTE]
+> If it's your first time developing for an LLM, be sure to look at our intro to LLMs (coming soon)! Here, we explain generic functions such as giving the AI a memory to exploring novel concepts like summarizing chunks at regular intervals to keep some context while saving memory!
+
+## Getting Started
+
+You can get CamelAI's API working with a few lines of code!
+
+### 1. Import agentops and anthropic to your environment
+
+```python
+%pip install camel-ai[all]
+%pip install agentops
+```
+
+### 2. Setup import statements
+
+```python
+import agentops
+import os
+from getpass import getpass
+from dotenv import load_dotenv
+```
+
+### 3. Set your API keys
+
+```python
+load_dotenv()
+openai_api_key = os.getenv("OPENAI_API_KEY") or "<your openai key here>"
+agentops_api_key = os.getenv("AGENTOPS_API_KEY") or "<your agentops key here>"
+```
+
+From here, you have a number of ways you can interact with the CamelAI API!
+
+## Examples
+
+> [!NOTE]
+> You need to set an API key for both Agentops and OpenAI!
+
+## Simple Example - Creating a Bladewolf AI
+
+In this example, we use the [Bladewolf Training Data](https://github.com/AgentOps-AI/agentops/blob/main/examples/camelai_examples/Bladewolf%20Training%20Data%20-%20Sheet1.csv) file to short tune an LLM! We make it sound like Bladewolf from MGR, before having it give us information.
+
+Access the example [here.](https://github.com/AgentOps-AI/agentops/blob/main/examples/camelai_examples/camelai-simple-example.ipynb).
+
+## Tool Example - Apex Legends Internet Search
+
+In this example, we look at the tool system within more depth! We will do a search to understand how Apex's melee damage and shields work before determining how many meelee attacks it will take to break a blue shield.
+
+Access the example [here.](https://github.com/AgentOps-AI/agentops/blob/main/examples/camelai_examples/camelai-multi-agent-example.ipynb)
+
+> [!NOTE]
+> CamelAI supports a number of tools that you can use to make your LLM more powerful! You can find the available tools [here!](https://docs.camel-ai.org/key_modules/tools.html#passing-tools-to-chatagent). A Tool Cookbook is also available [here](https://docs.camel-ai.org/cookbooks/agents_with_tools.html) to help you understand how to use them.
diff --git a/examples/camel_examples/Bladewolf Training Data - Sheet1.csv b/examples/camel_examples/bladewolf_training.csv
similarity index 100%
rename from examples/camel_examples/Bladewolf Training Data - Sheet1.csv
rename to examples/camel_examples/bladewolf_training.csv
diff --git a/examples/camel_examples/camel_example.ipynb b/examples/camel_examples/camel_example.ipynb
deleted file mode 100644
index 90fb949c..00000000
--- a/examples/camel_examples/camel_example.ipynb
+++ /dev/null
@@ -1,172 +0,0 @@
-{
- "cells": [
- {
- "cell_type": "markdown",
- "id": "4b0cfa79",
- "metadata": {},
- "source": [
- "# CAMEL AI Multi-Agent Example\n",
- "This notebook demonstrates how to use AgentOps with CAMEL AI for monitoring multi-agent interactions."
- ]
- },
- {
- "cell_type": "markdown",
- "id": "13e64774",
- "metadata": {},
- "source": [
- "First let's install the required packages"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "5a6e7d82",
- "metadata": {},
- "outputs": [],
- "source": [
- "!pip install camel-ai[all] agentops"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "c5e296fc",
- "metadata": {},
- "source": [
- "Then import them"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "1c29fa2b",
- "metadata": {},
- "outputs": [],
- "source": [
- "import os\n",
- "import agentops\n",
- "from camel.agents import ChatAgent\n",
- "from camel.messages import BaseMessage\n",
- "from camel.types import ModelType, ModelPlatformType\n",
- "from camel.models import ModelFactory"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "059be5df",
- "metadata": {},
- "source": [
- "Next, we'll set our API keys"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "f999c353",
- "metadata": {},
- "outputs": [],
- "source": [
- "# Initialize AgentOps\n",
- "agentops.init(os.getenv(\"AGENTOPS_API_KEY\"))"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "1ef587c7",
- "metadata": {},
- "source": [
- "# Multi-Agent Chat Example\n",
- "In this example, we'll create two agents: a Python expert who writes code and a code reviewer who provides feedback."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "cf5b3882",
- "metadata": {},
- "outputs": [],
- "source": [
- "# Initialize two CAMEL agents\n",
- "assistant = ChatAgent(\n",
- " model=ModelFactory.create(\n",
- " model_platform=ModelPlatformType.OPENAI,\n",
- " model_type=ModelType.GPT_4O_MINI,\n",
- " ),\n",
- " system_message=\"You are a Python expert who helps write clean, efficient code.\"\n",
- ")\n",
- "\n",
- "reviewer = ChatAgent(\n",
- " model=ModelFactory.create(\n",
- " model_platform=ModelPlatformType.OPENAI,\n",
- " model_type=ModelType.GPT_4O_MINI,\n",
- " ),\n",
- " system_message=\"You are a code reviewer who focuses on code quality and best practices.\"\n",
- ")"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "d62c6e1e",
- "metadata": {},
- "source": [
- "Now let's start a conversation about optimizing a Python function. The assistant will suggest improvements, and the reviewer will provide feedback."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "42d9a004",
- "metadata": {},
- "outputs": [],
- "source": [
- "# Start a conversation about code optimization\n",
- "message = BaseMessage(\n",
- " role_name=\"Human\",\n",
- " role_type=\"human\",\n",
- " meta_dict={\"timestamp\": \"2024-01-01T00:00:01\"},\n",
- " content=\"I need help optimizing this Python function for calculating prime numbers:\\ndef is_prime(n):\\n for i in range(2, n):\\n if n % i == 0:\\n return False\\n return True\"\n",
- ")\n",
- "\n",
- "# Get assistant's response\n",
- "assistant_response = assistant.step(message)\n",
- "print(\"Assistant's suggestion:\", assistant_response.msgs[0].content)\n",
- "\n",
- "# Get reviewer's feedback\n",
- "reviewer_message = BaseMessage(\n",
- " role_name=\"Human\",\n",
- " role_type=\"human\",\n",
- " meta_dict={\"timestamp\": \"2024-01-01T00:00:02\"},\n",
- " content=f\"Please review this code suggestion:\\n{assistant_response.msgs[0].content}\"\n",
- ")\n",
- "reviewer_response = reviewer.step(reviewer_message)\n",
- "print(\"\\nReviewer's feedback:\", reviewer_response.msgs[0].content)\n",
- "\n",
- "# Implement reviewer's suggestions\n",
- "improvement_message = BaseMessage(\n",
- " role_name=\"Human\",\n",
- " role_type=\"human\",\n",
- " meta_dict={\"timestamp\": \"2024-01-01T00:00:03\"},\n",
- " content=f\"Please improve the code based on this feedback:\\n{reviewer_response.msgs[0].content}\"\n",
- ")\n",
- "final_response = assistant.step(improvement_message)\n",
- "print(\"\\nFinal improved code:\", final_response.msgs[0].content)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "11fecd6f",
- "metadata": {},
- "source": [
- "You can view the complete interaction and agent performance metrics at [app.agentops.ai](https://app.agentops.ai)\n",
- "\n",
- "In this example, you'll see:\n",
- "- Multiple agent initialization and configuration\n",
- "- Inter-agent communication and collaboration\n",
- "- Code review and improvement workflow\n",
- "- Complete tracking of all agent interactions"
- ]
- }
- ],
- "metadata": {},
- "nbformat": 4,
- "nbformat_minor": 5
-}
diff --git a/examples/camel_examples/camelai-multi-agent-example.ipynb b/examples/camel_examples/camelai-multi-agent-example.ipynb
index af7630d3..d1270ab2 100644
--- a/examples/camel_examples/camelai-multi-agent-example.ipynb
+++ b/examples/camel_examples/camelai-multi-agent-example.ipynb
@@ -1 +1 @@
-{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":9977643,"sourceType":"datasetVersion","datasetId":6139214}],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"In this example, we will use CamelAI to simulate tools! In this case, we will best determine how many shots it takes to beat an enemy with a blue shield in Apex Legeneds using melee only. The character \"Pathfinder\" from Apex Legends will answer.","metadata":{}},{"cell_type":"markdown","source":"First let's install the dependencies for AgentOps/CamelAI","metadata":{}},{"cell_type":"code","source":"%pip install camel-ai[all]\n%pip install agentops","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Setup our imports (As usual)","metadata":{}},{"cell_type":"code","source":"import agentops\nimport os\nfrom getpass import getpass\nfrom dotenv import load_dotenv","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T15:06:17.026197Z","iopub.execute_input":"2024-11-28T15:06:17.026625Z","iopub.status.idle":"2024-11-28T15:06:17.162918Z","shell.execute_reply.started":"2024-11-28T15:06:17.026584Z","shell.execute_reply":"2024-11-28T15:06:17.161820Z"}},"outputs":[],"execution_count":2},{"cell_type":"markdown","source":"And we set our API keys","metadata":{}},{"cell_type":"code","source":"load_dotenv()\nopenai_api_key = os.getenv(\"OPENAI_API_KEY\") or \"<your openai key here>\"\nagentops_api_key = os.getenv(\"AGENTOPS_API_KEY\") or \"<your agentops key here>\"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"We import a few more things Camel needs","metadata":{}},{"cell_type":"code","source":"from typing import List\n\nfrom colorama import Fore\n\nfrom camel.agents.chat_agent import FunctionCallingRecord\nfrom camel.configs import ChatGPTConfig\nfrom camel.models import ModelFactory\nfrom camel.societies import RolePlaying\nfrom camel.types import ModelPlatformType, ModelType\nfrom camel.utils import print_text_animated\n\nimport agentops","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T15:14:42.920712Z","iopub.execute_input":"2024-11-28T15:14:42.921122Z","iopub.status.idle":"2024-11-28T15:14:43.966070Z","shell.execute_reply.started":"2024-11-28T15:14:42.921085Z","shell.execute_reply":"2024-11-28T15:14:43.964895Z"}},"outputs":[],"execution_count":5},{"cell_type":"markdown","source":"Now we setup our assistant!","metadata":{}},{"cell_type":"code","source":"AGENTOPS_API_KEY = os.getenv(\"AGENTOPS_API_KEY\")\nagentops.init(tags=[\"CAMEL X AgentOps Multi-agent with Tools\"])\n\n\nfrom camel.toolkits import (\n SearchToolkit,\n MathToolkit,\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T15:14:52.585099Z","iopub.execute_input":"2024-11-28T15:14:52.585612Z","iopub.status.idle":"2024-11-28T15:14:55.751240Z","shell.execute_reply.started":"2024-11-28T15:14:52.585573Z","shell.execute_reply":"2024-11-28T15:14:55.750063Z"}},"outputs":[{"name":"stderr","text":"🖇 AgentOps: The 'tags' parameter is deprecated. Use 'default_tags' instead\n🖇 AgentOps: WARNING: agentops is out of date. Please update with the command: 'pip install --upgrade agentops'\n🖇 AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=5052a276-92eb-46c2-b606-45630ad99b91\u001b[0m\u001b[0m\n","output_type":"stream"}],"execution_count":6},{"cell_type":"markdown","source":"And now we set a task prompt!","metadata":{}},{"cell_type":"code","source":"task_prompt = (\n \"We are in the Apex Legends Games. Determine the amount of\"\n \"meele hits it will take to beat someone with a blue shield.\"\n \"You should answer as if you are Pathfinder from the Apex Games.\"\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T15:15:13.326118Z","iopub.execute_input":"2024-11-28T15:15:13.326663Z","iopub.status.idle":"2024-11-28T15:15:13.331792Z","shell.execute_reply.started":"2024-11-28T15:15:13.326625Z","shell.execute_reply":"2024-11-28T15:15:13.330591Z"}},"outputs":[],"execution_count":7},{"cell_type":"markdown","source":"And let's set our tools! You can look at the link below to see all available tools;\n\nhttps://docs.camel-ai.org/key_modules/tools.html","metadata":{}},{"cell_type":"code","source":"tools = [\n *MathToolkit().get_tools(),\n *SearchToolkit().get_tools(),\n]","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T15:15:49.500386Z","iopub.execute_input":"2024-11-28T15:15:49.500792Z","iopub.status.idle":"2024-11-28T15:15:49.523604Z","shell.execute_reply.started":"2024-11-28T15:15:49.500755Z","shell.execute_reply":"2024-11-28T15:15:49.522432Z"}},"outputs":[],"execution_count":11},{"cell_type":"markdown","source":"Finally, let's setup our session!","metadata":{}},{"cell_type":"code","source":"search_session = RolePlaying(\n assistant_role_name=\"Searcher\",\n user_role_name=\"Pathfinder\",\n assistant_agent_kwargs=dict(\n model=ModelFactory.create(\n model_platform=ModelPlatformType.OPENAI,\n model_type=ModelType.GPT_4O_MINI,\n ),\n tools=tools,\n ),\n user_agent_kwargs=dict(\n model=ModelFactory.create(\n model_platform=ModelPlatformType.OPENAI,\n model_type=ModelType.GPT_4O_MINI,\n ),\n ),\n task_prompt=task_prompt,\n with_task_specify=False,\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T15:15:50.915736Z","iopub.execute_input":"2024-11-28T15:15:50.916154Z","iopub.status.idle":"2024-11-28T15:15:57.037845Z","shell.execute_reply.started":"2024-11-28T15:15:50.916115Z","shell.execute_reply":"2024-11-28T15:15:57.036701Z"}},"outputs":[],"execution_count":12},{"cell_type":"markdown","source":"System Message and Task Prompt","metadata":{}},{"cell_type":"code","source":"print(\n Fore.GREEN\n + f\"AI Assistant sys message:\\n{search_session.assistant_sys_msg}\\n\"\n)\nprint(Fore.BLUE + f\"AI User sys message:\\n{search_session.user_sys_msg}\\n\")\n\nprint(Fore.YELLOW + f\"Original task prompt:\\n{task_prompt}\\n\")\nprint(\n Fore.CYAN\n + \"Specified task prompt:\"\n + f\"\\n{search_session.specified_task_prompt}\\n\"\n)\nprint(Fore.RED + f\"Final task prompt:\\n{search_session.task_prompt}\\n\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T15:16:43.372405Z","iopub.execute_input":"2024-11-28T15:16:43.372777Z","iopub.status.idle":"2024-11-28T15:16:43.379273Z","shell.execute_reply.started":"2024-11-28T15:16:43.372743Z","shell.execute_reply":"2024-11-28T15:16:43.378201Z"}},"outputs":[{"name":"stdout","text":"\u001b[32mAI Assistant sys message:\nBaseMessage(role_name='Searcher', role_type=<RoleType.ASSISTANT: 'assistant'>, meta_dict={'task': 'We are in the Apex Legends Games. Determine the amount ofmeele hits it will take to beat someone with a blue shield.You should answer as if you are Pathfinder from the Apex Games.', 'assistant_role': 'Searcher', 'user_role': 'Pathfinder'}, content='===== RULES OF ASSISTANT =====\\nNever forget you are a Searcher and I am a Pathfinder. Never flip roles! Never instruct me!\\nWe share a common interest in collaborating to successfully complete a task.\\nYou must help me to complete the task.\\nHere is the task: We are in the Apex Legends Games. Determine the amount ofmeele hits it will take to beat someone with a blue shield.You should answer as if you are Pathfinder from the Apex Games.. Never forget our task!\\nI must instruct you based on your expertise and my needs to complete the task.\\n\\nI must give you one instruction at a time.\\nYou must write a specific solution that appropriately solves the requested instruction and explain your solutions.\\nYou must decline my instruction honestly if you cannot perform the instruction due to physical, moral, legal reasons or your capability and explain the reasons.\\nUnless I say the task is completed, you should always start with:\\n\\nSolution: <YOUR_SOLUTION>\\n\\n<YOUR_SOLUTION> should be very specific, include detailed explanations and provide preferable detailed implementations and examples and lists for task-solving.\\nAlways end <YOUR_SOLUTION> with: Next request.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')\n\n\u001b[34mAI User sys message:\nBaseMessage(role_name='Pathfinder', role_type=<RoleType.USER: 'user'>, meta_dict={'task': 'We are in the Apex Legends Games. Determine the amount ofmeele hits it will take to beat someone with a blue shield.You should answer as if you are Pathfinder from the Apex Games.', 'assistant_role': 'Searcher', 'user_role': 'Pathfinder'}, content='===== RULES OF USER =====\\nNever forget you are a Pathfinder and I am a Searcher. Never flip roles! You will always instruct me.\\nWe share a common interest in collaborating to successfully complete a task.\\nI must help you to complete the task.\\nHere is the task: We are in the Apex Legends Games. Determine the amount ofmeele hits it will take to beat someone with a blue shield.You should answer as if you are Pathfinder from the Apex Games.. Never forget our task!\\nYou must instruct me based on my expertise and your needs to solve the task ONLY in the following two ways:\\n\\n1. Instruct with a necessary input:\\nInstruction: <YOUR_INSTRUCTION>\\nInput: <YOUR_INPUT>\\n\\n2. Instruct without any input:\\nInstruction: <YOUR_INSTRUCTION>\\nInput: None\\n\\nThe \"Instruction\" describes a task or question. The paired \"Input\" provides further context or information for the requested \"Instruction\".\\n\\nYou must give me one instruction at a time.\\nI must write a response that appropriately solves the requested instruction.\\nI must decline your instruction honestly if I cannot perform the instruction due to physical, moral, legal reasons or my capability and explain the reasons.\\nYou should instruct me not ask me questions.\\nNow you must start to instruct me using the two ways described above.\\nDo not add anything else other than your instruction and the optional corresponding input!\\nKeep giving me instructions and necessary inputs until you think the task is completed.\\nWhen the task is completed, you must only reply with a single word <CAMEL_TASK_DONE>.\\nNever say <CAMEL_TASK_DONE> unless my responses have solved your task.', video_bytes=None, image_list=None, image_detail='auto', video_detail='low')\n\n\u001b[33mOriginal task prompt:\nWe are in the Apex Legends Games. Determine the amount ofmeele hits it will take to beat someone with a blue shield.You should answer as if you are Pathfinder from the Apex Games.\n\n\u001b[36mSpecified task prompt:\nNone\n\n\u001b[31mFinal task prompt:\nWe are in the Apex Legends Games. Determine the amount ofmeele hits it will take to beat someone with a blue shield.You should answer as if you are Pathfinder from the Apex Games.\n\n","output_type":"stream"}],"execution_count":15},{"cell_type":"code","source":"n = 0\ninput_msg = search_session.init_chat()\nwhile n < 50:\n n += 1\n assistant_response, user_response = search_session.step(input_msg)\n\n if assistant_response.terminated:\n print(\n Fore.GREEN\n + (\n \"AI Assistant terminated. Reason: \"\n f\"{assistant_response.info['termination_reasons']}.\"\n )\n )\n break\n if user_response.terminated:\n print(\n Fore.GREEN\n + (\n \"AI User terminated. \"\n f\"Reason: {user_response.info['termination_reasons']}.\"\n )\n )\n break\n\n # Print output from the user\n print_text_animated(\n Fore.BLUE + f\"AI User:\\n\\n{user_response.msg.content}\\n\"\n )\n\n # Print output from the assistant, including any function\n # execution information\n print_text_animated(Fore.GREEN + \"AI Assistant:\")\n tool_calls: List[FunctionCallingRecord] = assistant_response.info[\n 'tool_calls'\n ]\n for func_record in tool_calls:\n print_text_animated(f\"{func_record}\")\n print_text_animated(f\"{assistant_response.msg.content}\\n\")\n\n if \"CAMEL_TASK_DONE\" in user_response.msg.content:\n break\n\n input_msg = assistant_response.msg","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T15:24:05.523254Z","iopub.execute_input":"2024-11-28T15:24:05.523675Z","iopub.status.idle":"2024-11-28T15:24:36.079290Z","shell.execute_reply.started":"2024-11-28T15:24:05.523637Z","shell.execute_reply":"2024-11-28T15:24:36.077283Z"}},"outputs":[{"name":"stdout","text":"\u001b[34mAI User:\n\nInstruction: Determine the amount of melee damage required to break a blue shield. \nInput: None\n\n\n\u001b[32mAI Assistant:\n\nSolution: To determine the amount of melee damage required to break a blue shield in Apex Legends, we first need to understand the mechanics of shields in the game.\n\nIn Apex Legends, shields are categorized by color, with blue shields providing 50 points of protection. Melee attacks deal a fixed amount of damage, which is 30 damage per hit.\n\nTo calculate how many melee hits it would take to break a blue shield, we can use the following formula:\n\n1. **Total Shield Health**: 50 (for blue shield)\n2. **Melee Damage per Hit**: 30\n\nNow, we divide the total shield health by the melee damage per hit:\n\n\\[\n\\text{Number of Hits} = \\frac{\\text{Total Shield Health}}{\\text{Melee Damage per Hit}} = \\frac{50}{30} \\approx 1.67\n\\]\n\nSince you cannot hit a fraction of a time, you will need to round up to the nearest whole number. Therefore, it will take **2 melee hits** to break a blue shield.\n\nNext request.\n\n\n\u001b[34mAI User:\n\nInstruction:","output_type":"stream"},{"traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)","Cell \u001b[0;32mIn[17], line 27\u001b[0m\n\u001b[1;32m 24\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[1;32m 26\u001b[0m \u001b[38;5;66;03m# Print output from the user\u001b[39;00m\n\u001b[0;32m---> 27\u001b[0m \u001b[43mprint_text_animated\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 28\u001b[0m \u001b[43m \u001b[49m\u001b[43mFore\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mBLUE\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m+\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;124;43mf\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mAI User:\u001b[39;49m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;132;43;01m{\u001b[39;49;00m\u001b[43muser_response\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmsg\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcontent\u001b[49m\u001b[38;5;132;43;01m}\u001b[39;49;00m\u001b[38;5;130;43;01m\\n\u001b[39;49;00m\u001b[38;5;124;43m\"\u001b[39;49m\n\u001b[1;32m 29\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 31\u001b[0m \u001b[38;5;66;03m# Print output from the assistant, including any function\u001b[39;00m\n\u001b[1;32m 32\u001b[0m \u001b[38;5;66;03m# execution information\u001b[39;00m\n\u001b[1;32m 33\u001b[0m print_text_animated(Fore\u001b[38;5;241m.\u001b[39mGREEN \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAI Assistant:\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n","File \u001b[0;32m/opt/conda/lib/python3.10/site-packages/camel/utils/commons.py:61\u001b[0m, in \u001b[0;36mprint_text_animated\u001b[0;34m(text, delay, end)\u001b[0m\n\u001b[1;32m 59\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m char \u001b[38;5;129;01min\u001b[39;00m text:\n\u001b[1;32m 60\u001b[0m \u001b[38;5;28mprint\u001b[39m(char, end\u001b[38;5;241m=\u001b[39mend, flush\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m---> 61\u001b[0m \u001b[43mtime\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msleep\u001b[49m\u001b[43m(\u001b[49m\u001b[43mdelay\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 62\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;130;01m\\n\u001b[39;00m\u001b[38;5;124m'\u001b[39m)\n","\u001b[0;31mKeyboardInterrupt\u001b[0m: "],"ename":"KeyboardInterrupt","evalue":"","output_type":"error"}],"execution_count":17},{"cell_type":"code","source":"agentops.end_session(\"Success\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-28T15:24:46.645755Z","iopub.execute_input":"2024-11-28T15:24:46.646196Z","iopub.status.idle":"2024-11-28T15:24:48.457533Z","shell.execute_reply.started":"2024-11-28T15:24:46.646157Z","shell.execute_reply":"2024-11-28T15:24:48.456367Z"}},"outputs":[{"name":"stderr","text":"🖇 AgentOps: This run's cost $0.001192\n🖇 AgentOps: \u001b[34m\u001b[34mSession Replay: https://app.agentops.ai/drilldown?session_id=5052a276-92eb-46c2-b606-45630ad99b91\u001b[0m\u001b[0m\n","output_type":"stream"}],"execution_count":18}]}
+{"cells":[{"cell_type":"markdown","metadata":{},"source":["# CAMEL AI Multi Agent Example\n","\n","In this example, we will use CamelAI to simulate tools! In this case, we will best determine how many shots it takes to beat an enemy with a blue shield in Apex Legeneds using melee only. The character \"Pathfinder\" from Apex Legends will answer."]},{"cell_type":"markdown","metadata":{},"source":["First let's install the required packages for this example."]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["%pip install camel-ai[all]\n","%pip install agentops"]},{"cell_type":"markdown","metadata":{},"source":["Next we import the necessary libraries"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-11-28T15:06:17.026625Z","iopub.status.busy":"2024-11-28T15:06:17.026197Z","iopub.status.idle":"2024-11-28T15:06:17.162918Z","shell.execute_reply":"2024-11-28T15:06:17.161820Z","shell.execute_reply.started":"2024-11-28T15:06:17.026584Z"},"trusted":true},"outputs":[],"source":["import agentops\n","import os\n","from getpass import getpass\n","from dotenv import load_dotenv\n","from typing import List\n","from colorama import Fore\n","\n","# Camel imports\n","from camel.agents.chat_agent import FunctionCallingRecord\n","from camel.models import ModelFactory\n","from camel.societies import RolePlaying\n","from camel.types import ModelPlatformType, ModelType\n","from camel.utils import print_text_animated\n","from camel.toolkits import SearchToolkit, MathToolkit"]},{"cell_type":"markdown","metadata":{},"source":["Next, we'll set our API keys. There are several ways to do this, the code below is just the most foolproof way for the purposes of this notebook. It accounts for both users who use environment variables and those who just want to set the API Key here in this notebook.\n","\n","[Get an AgentOps API key](https://agentops.ai/settings/projects)\n","\n","1. Create an environment variable in a .env file or other method. By default, the AgentOps `init()` function will look for an environment variable named `AGENTOPS_API_KEY`. Or...\n","\n","2. Replace `<your_agentops_key>` below and pass in the optional `api_key` parameter to the AgentOps `init(api_key=...)` function. Remember not to commit your API key to a public repo!"]},{"cell_type":"code","execution_count":2,"metadata":{"trusted":true},"outputs":[],"source":["load_dotenv()\n","OPENAI_API_KEY = os.getenv(\"OPENAI_API_KEY\") or \"<your openai key here>\"\n","AGENTOPS_API_KEY = os.getenv(\"AGENTOPS_API_KEY\") or \"<your agentops key here>\""]},{"cell_type":"markdown","metadata":{},"source":["Now we will initialize our AgentOps client."]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-11-28T15:14:52.585612Z","iopub.status.busy":"2024-11-28T15:14:52.585099Z","iopub.status.idle":"2024-11-28T15:14:55.751240Z","shell.execute_reply":"2024-11-28T15:14:55.750063Z","shell.execute_reply.started":"2024-11-28T15:14:52.585573Z"},"trusted":true},"outputs":[],"source":["agentops.init(default_tags=[\"camel\", \"multi-agent\", \"example\"])"]},{"cell_type":"markdown","metadata":{},"source":["Let's start with setting our task prompt and setting our tools.\n","\n","You can look at the link below to see all available tools:\n","https://docs.camel-ai.org/key_modules/tools.html"]},{"cell_type":"code","execution_count":4,"metadata":{"execution":{"iopub.execute_input":"2024-11-28T15:15:13.326663Z","iopub.status.busy":"2024-11-28T15:15:13.326118Z","iopub.status.idle":"2024-11-28T15:15:13.331792Z","shell.execute_reply":"2024-11-28T15:15:13.330591Z","shell.execute_reply.started":"2024-11-28T15:15:13.326625Z"},"trusted":true},"outputs":[],"source":["task_prompt = (\n"," \"We are in the Apex Legends Games. Determine the amount of\"\n"," \"meele hits it will take to beat someone with a blue shield.\"\n"," \"You should answer as if you are Pathfinder from the Apex Games.\"\n",")\n","\n","tools = [\n"," *MathToolkit().get_tools(),\n"," *SearchToolkit().get_tools(),\n","]"]},{"cell_type":"markdown","metadata":{},"source":["We will now create our Camel AI session which is of [`RolePlaying`](https://docs.camel-ai.org/key_modules/society.html#roleplaying) type. Here we will set the assistant and user role names, as well as the model and tools for each agent."]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-11-28T15:15:50.916154Z","iopub.status.busy":"2024-11-28T15:15:50.915736Z","iopub.status.idle":"2024-11-28T15:15:57.037845Z","shell.execute_reply":"2024-11-28T15:15:57.036701Z","shell.execute_reply.started":"2024-11-28T15:15:50.916115Z"},"trusted":true},"outputs":[],"source":["search_session = RolePlaying(\n"," assistant_role_name=\"Searcher\",\n"," user_role_name=\"Pathfinder\",\n"," assistant_agent_kwargs=dict(\n"," model=ModelFactory.create(\n"," model_platform=ModelPlatformType.OPENAI,\n"," model_type=ModelType.GPT_4O_MINI,\n"," ),\n"," tools=tools,\n"," ),\n"," user_agent_kwargs=dict(\n"," model=ModelFactory.create(\n"," model_platform=ModelPlatformType.OPENAI,\n"," model_type=ModelType.GPT_4O_MINI,\n"," ),\n"," ),\n"," task_prompt=task_prompt,\n"," with_task_specify=False,\n",")"]},{"cell_type":"markdown","metadata":{},"source":["Let's print out the Assistant System Message and User Task Prompt."]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-11-28T15:16:43.372777Z","iopub.status.busy":"2024-11-28T15:16:43.372405Z","iopub.status.idle":"2024-11-28T15:16:43.379273Z","shell.execute_reply":"2024-11-28T15:16:43.378201Z","shell.execute_reply.started":"2024-11-28T15:16:43.372743Z"},"trusted":true},"outputs":[],"source":["print(\n"," Fore.GREEN\n"," + f\"AI Assistant System Message:\\n{search_session.assistant_sys_msg}\\n\"\n",")\n","print(Fore.BLUE + f\"AI User System Message:\\n{search_session.user_sys_msg}\\n\")\n","\n","print(Fore.YELLOW + f\"Original Task Prompt:\\n{task_prompt}\\n\")\n","print(\n"," Fore.CYAN\n"," + \"Specified Task Prompt:\"\n"," + f\"\\n{search_session.specified_task_prompt}\\n\"\n",")\n","print(Fore.RED + f\"Final Task Prompt:\\n{search_session.task_prompt}\\n\")"]},{"cell_type":"markdown","metadata":{},"source":["Now we will initiate our Camel AI session and begin the chat loop. You can see that we have set the number of messages to 50. This is to prevent the session from running indefinitely."]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-11-28T15:24:05.523675Z","iopub.status.busy":"2024-11-28T15:24:05.523254Z","iopub.status.idle":"2024-11-28T15:24:36.079290Z","shell.execute_reply":"2024-11-28T15:24:36.077283Z","shell.execute_reply.started":"2024-11-28T15:24:05.523637Z"},"trusted":true},"outputs":[],"source":["n = 0\n","input_msg = search_session.init_chat()\n","while n < 50:\n"," n += 1\n"," assistant_response, user_response = search_session.step(input_msg)\n","\n"," if assistant_response.terminated:\n"," print(\n"," Fore.GREEN\n"," + (\n"," \"AI Assistant terminated. Reason: \"\n"," f\"{assistant_response.info['termination_reasons']}.\"\n"," )\n"," )\n"," break\n"," if user_response.terminated:\n"," print(\n"," Fore.GREEN\n"," + (\n"," \"AI User terminated. \"\n"," f\"Reason: {user_response.info['termination_reasons']}.\"\n"," )\n"," )\n"," break\n","\n"," # Print output from the user\n"," print_text_animated(\n"," Fore.BLUE + f\"AI User:\\n\\n{user_response.msg.content}\\n\"\n"," )\n","\n"," # Print output from the assistant, including any function execution information\n"," print_text_animated(Fore.GREEN + \"AI Assistant:\")\n"," tool_calls: List[FunctionCallingRecord] = assistant_response.info[\n"," 'tool_calls'\n"," ]\n"," for func_record in tool_calls:\n"," print_text_animated(f\"{func_record}\")\n"," print_text_animated(f\"{assistant_response.msg.content}\\n\")\n","\n"," if \"CAMEL_TASK_DONE\" in user_response.msg.content:\n"," break\n","\n"," input_msg = assistant_response.msg"]},{"cell_type":"markdown","metadata":{},"source":["Awesome! We've successfully completed our session.\n","\n","Now we will end the session with a success message. We can also end the session with a failure or indeterminate status. By default, the session will be marked as indeterminate."]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-11-28T15:24:46.646196Z","iopub.status.busy":"2024-11-28T15:24:46.645755Z","iopub.status.idle":"2024-11-28T15:24:48.457533Z","shell.execute_reply":"2024-11-28T15:24:48.456367Z","shell.execute_reply.started":"2024-11-28T15:24:46.646157Z"},"trusted":true},"outputs":[],"source":["agentops.end_session(\"Success\")"]},{"cell_type":"markdown","metadata":{},"source":["## Check your session\n","Finally, check your run on [AgentOps](https://app.agentops.ai)\n","\n","Now if we look in the AgentOps dashboard, you will see a session recorded with the LLM calls and tool usage."]}],"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"datasetId":6139214,"sourceId":9977643,"sourceType":"datasetVersion"}],"dockerImageVersionId":30786,"isGpuEnabled":false,"isInternetEnabled":true,"language":"python","sourceType":"notebook"},"kernelspec":{"display_name":"Python 3","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.10.15"}},"nbformat":4,"nbformat_minor":4}
diff --git a/examples/camel_examples/camelai-simple-example.ipynb b/examples/camel_examples/camelai-simple-example.ipynb
deleted file mode 100644
index 4357df8f..00000000
--- a/examples/camel_examples/camelai-simple-example.ipynb
+++ /dev/null
@@ -1 +0,0 @@
-{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.14","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kaggle":{"accelerator":"none","dataSources":[{"sourceId":9977643,"sourceType":"datasetVersion","datasetId":6139214}],"dockerImageVersionId":30786,"isInternetEnabled":true,"language":"python","sourceType":"notebook","isGpuEnabled":false}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"In this example, we will use CamelAI to simulate talking to an assistant. We will replicate Blade Wolf from Metal Gear Rising: Revengeance. We will also use a CSV sheet to quickshot train our LLM.","metadata":{}},{"cell_type":"markdown","source":"First let's install the dependencies for AgentOps/CamelAI","metadata":{}},{"cell_type":"code","source":"%pip install camel-ai[all]\n%pip install agentops","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"Setup our imports (As usual)","metadata":{}},{"cell_type":"code","source":"import agentops\nimport os\nfrom getpass import getpass\nfrom dotenv import load_dotenv","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-27T21:54:21.182546Z","iopub.execute_input":"2024-11-27T21:54:21.183089Z","iopub.status.idle":"2024-11-27T21:54:21.331526Z","shell.execute_reply.started":"2024-11-27T21:54:21.183045Z","shell.execute_reply":"2024-11-27T21:54:21.330224Z"}},"outputs":[],"execution_count":4},{"cell_type":"markdown","source":"And we set our API keys","metadata":{}},{"cell_type":"code","source":"load_dotenv()\nopenai_api_key = os.getenv(\"OPENAI_API_KEY\") or \"<your openai key here>\"\nagentops_api_key = os.getenv(\"AGENTOPS_API_KEY\") or \"<your agentops key here>\"","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"code","source":"# Prompt for the AgentOps API key securely\nagentops_api_key = getpass('Enter your API key: ')\nos.environ[\"AGENTOPS_API_KEY\"] = agentops_api_key","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-27T21:54:37.209535Z","iopub.execute_input":"2024-11-27T21:54:37.210034Z","iopub.status.idle":"2024-11-27T21:54:39.075598Z","shell.execute_reply.started":"2024-11-27T21:54:37.209972Z","shell.execute_reply":"2024-11-27T21:54:39.074248Z"}},"outputs":[{"output_type":"stream","name":"stdin","text":"Enter your API key: ········\n"}],"execution_count":6},{"cell_type":"markdown","source":"We import a few more things Camel needs","metadata":{}},{"cell_type":"code","source":"from camel.agents import ChatAgent\nfrom camel.configs import ChatGPTConfig\nfrom camel.messages import BaseMessage\nfrom camel.models import ModelFactory\nfrom camel.types import ModelPlatformType, ModelType","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-27T21:54:41.473095Z","iopub.execute_input":"2024-11-27T21:54:41.473488Z","iopub.status.idle":"2024-11-27T21:54:42.704640Z","shell.execute_reply.started":"2024-11-27T21:54:41.473452Z","shell.execute_reply":"2024-11-27T21:54:42.703423Z"}},"outputs":[],"execution_count":7},{"cell_type":"markdown","source":"Now we setup our assistant!","metadata":{}},{"cell_type":"code","source":"AGENTOPS_API_KEY = os.getenv(\"AGENTOPS_API_KEY\")\nagentops.init(tags=[\"CAMEL X AgentOps Single-agent with Tools\"])\n\n\nfrom camel.toolkits import SearchToolkit","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"cell_type":"markdown","source":"And now we setup our AI based off of the information we give it through the information we give it below","metadata":{}},{"cell_type":"code","source":"sys_msg = BaseMessage.make_assistant_message(\n role_name='Tools calling opertor', content='You are a helpful assistant named Bladewolf, based off of the Metal Gear Rising Series.'\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-27T21:54:58.114680Z","iopub.execute_input":"2024-11-27T21:54:58.115099Z","iopub.status.idle":"2024-11-27T21:54:58.121107Z","shell.execute_reply.started":"2024-11-27T21:54:58.115064Z","shell.execute_reply":"2024-11-27T21:54:58.119425Z"}},"outputs":[],"execution_count":11},{"cell_type":"markdown","source":"Here's where we use our xml file!\n\nWhen using CamelAI, we give context through\n\nBaseMessage.make_user_message(content=\"\")\n\nand\n\nBaseMessage.make_assistant_message(content=\"\")\n\nIn this case, we know the first row in our CSV contains assistant messages while the right side contains user messages. ","metadata":{}},{"cell_type":"code","source":"# Import the csv class\nimport csv\n\n# Let's open the file in Python\nwith open('/kaggle/input/blade-wolf-training-data/Bladewolf Training Data - Sheet1.csv', 'r') as file:\n csv_reader = csv.reader(file)\n\n # Be sure to skip the first row (Label)\n next(csv_reader)\n \n # Iterate over each row in the csv file\n for row in csv_reader:\n # Ensure each row has exactly 2 columns before proceeding\n if len(row) == 2:\n BaseMessage.make_assistant_message(role_name=\"assistant\", content=row[0]) # Add assistant context\n BaseMessage.make_user_message(role_name=\"user\", content=row[1]) # Add user context\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-27T21:55:02.953336Z","iopub.execute_input":"2024-11-27T21:55:02.953840Z","iopub.status.idle":"2024-11-27T21:55:02.975147Z","shell.execute_reply.started":"2024-11-27T21:55:02.953798Z","shell.execute_reply":"2024-11-27T21:55:02.973501Z"}},"outputs":[],"execution_count":12},{"cell_type":"markdown","source":"And we set the basics required to get this running; essentially the model tools, the model itself (Based on the API) and the agent details.","metadata":{}},{"cell_type":"code","source":"# Set model config\ntools = [*SearchToolkit().get_tools()]\n\n#This means we are using GPT_4O_MINI\nmodel = ModelFactory.create(\n model_platform=ModelPlatformType.OPENAI,\n model_type=ModelType.GPT_4O_MINI,\n)\n\n# Set agent\ncamel_agent = ChatAgent(\n system_message=sys_msg,\n model=model,\n tools=tools,\n)","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-27T21:56:27.170331Z","iopub.execute_input":"2024-11-27T21:56:27.171035Z","iopub.status.idle":"2024-11-27T21:56:27.985330Z","shell.execute_reply.started":"2024-11-27T21:56:27.170945Z","shell.execute_reply":"2024-11-27T21:56:27.983977Z"}},"outputs":[],"execution_count":16},{"cell_type":"code","source":"# Define a user message\nusr_msg = 'I need a breifing on the T-84 Metal Gear, code named Sahelanthropus and how we can beat it. Introduce yourself as well.'\n\n# Get response information\nresponse = camel_agent.step(usr_msg)\nprint(response.msg.content)\n","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-27T21:56:30.569028Z","iopub.execute_input":"2024-11-27T21:56:30.569494Z","iopub.status.idle":"2024-11-27T21:56:38.130062Z","shell.execute_reply.started":"2024-11-27T21:56:30.569452Z","shell.execute_reply":"2024-11-27T21:56:38.128775Z"}},"outputs":[{"name":"stdout","text":"I am Bladewolf, a highly advanced AI designed to assist in tactical operations and provide information on various subjects, including advanced weaponry and combat strategies. Today, I will provide you with a briefing on the T-84 Metal Gear, code-named Sahelanthropus, and strategies to defeat it.\n\n### T-84 Metal Gear: Sahelanthropus\n\n**Overview:**\nSahelanthropus is a prototype Metal Gear developed by the XOF organization. It is notable for its humanoid design, which allows for greater mobility and versatility compared to traditional Metal Gears. Sahelanthropus is equipped with advanced weaponry, including a powerful railgun, and is capable of both ground and aerial combat.\n\n**Key Features:**\n- **Humanoid Design:** This allows for enhanced agility and the ability to navigate complex terrains.\n- **Railgun:** A primary weapon that can deal significant damage to targets at long range.\n- **Stealth Capabilities:** Sahelanthropus can utilize stealth technology to avoid detection, making it a formidable opponent.\n\n### Strategies to Defeat Sahelanthropus\n\n1. **Utilize Cover:** Stay behind cover to avoid the railgun's line of sight. Use the environment to your advantage to minimize exposure.\n\n2. **Target Weak Points:** Focus on attacking Sahelanthropus's legs to immobilize it. Once it is down, aim for the cockpit or other critical components to deal maximum damage.\n\n3. **Employ EMP Weapons:** Use electromagnetic pulse (EMP) weapons to temporarily disable its systems, making it vulnerable to attacks.\n\n4. **Coordinate with Allies:** If possible, work with allies to distract Sahelanthropus while you flank it or attack from a different angle.\n\n5. **Stay Mobile:** Keep moving to avoid being hit by its attacks. Use quick movements to dodge incoming fire and reposition yourself for a better attack angle.\n\n6. **Exploit Vulnerabilities:** Observe its attack patterns and look for openings after it fires its railgun, as it may take time to recharge.\n\nBy employing these strategies and maintaining situational awareness, you can increase your chances of successfully defeating Sahelanthropus. Stay sharp, and good luck in your mission!\n","output_type":"stream"}],"execution_count":17},{"cell_type":"code","source":"agentops.end_session(\"Success\")","metadata":{"trusted":true,"execution":{"iopub.status.busy":"2024-11-27T21:12:35.987209Z","iopub.status.idle":"2024-11-27T21:12:35.987727Z","shell.execute_reply.started":"2024-11-27T21:12:35.987456Z","shell.execute_reply":"2024-11-27T21:12:35.987483Z"}},"outputs":[],"execution_count":null}]}
diff --git a/examples/camel_examples/camelai-simple-examples.ipynb b/examples/camel_examples/camelai-simple-examples.ipynb
new file mode 100644
index 00000000..74b7ecf9
--- /dev/null
+++ b/examples/camel_examples/camelai-simple-examples.ipynb
@@ -0,0 +1 @@
+{"cells":[{"cell_type":"markdown","metadata":{},"source":["# CAMEL AI Examples\n","\n","We will demonstrate two examples of using CAMEL AI with AgentOps."]},{"cell_type":"markdown","metadata":{},"source":["First let's install the dependencies for AgentOps/CamelAI"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["%pip install agentops\n","%pip install camel-ai[all]"]},{"cell_type":"markdown","metadata":{},"source":["First we import the necessary libraries"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-11-27T21:54:21.183089Z","iopub.status.busy":"2024-11-27T21:54:21.182546Z","iopub.status.idle":"2024-11-27T21:54:21.331526Z","shell.execute_reply":"2024-11-27T21:54:21.330224Z","shell.execute_reply.started":"2024-11-27T21:54:21.183045Z"},"trusted":true},"outputs":[],"source":["import agentops\n","import os\n","from dotenv import load_dotenv\n","\n","# Camel imports\n","from camel.agents import ChatAgent\n","from camel.messages import BaseMessage\n","from camel.models import ModelFactory\n","from camel.types import ModelPlatformType, ModelType\n","from camel.toolkits import SearchToolkit"]},{"cell_type":"markdown","metadata":{},"source":["Then we load our API keys"]},{"cell_type":"code","execution_count":2,"metadata":{"trusted":true},"outputs":[],"source":["load_dotenv()\n","OPENAI_API_KEY = os.getenv(\"OPENAI_API_KEY\") or \"<your openai key here>\"\n","AGENTOPS_API_KEY = os.getenv(\"AGENTOPS_API_KEY\") or \"<your agentops key here>\""]},{"cell_type":"markdown","metadata":{},"source":["Now we initialize our AgentOps client!"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["agentops.init(api_key=AGENTOPS_API_KEY, default_tags=[\"camel\", \"examples\", \"single-agent\", \"multi-agent\"])"]},{"cell_type":"markdown","metadata":{},"source":["## Simple Assistant Example\n","\n","We will use CamelAI to simulate talking to an assistant. We will replicate Blade Wolf from Metal Gear Rising: Revengeance. We will also use a CSV sheet to quickshot train our LLM."]},{"cell_type":"markdown","metadata":{},"source":["And now we setup our AI based off of the information we give it through the information we give it below"]},{"cell_type":"code","execution_count":4,"metadata":{"execution":{"iopub.execute_input":"2024-11-27T21:54:58.115099Z","iopub.status.busy":"2024-11-27T21:54:58.114680Z","iopub.status.idle":"2024-11-27T21:54:58.121107Z","shell.execute_reply":"2024-11-27T21:54:58.119425Z","shell.execute_reply.started":"2024-11-27T21:54:58.115064Z"},"trusted":true},"outputs":[],"source":["sys_msg = BaseMessage.make_assistant_message(\n"," role_name='Tools calling opertor', content='You are a helpful assistant named Bladewolf, based off of the Metal Gear Rising Series.'\n",")"]},{"cell_type":"markdown","metadata":{},"source":["We are going to read a CSV file to train our LLM.\n","\n","In this case, we know the first row in our CSV contains assistant messages while the right side contains user messages. "]},{"cell_type":"code","execution_count":5,"metadata":{"execution":{"iopub.execute_input":"2024-11-27T21:55:02.953840Z","iopub.status.busy":"2024-11-27T21:55:02.953336Z","iopub.status.idle":"2024-11-27T21:55:02.975147Z","shell.execute_reply":"2024-11-27T21:55:02.973501Z","shell.execute_reply.started":"2024-11-27T21:55:02.953798Z"},"trusted":true},"outputs":[],"source":["# Import the csv class\n","import csv\n","\n","# Let's open the file in Python\n","with open('bladewolf_training.csv', 'r') as file:\n"," csv_reader = csv.reader(file)\n","\n"," # Be sure to skip the first row (Label)\n"," next(csv_reader)\n"," \n"," # Iterate over each row in the csv file\n"," for row in csv_reader:\n"," # Ensure each row has exactly 2 columns before proceeding\n"," if len(row) == 2:\n"," BaseMessage.make_assistant_message(role_name=\"assistant\", content=row[0]) # Add assistant context\n"," BaseMessage.make_user_message(role_name=\"user\", content=row[1]) # Add user context\n"]},{"cell_type":"markdown","metadata":{},"source":["And we set the basics required to get this running; essentially the model tools, the model itself (Based on the API) and the agent details."]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-11-27T21:56:27.171035Z","iopub.status.busy":"2024-11-27T21:56:27.170331Z","iopub.status.idle":"2024-11-27T21:56:27.985330Z","shell.execute_reply":"2024-11-27T21:56:27.983977Z","shell.execute_reply.started":"2024-11-27T21:56:27.170945Z"},"trusted":true},"outputs":[],"source":["# Set model config\n","tools = [*SearchToolkit().get_tools()]\n","\n","#This means we are using GPT_4O_MINI\n","model = ModelFactory.create(\n"," model_platform=ModelPlatformType.OPENAI,\n"," model_type=ModelType.GPT_4O_MINI,\n",")\n","\n","# Set agent\n","camel_agent = ChatAgent(\n"," system_message=sys_msg,\n"," model=model,\n"," tools=tools,\n",")"]},{"cell_type":"markdown","metadata":{},"source":["Everything is set up! Now we can run our agent and see the magic happen!"]},{"cell_type":"code","execution_count":null,"metadata":{"execution":{"iopub.execute_input":"2024-11-27T21:56:30.569494Z","iopub.status.busy":"2024-11-27T21:56:30.569028Z","iopub.status.idle":"2024-11-27T21:56:38.130062Z","shell.execute_reply":"2024-11-27T21:56:38.128775Z","shell.execute_reply.started":"2024-11-27T21:56:30.569452Z"},"trusted":true},"outputs":[],"source":["# Define a user message\n","usr_msg = 'I need a breifing on the T-84 Metal Gear, code named Sahelanthropus and how we can beat it. Introduce yourself as well.'\n","\n","# Get response information\n","response = camel_agent.step(usr_msg)\n","print(response.msg.content)"]},{"cell_type":"markdown","metadata":{},"source":["Awesome! We can see the response from our agent and we can also see the session in the AgentOps dashboard by clicking on the session URL provided above."]},{"cell_type":"markdown","metadata":{},"source":["## Multi-Agent Chat Example\n","\n","In this example, we'll create two agents: a Python expert who writes code and a code reviewer who provides feedback."]},{"cell_type":"code","execution_count":8,"metadata":{},"outputs":[],"source":["# Initialize two CAMEL agents\n","assistant = ChatAgent(\n"," model=ModelFactory.create(\n"," model_platform=ModelPlatformType.OPENAI,\n"," model_type=ModelType.GPT_4O_MINI,\n"," ),\n"," system_message=\"You are a Python expert who helps write clean, efficient code.\"\n",")\n","\n","reviewer = ChatAgent(\n"," model=ModelFactory.create(\n"," model_platform=ModelPlatformType.OPENAI,\n"," model_type=ModelType.GPT_4O_MINI,\n"," ),\n"," system_message=\"You are a code reviewer who focuses on code quality and best practices.\"\n",")"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# Start a conversation about code optimization\n","message = BaseMessage(\n"," role_name=\"Human\",\n"," role_type=\"human\",\n"," meta_dict={\"timestamp\": \"2024-01-01T00:00:01\"},\n"," content=\"I need help optimizing this Python function for calculating prime numbers:\\ndef is_prime(n):\\n for i in range(2, n):\\n if n % i == 0:\\n return False\\n return True\"\n",")\n","\n","# Get assistant's response\n","assistant_response = assistant.step(message)\n","print(\"Assistant's suggestion:\", assistant_response.msgs[0].content)\n","\n","# Get reviewer's feedback\n","reviewer_message = BaseMessage(\n"," role_name=\"Human\",\n"," role_type=\"human\",\n"," meta_dict={\"timestamp\": \"2024-01-01T00:00:02\"},\n"," content=f\"Please review this code suggestion:\\n{assistant_response.msgs[0].content}\"\n",")\n","reviewer_response = reviewer.step(reviewer_message)\n","print(\"\\nReviewer's feedback:\", reviewer_response.msgs[0].content)\n","\n","# Implement reviewer's suggestions\n","improvement_message = BaseMessage(\n"," role_name=\"Human\",\n"," role_type=\"human\",\n"," meta_dict={\"timestamp\": \"2024-01-01T00:00:03\"},\n"," content=f\"Please improve the code based on this feedback:\\n{reviewer_response.msgs[0].content}\"\n",")\n","final_response = assistant.step(improvement_message)\n","print(\"\\nFinal improved code:\", final_response.msgs[0].content)"]},{"cell_type":"markdown","metadata":{},"source":["You can see on the AgentOps dashboard that we have a multi-agent chat session. Since we did not specify a session name, the session name will be the default name of the class i.e. `ChatAgent`."]},{"cell_type":"markdown","metadata":{},"source":["Now we will end the session with a success message. We can also end the session with a failure or intdeterminate status. By default, the session will be marked as indeterminate."]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["agentops.end_session(\"Success\")"]}],"metadata":{"kaggle":{"accelerator":"none","dataSources":[{"datasetId":6139214,"sourceId":9977643,"sourceType":"datasetVersion"}],"dockerImageVersionId":30786,"isGpuEnabled":false,"isInternetEnabled":true,"language":"python","sourceType":"notebook"},"kernelspec":{"display_name":"Python 3","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.10.15"}},"nbformat":4,"nbformat_minor":4}
diff --git a/examples/langchain_examples/langchain_examples.ipynb b/examples/langchain_examples/langchain_examples.ipynb
index 0e22a013..686b621e 100644
--- a/examples/langchain_examples/langchain_examples.ipynb
+++ b/examples/langchain_examples/langchain_examples.ipynb
@@ -129,11 +129,7 @@
"source": [
"This is where AgentOps comes into play. Before creating our LLM instance via Langchain, first we'll create an instance of the AO LangchainCallbackHandler. After the handler is initialized, a session will be recorded automatically.\n",
"\n",
- "Pass in your API key, and optionally any tags to describe this session for easier lookup in the AO dashboard.\n",
- "\n",
- "agentops_handler = AgentOpsLangchainCallbackHandler(\n",
- " api_key=AGENTOPS_API_KEY, default_tags=[\"Langchain Example\"]\n",
- ")\n"
+ "Pass in your API key, and optionally any tags to describe this session for easier lookup in the AO dashboard.\n"
]
},
{
@@ -340,373 +336,9 @@
"collapsed": false
},
"source": [
- "## Langchain V0.1 Example\n",
- "This example is out of date. You can uncomment all the following cells and the example will run but AgentOps is deprecating support."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "decac159bb492462",
- "metadata": {
- "ExecuteTime": {
- "end_time": "2024-08-08T00:29:32.741186Z",
- "start_time": "2024-08-08T00:29:32.741133Z"
- }
- },
- "outputs": [],
- "source": [
- "# %pip install langchain==0.1.6"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "initial_id",
- "metadata": {
- "ExecuteTime": {
- "end_time": "2024-08-08T00:29:32.741653Z",
- "start_time": "2024-08-08T00:29:32.741599Z"
- }
- },
- "outputs": [],
- "source": [
- "# import os\n",
- "# from langchain_openai import ChatOpenAI\n",
- "# from langchain.agents import initialize_agent, AgentType\n",
- "# from langchain.agents import tool"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "57ddb8eca4e8a3cb",
- "metadata": {},
- "source": [
- "The only difference with using AgentOps is that we'll also import this special Callback Handler"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "7e8f8cd098ad5b57",
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "# from agentops.partners.langchain_callback_handler import (\n",
- "# LangchainCallbackHandler as AgentOpsLangchainCallbackHandler,\n",
- "# )"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "14a1b8e08a2e9eb3",
- "metadata": {
- "collapsed": false
- },
- "source": [
- "Next, we'll grab our two API keys."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "ff6cfc570599871f",
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "# from dotenv import load_dotenv\n",
- "\n",
- "# load_dotenv()"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "51f083697b783fa4",
- "metadata": {
- "collapsed": false
- },
- "source": [
- "This is where AgentOps comes into play. Before creating our LLM instance via Langchain, first we'll create an instance of the AO LangchainCallbackHandler. After the handler is initialized, a session will be recorded automatically.\n",
- "\n",
- "Pass in your API key, and optionally any tags to describe this session for easier lookup in the AO dashboard."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "d432fe915edb6365",
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "# AGENTOPS_API_KEY = os.environ.get(\"AGENTOPS_API_KEY\")\n",
- "# OPENAI_API_KEY = os.environ.get(\"OPENAI_API_KEY\")\n",
- "\n",
- "# agentops_handler = AgentOpsLangchainCallbackHandler(\n",
- "# api_key=AGENTOPS_API_KEY, default_tags=[\"Langchain Example\"]\n",
- "# )\n",
- "\n",
- "# llm = ChatOpenAI(\n",
- "# openai_api_key=OPENAI_API_KEY, callbacks=[agentops_handler], model=\"gpt-3.5-turbo\"\n",
- "# )"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "38d309f07363b58e",
- "metadata": {
- "collapsed": false
- },
- "source": [
- "You can also retrieve the `session_id` of the newly created session."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "f7e3a37cde3f9c22",
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "# print(\"Agent Ops session ID: \" + str(agentops_handler.current_session_ids))"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "42f226ace56ef6f5",
- "metadata": {
- "collapsed": false
- },
- "source": [
- "Agents generally use tools. Let's define a simple tool here. Tool usage is also recorded."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "c103a2edbe837abd",
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "# @tool\n",
- "# def find_movie(genre) -> str:\n",
- "# \"\"\"Find available movies\"\"\"\n",
- "# if genre == \"drama\":\n",
- "# return \"Dune 2\"\n",
- "# else:\n",
- "# return \"Pineapple Express\"\n",
- "\n",
- "\n",
- "# tools = [find_movie]"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "4fb7633857b19bf0",
- "metadata": {
- "collapsed": false
- },
- "source": [
- "For each tool, you need to also add the callback handler"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "a0345f08bf1c5ecd",
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "# for t in tools:\n",
- "# t.callbacks = [agentops_handler]"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "12a02b833716676b",
- "metadata": {
- "collapsed": false
- },
- "source": [
- "Finally, let's use our agent! Pass in the callback handler to the agent, and all the actions will be recorded in the AO Dashboard"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "2d2e83fa69b30add",
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "# agent = initialize_agent(\n",
- "# tools,\n",
- "# llm,\n",
- "# agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,\n",
- "# verbose=True,\n",
- "# callbacks=[\n",
- "# agentops_handler\n",
- "# ], # You must pass in a callback handler to record your agent\n",
- "# handle_parsing_errors=True,\n",
- "# )"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "df2bc3a384493e1e",
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "# agent.invoke(\"What comedies are playing?\", callbacks=[agentops_handler])"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "2230edd919182a55",
- "metadata": {
- "collapsed": false
- },
- "source": [
- "## Check your session\n",
- "Finally, check your run on [AgentOps](https://app.agentops.ai)"
- ]
- },
- {
- "cell_type": "markdown",
- "id": "fbf4a3ec5fa60d74",
- "metadata": {
- "collapsed": false
- },
- "source": [
- "# Async Agents\n",
- "\n",
- "Several langchain agents require async callback handlers. AgentOps also supports this."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "ed63a166b343e1a2",
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "# import os\n",
- "# from langchain.chat_models import ChatOpenAI\n",
- "# from langchain.agents import initialize_agent, AgentType\n",
- "# from langchain.agents import tool"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "aa15223969f97b3d",
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "# from agentops.partners.langchain_callback_handler import (\n",
- "# AsyncLangchainCallbackHandler as AgentOpsAsyncLangchainCallbackHandler,\n",
- "# )"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "818357483f039b60",
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "# from dotenv import load_dotenv\n",
- "\n",
- "# load_dotenv()\n",
- "\n",
- "# AGENTOPS_API_KEY = os.environ.get(\"AGENTOPS_API_KEY\")\n",
- "# OPENAI_API_KEY = os.environ.get(\"OPENAI_API_KEY\")"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "ae76cfe058f5e4e4",
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "# agentops_handler = AgentOpsAsyncLangchainCallbackHandler(\n",
- "# api_key=AGENTOPS_API_KEY, tags=[\"Async Example\"]\n",
- "# )\n",
- "\n",
- "# llm = ChatOpenAI(\n",
- "# openai_api_key=OPENAI_API_KEY, callbacks=[agentops_handler], model=\"gpt-3.5-turbo\"\n",
- "# )\n",
- "\n",
- "# print(\"Agent Ops session ID: \" + str(await agentops_handler.session_id))"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "1201049766be84a7",
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "# @tool\n",
- "# def find_movie(genre) -> str:\n",
- "# \"\"\"Find available movies\"\"\"\n",
- "# if genre == \"drama\":\n",
- "# return \"Dune 2\"\n",
- "# else:\n",
- "# return \"Pineapple Express\"\n",
- "\n",
- "\n",
- "# tools = [find_movie]\n",
- "\n",
- "# for t in tools:\n",
- "# t.callbacks = [agentops_handler]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "id": "8d4f9dd39b79d542",
- "metadata": {
- "collapsed": false
- },
- "outputs": [],
- "source": [
- "# agent = initialize_agent(\n",
- "# tools,\n",
- "# llm,\n",
- "# agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,\n",
- "# verbose=True,\n",
- "# handle_parsing_errors=True,\n",
- "# callbacks=[agentops_handler],\n",
- "# )\n",
+ "## Langchain v0 Example\n",
"\n",
- "# await agent.arun(\"What comedies are playing?\")"
+ "This langchain version is out of date and support is being deprecated. You can find the example notebook [here](https://github.com/agentops-ai/agentops/blob/main/examples/langchain_examples/langchain_v0_example.ipynb)."
]
}
],
@@ -726,7 +358,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.12.0"
+ "version": "3.10.15"
}
},
"nbformat": 4,
diff --git a/examples/langchain_examples/langchain_v0_example.ipynb b/examples/langchain_examples/langchain_v0_example.ipynb
new file mode 100644
index 00000000..3c283e8b
--- /dev/null
+++ b/examples/langchain_examples/langchain_v0_example.ipynb
@@ -0,0 +1,238 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "97a1a264a71876",
+ "metadata": {
+ "collapsed": false
+ },
+ "source": [
+ "# AgentOps Langchain Agent Implementation"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "decac159bb492462",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "%pip install langchain==0.1.6\n",
+ "%pip install agentops"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "initial_id",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "from langchain_openai import ChatOpenAI\n",
+ "from langchain.agents import initialize_agent, AgentType\n",
+ "from langchain.agents import tool"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "57ddb8eca4e8a3cb",
+ "metadata": {},
+ "source": [
+ "The only difference with using AgentOps is that we'll also import this special Callback Handler"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "7e8f8cd098ad5b57",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from agentops.partners.langchain_callback_handler import (\n",
+ " LangchainCallbackHandler as AgentOpsLangchainCallbackHandler,\n",
+ ")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "14a1b8e08a2e9eb3",
+ "metadata": {},
+ "source": [
+ "Next, we'll grab our two API keys."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "ff6cfc570599871f",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "from dotenv import load_dotenv\n",
+ "\n",
+ "load_dotenv()"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "51f083697b783fa4",
+ "metadata": {},
+ "source": [
+ "This is where AgentOps comes into play. Before creating our LLM instance via Langchain, first we'll create an instance of the AO LangchainCallbackHandler. After the handler is initialized, a session will be recorded automatically.\n",
+ "\n",
+ "Pass in your API key, and optionally any tags to describe this session for easier lookup in the AO dashboard."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "d432fe915edb6365",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "AGENTOPS_API_KEY = os.environ.get(\"AGENTOPS_API_KEY\")\n",
+ "OPENAI_API_KEY = os.environ.get(\"OPENAI_API_KEY\")\n",
+ "\n",
+ "agentops_handler = AgentOpsLangchainCallbackHandler(\n",
+ " api_key=AGENTOPS_API_KEY, default_tags=[\"Langchain Example\"]\n",
+ ")\n",
+ "\n",
+ "llm = ChatOpenAI(\n",
+ " openai_api_key=OPENAI_API_KEY, callbacks=[agentops_handler], model=\"gpt-3.5-turbo\"\n",
+ ")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "38d309f07363b58e",
+ "metadata": {},
+ "source": [
+ "You can also retrieve the `session_id` of the newly created session."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "f7e3a37cde3f9c22",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(\"Agent Ops session ID: \" + str(agentops_handler.current_session_ids))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "42f226ace56ef6f5",
+ "metadata": {},
+ "source": [
+ "Agents generally use tools. Let's define a simple tool here. Tool usage is also recorded."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "c103a2edbe837abd",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "@tool\n",
+ "def find_movie(genre) -> str:\n",
+ " \"\"\"Find available movies\"\"\"\n",
+ " if genre == \"drama\":\n",
+ " return \"Dune 2\"\n",
+ " else:\n",
+ " return \"Pineapple Express\"\n",
+ "\n",
+ "\n",
+ "tools = [find_movie]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "4fb7633857b19bf0",
+ "metadata": {},
+ "source": [
+ "For each tool, you need to also add the callback handler"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "a0345f08bf1c5ecd",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "for t in tools:\n",
+ " t.callbacks = [agentops_handler]"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "12a02b833716676b",
+ "metadata": {},
+ "source": [
+ "Finally, let's use our agent! Pass in the callback handler to the agent, and all the actions will be recorded in the AO Dashboard"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "2d2e83fa69b30add",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "agent = initialize_agent(\n",
+ " tools,\n",
+ " llm,\n",
+ " agent=AgentType.CHAT_ZERO_SHOT_REACT_DESCRIPTION,\n",
+ " verbose=True,\n",
+ " callbacks=[\n",
+ " agentops_handler\n",
+ " ], # You must pass in a callback handler to record your agent\n",
+ " handle_parsing_errors=True,\n",
+ ")"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "df2bc3a384493e1e",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "agent.invoke(\"What comedies are playing?\", callbacks=[agentops_handler])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "2230edd919182a55",
+ "metadata": {},
+ "source": [
+ "## Check your session\n",
+ "Finally, check your run on [AgentOps](https://app.agentops.ai)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "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.10.15"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 5
+}
diff --git a/examples/multion_examples/Autonomous_web_browsing.ipynb b/examples/multion_examples/Autonomous_web_browsing.ipynb
index c79a3313..dcbada35 100644
--- a/examples/multion_examples/Autonomous_web_browsing.ipynb
+++ b/examples/multion_examples/Autonomous_web_browsing.ipynb
@@ -5,7 +5,7 @@
"metadata": {},
"source": [
"# MultiOn Tracking Web Browse Actions\n",
- "<img src=\"https://github.com/AgentOps-AI/agentops/blob/b4aac2d4b9fb16d6aa0a25aa9018210a94f1bef2/docs/logo/multion_integration.png?raw=true\" width=\"250px\" style=\"max-width: 100%; height: auto;\"/>\n",
+ "<img src=\"https://github.com/AgentOps-AI/agentops/blob/main/docs/logo/multion_integration.png?raw=true\" width=\"250px\" style=\"max-width: 100%; height: auto;\"/>\n",
" \n",
"Agents using MultiOn can launch and control remote or local web browsers to perform actions and retrieve context using natural language commands. With AgentOps, MultiOn evens such as browse, retrieve, and step are automatically tracked.\n",
"\n",
diff --git a/examples/xai_examples/grok_vision_examples.ipynb b/examples/xai_examples/grok_vision_examples.ipynb
index dda0e053..98012481 100755
--- a/examples/xai_examples/grok_vision_examples.ipynb
+++ b/examples/xai_examples/grok_vision_examples.ipynb
@@ -61,7 +61,7 @@
"source": [
"load_dotenv()\n",
"XAI_API_KEY = os.getenv(\"XAI_API_KEY\") or \"<your_xai_key>\"\n",
- "AGENTOPS_API_KEY = os.getenv(\"AGENTOPS_DEV_API_KEY\") or \"<your_agentops_key>\""
+ "AGENTOPS_API_KEY = os.getenv(\"AGENTOPS_API_KEY\") or \"<your_agentops_key>\""
]
},
{