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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 29 additions & 16 deletions docs/v2/integrations/anthropic.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,14 @@ client = anthropic.Anthropic(api_key="<YOUR_ANTHROPIC_API_KEY>")
# Define tools
tools = [
{
"type": "custom",
"name": "get_current_time",
"description": "Get the current date and time",
"input_schema": {},
"input_schema": {
"type": "object",
"properties": {},
"required": []
}
}
]

Expand All @@ -149,9 +154,9 @@ def get_current_time():
)

# Handle tool use
if message.content[0].type == "tool_use":
tool_use = message.content[0].tool_use
tool_name = tool_use.name
if message.content[0].type == "tool_calls":
tool_call = message.content[0].tool_calls[0]
tool_name = tool_call.name

if tool_name == "get_current_time":
tool_response = get_current_time()
Expand All @@ -162,18 +167,26 @@ if message.content[0].type == "tool_use":
max_tokens=1000,
messages=[
{"role": "user", "content": "What time is it now?"},
{"role": "assistant", "content": [
{"type": "tool_use", "tool_use": {
"name": "get_current_time",
"input": {}
}}
]},
{"role": "user", "content": [
{"type": "tool_result", "tool_result": {
"tool_name": "get_current_time",
"content": json.dumps(tool_response)
}}
]}
{
"role": "assistant",
"content": [
{
"type": "tool_calls",
"tool_calls": [
{
"type": "custom",
"name": "get_current_time",
"input": {}
}
]
}
]
},
{
"role": "tool",
"content": json.dumps(tool_response),
"tool_call_id": tool_call.id
}
]
)

