Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 15 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 122 additions & 37 deletions docs/v1/examples/camel.mdx
Original file line number Diff line number Diff line change
@@ -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)
## 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.
8 changes: 4 additions & 4 deletions docs/v1/examples/examples.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
11 changes: 3 additions & 8 deletions docs/v1/examples/langchain.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down Expand Up @@ -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).
2 changes: 1 addition & 1 deletion docs/v1/examples/simple_agent.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
)
)
Expand Down
50 changes: 12 additions & 38 deletions docs/v1/integrations/camel.mdx
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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"
Expand All @@ -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>
Expand All @@ -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
Expand Down Expand Up @@ -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>
Expand Down
Loading
Loading