Expand Down
113 changes: 64 additions & 49 deletions docs/v2/integrations/crewai.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -21,55 +21,65 @@ import EnvTooltip from '/snippets/add-env-tooltip.mdx'
</Step>
<Step title="Add AgentOps to your code">
<CodeTooltip/>
<CodeGroup>
```python python
import agentops
from crewai import Agent, Task, Crew, LLM
import os
from dotenv import load_dotenv

# Load environment variables
load_dotenv()
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY") or "YOUR_OPENAI_API_KEY"
AGENTOPS_API_KEY = os.getenv("AGENTOPS_API_KEY") or "YOUR_AGENTOPS_API_KEY"

# Initialize AgentOps at the start of your application
agentops.init(AGENTOPS_API_KEY)

# Set up your CrewAI elements as you normally would
# AgentOps will automatically track all interactions
llm = LLM(model="openai/gpt-4o", api_key=OPENAI_API_KEY)

researcher = Agent(
role="Researcher",
goal="Find accurate information about a topic",
backstory="You're an expert researcher with keen attention to detail",
llm=llm
)

research_task = Task(
description="Research the latest developments in quantum computing",
expected_output="A comprehensive report on the latest breakthroughs in quantum computing, including advancements in quantum algorithms, hardware, and potential applications.",
agent=researcher
)

crew = Crew(
agents=[researcher],
tasks=[research_task],
verbose=True
)

# Run the crew - AgentOps will track everything
result = crew.kickoff()
```
</CodeGroup>
<CodeGroup>
```python python
import os
from dotenv import load_dotenv
import agentops
from crewai import Agent, Task, Crew
from langchain_openai import ChatOpenAI

# Load environment variables
load_dotenv()

# Initialize AgentOps
agentops.init(os.getenv("AGENTOPS_API_KEY"))

# Create LLM
llm = ChatOpenAI(
model="gpt-4",
temperature=0.7,
api_key=os.getenv("OPENAI_API_KEY")
)

# Create an agent
researcher = Agent(
role='Researcher',
goal='Research and provide accurate information about cities and their history',
backstory='You are an expert researcher with vast knowledge of world geography and history.',
llm=llm,
verbose=True
)

# Create a task
research_task = Task(
description='What is the capital of France? Provide a detailed answer about its history, culture, and significance.',
expected_output='A comprehensive response about Paris, including its status as the capital of France, historical significance, cultural importance, and key landmarks.',
agent=researcher
)

# Create a crew with the researcher
crew = Crew(
agents=[researcher],
tasks=[research_task],
verbose=True
)

# Execute the task - AgentOps will automatically track all LLM calls
result = crew.kickoff()

print("\nCrew Research Results:")
print(result)
```
</CodeGroup>
<EnvTooltip />
<CodeGroup>
```python .env
AGENTOPS_API_KEY=<YOUR API KEY>
```
</CodeGroup>
Read more about environment variables in [Advanced Configuration](/v2/usage/advanced-configuration)
<CodeGroup>
```python .env
AGENTOPS_API_KEY=<YOUR API KEY>
OPENAI_API_KEY=<YOUR OPENAI API KEY>
```
</CodeGroup>
Read more about environment variables in [Advanced Configuration](/v2/usage/advanced-configuration)
</Step>
<Step title="Run your crew">
Execute your program and visit [app.agentops.ai/traces](https://app.agentops.ai/traces) to observe your Crew! 🕵️
Expand All @@ -83,6 +93,12 @@ import EnvTooltip from '/snippets/add-env-tooltip.mdx'
</Step>
</Steps>

## Important Notes

1. The `Task` class requires an `expected_output` field that describes what the task should produce
2. Setting `verbose=True` on both the agent and crew provides better visibility into the execution process
3. Tasks should have clear, detailed descriptions to guide the agent effectively

## Crew + AgentOps Examples

<CardGroup cols={3}>
Expand All @@ -95,4 +111,3 @@ import EnvTooltip from '/snippets/add-env-tooltip.mdx'
<script type="module" src="/scripts/scroll-img-fadein-animation.js"></script>
<script type="module" src="/scripts/button_heartbeat_animation.js"></script>
<script type="css" src="/styles/styles.css"></script>
<script type="module" src="/scripts/adjust_api_dynamically.js"></script>
28 changes: 14 additions & 14 deletions docs/v2/integrations/gemini.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,23 @@ print(response.text)

## Alternative Client Setup

You can also set up the client using environment variables or with Vertex AI:
You can also set up the client using Vertex AI or with environment variables:

<CodeGroup>
```python Using Environment Variables

```python Vertex AI
import agentops
from google import genai

# Initialize AgentOps
agentops.init(<INSERT YOUR API KEY HERE>)

# Set GOOGLE_API_KEY environment variable before running
# export GOOGLE_API_KEY='your-api-key'
client = genai.Client()
# Using Vertex AI
client = genai.Client(
vertexai=True,
project='your-project-id',
location='us-central1'
)

# Generate content
response = client.models.generate_content(
Expand All @@ -71,19 +75,16 @@ response = client.models.generate_content(
print(response.text)
```

```python Vertex AI
```python Using Environment Variables
import agentops
from google import genai

# Initialize AgentOps
agentops.init(<INSERT YOUR API KEY HERE>)

# Using Vertex AI
client = genai.Client(
vertexai=True,
project='your-project-id',
location='us-central1'
)
# Set GOOGLE_API_KEY environment variable before running
# export GOOGLE_API_KEY='your-api-key'
client = genai.Client()

# Generate content
response = client.models.generate_content(
Expand Down Expand Up @@ -142,10 +143,9 @@ agentops.init(<INSERT YOUR API KEY HERE>)
client = genai.Client(api_key="YOUR_GEMINI_API_KEY")

# Generate streaming content
for chunk in client.models.generate_content(
for chunk in client.models.generate_content_stream(
model='gemini-2.0-flash-001',
contents='Explain quantum computing in simple terms.',
stream=True
):
print(chunk.text, end="", flush=True)

Expand Down
79 changes: 27 additions & 52 deletions docs/v2/integrations/litellm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,18 @@ The simplest way to integrate AgentOps with LiteLLM is to set up the success_cal

<CodeGroup>
```python Simple Integration
import os
from dotenv import load_dotenv
import litellm

# Configure LiteLLM to use AgentOps
litellm.success_callback = ["agentops"]

# Make completion requests with LiteLLM
response = litellm.completion(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": "Hello, how are you?"}]
)

print(response.choices[0].message.content)

# All LiteLLM API calls are automatically tracked by AgentOps
```
</CodeGroup>

You can also initialize AgentOps separately for additional configuration:

<CodeGroup>
```python With AgentOps Init
import agentops
from litellm import completion

# Initialize AgentOps
agentops.init(<INSERT YOUR API KEY HERE>)
# Load environment variables
load_dotenv()

# Set API keys for different providers
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
os.environ["ANTHROPIC_API_KEY"] = os.getenv("ANTHROPIC_API_KEY")
os.environ["AGENTOPS_API_KEY"] = os.getenv("AGENTOPS_API_KEY")

# Configure LiteLLM to use AgentOps
litellm.success_callback = ["agentops"]
Expand All @@ -67,40 +53,22 @@ print(response.choices[0].message.content)
```
</CodeGroup>

## Using the LiteLLM Client

<CodeGroup>
```python Python
import litellm
from litellm import LiteLLM

# Configure LiteLLM to use AgentOps
litellm.success_callback = ["agentops"]

# Create a LiteLLM client
client = LiteLLM()

# Make a completion request
response = client.completion(
model="anthropic/claude-3-opus-20240229",
messages=[{"role": "user", "content": "What are the benefits of using LiteLLM?"}]
)

print(response.choices[0].message.content)

# All client requests are automatically tracked by AgentOps
```
</CodeGroup>

## Streaming Example

AgentOps also tracks streaming requests with LiteLLM:

<CodeGroup>
```python Python
```python Streaming
import os
from dotenv import load_dotenv
import litellm
from litellm import completion

# Load environment variables and set API keys
load_dotenv()
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
os.environ["AGENTOPS_API_KEY"] = os.getenv("AGENTOPS_API_KEY")

# Configure LiteLLM to use AgentOps
litellm.success_callback = ["agentops"]

Expand All @@ -115,8 +83,7 @@ response = completion(
for chunk in response:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)

# All streaming requests are automatically tracked by AgentOps
print() # Add a newline at the end
```
</CodeGroup>

Expand All @@ -125,10 +92,18 @@ for chunk in response:
One of LiteLLM's key features is the ability to switch between providers easily:

<CodeGroup>
```python Python
```python Multi-Provider
import os
from dotenv import load_dotenv
import litellm
from litellm import completion

# Load environment variables and set API keys
load_dotenv()
os.environ["OPENAI_API_KEY"] = os.getenv("OPENAI_API_KEY")
os.environ["ANTHROPIC_API_KEY"] = os.getenv("ANTHROPIC_API_KEY")
os.environ["AGENTOPS_API_KEY"] = os.getenv("AGENTOPS_API_KEY")

# Configure LiteLLM to use AgentOps
litellm.success_callback = ["agentops"]

Expand Down
Loading