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

Portkey Integration with Autogen #3395

Merged
merged 23 commits into from
Sep 9, 2024
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b715223
Portkey Integration with Autogen
siddharthsambharia-portkey Aug 21, 2024
adce2ed
Merge branch 'main' into main
thinkall Aug 22, 2024
919e1ec
Update website/docs/ecosystem/portkey.md
siddharthsambharia-portkey Aug 25, 2024
104b809
Update website/docs/ecosystem/portkey.md
siddharthsambharia-portkey Aug 25, 2024
f1a21fe
Update website/docs/ecosystem/portkey.md
siddharthsambharia-portkey Aug 25, 2024
834bea0
Merge branch 'main' into main
siddharthsambharia-portkey Aug 26, 2024
4417cf8
Update website/docs/ecosystem/portkey.md
gagb Aug 26, 2024
4bfff47
Update website/docs/ecosystem/portkey.md
gagb Aug 26, 2024
a63517c
Update website/docs/ecosystem/portkey.md
gagb Aug 26, 2024
cab3c54
Update website/docs/ecosystem/portkey.md
gagb Aug 26, 2024
1fd287a
Update website/docs/ecosystem/portkey.md
gagb Aug 26, 2024
2f89009
Update portkey.md with changes
siddharthsambharia-portkey Aug 26, 2024
8039fd3
Merge branch 'main' into main
gagb Aug 26, 2024
7fa62b0
Update website/docs/ecosystem/portkey.md
siddharthsambharia-portkey Aug 27, 2024
b9837fb
Merge branch 'main' into main
gagb Aug 27, 2024
faf13df
Merge branch 'main' into main
gagb Aug 27, 2024
ee16d4d
Merge branch 'main' into main
gagb Aug 29, 2024
e77d46d
Remove trailing white spaces
siddharthsambharia-portkey Aug 29, 2024
170c7c2
Update portkey.md with mark's note
siddharthsambharia-portkey Aug 30, 2024
ce8f173
Merge branch 'main' into main
marklysze Aug 30, 2024
33c6639
Merge branch 'main' into main
gagb Aug 31, 2024
28c1ad7
remove trailing white spaces line 15 and empty line at end
siddharthsambharia-portkey Aug 31, 2024
dda4c7e
Merge branch 'main' into main
gagb Sep 9, 2024
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
210 changes: 210 additions & 0 deletions website/docs/ecosystem/portkey.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
# Portkey Integration with Autogen
siddharthsambharia-portkey marked this conversation as resolved.
Show resolved Hide resolved
<img src="https://github.com/siddharthsambharia-portkey/Portkey-Product-Images/blob/main/Portkey-Autogen.png?raw=true" alt="Portkey Metrics Visualization" width=70% />

[Portkey](https://portkey.ai) is a 2-line upgrade to make your Autogen agents reliable, cost-efficient, and fast.
siddharthsambharia-portkey marked this conversation as resolved.
Show resolved Hide resolved

Portkey adds 4 core production capabilities to any Autogen agent:
siddharthsambharia-portkey marked this conversation as resolved.
Show resolved Hide resolved
1. Routing to 200+ LLMs
2. Making each LLM call more robust
3. Full-stack tracing & cost, performance analytics
4. Real-time guardrails to enforce behavior

## Getting Started

1. **Install Required Packages:**

```bash
pip install -qU pyautogen portkey-ai
```

2. **Configure Autogen with Portkey:**
gagb marked this conversation as resolved.
Show resolved Hide resolved

```python
from autogen import AssistantAgent, UserProxyAgent, config_list_from_json
from portkey_ai import PORTKEY_GATEWAY_URL, createHeaders

config = [
{
"api_key": "OPENAI_API_KEY",
"model": "gpt-3.5-turbo",
"base_url": PORTKEY_GATEWAY_URL,
"api_type": "openai",
"default_headers": createHeaders(
api_key="YOUR_PORTKEY_API_KEY",
provider="openai",
)
}
]
```

Generate your API key in the [Portkey Dashboard](https://app.portkey.ai/).

And, that's it! With just this, you can start logging all of your Autogen requests and make them reliable.
gagb marked this conversation as resolved.
Show resolved Hide resolved

3. **Let's Run your Agent**

``` python
import autogen

# Create user proxy agent, coder, product manager


user_proxy = autogen.UserProxyAgent(
name="User_proxy",
system_message="A human admin who will give the idea and run the code provided by Coder.",
code_execution_config={"last_n_messages": 2, "work_dir": "groupchat"},
human_input_mode="ALWAYS",
)


coder = autogen.AssistantAgent(
name="Coder",
system_message = "You are a Python developer who is good at developing games. You work with Product Manager."
siddharthsambharia-portkey marked this conversation as resolved.
Show resolved Hide resolved
llm_config={"config_list": config},
)

# Create groupchat
groupchat = autogen.GroupChat(
agents=[user_proxy, coder], messages=[])
manager = autogen.GroupChatManager(groupchat=groupchat, llm_config={"config_list": config})



# Start the conversation
user_proxy.initiate_chat(
manager, message="Build a classic & basic pong game with 2 players in python")

```
<br>
Here’s the output from your Agent’s run on Portkey's dashboard<br>
<img src=https://github.com/siddharthsambharia-portkey/Portkey-Product-Images/blob/main/Portkey-Dashboard.png?raw=true width=70%" alt="Portkey Dashboard" />






## Key Features
Portkey offers a range of advanced features to enhance your Autogen agents. Here’s an overview
gagb marked this conversation as resolved.
Show resolved Hide resolved

| Feature | Description |
|---------|-------------|
| 🌐 [Multi-LLM Integration](#interoperability) | Access 200+ LLMs with simple configuration changes |
| 🛡️ [Enhanced Reliability](#reliability) | Implement fallbacks, load balancing, retries, and much more |
| 📊 [Advanced Metrics](#metrics) | Track costs, tokens, latency, and 40+ custom metrics effortlessly |
| 🔍 [Detailed Traces and Logs](#comprehensive-logging) | Gain insights into every agent action and decision |
| 🚧 [Guardrails](#guardrails) | Enforce agent behavior with real-time checks on inputs and outputs |
| 🔄 [Continuous Optimization](#continuous-improvement) | Capture user feedback for ongoing agent improvements |
| 💾 [Smart Caching](#caching) | Reduce costs and latency with built-in caching mechanisms |
| 🔐 [Enterprise-Grade Security](#security-and-compliance) | Set budget limits and implement fine-grained access controls |


## Colab Notebook

For a hands-on example of integrating Portkey with Autogen, check out our notebook<br> <br>[![Google Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://git.new/Portkey-Autogen) .



## Advanced Features

### Interoperability

Easily switch between **200+ LLMs** by changing the `provider` and API key in your configuration.

#### Example: Switching from OpenAI to Azure OpenAI

```python
config = [
{
"api_key": "api-key",
"model": "gpt-3.5-turbo",
"base_url": PORTKEY_GATEWAY_URL,
"api_type": "openai",
"default_headers": createHeaders(
api_key="YOUR_PORTKEY_API_KEY",
provider="azure-openai",
virtual_key="AZURE_VIRTUAL_KEY"
)
}
]
```

### Reliability

Implement fallbacks, load balancing, and automatic retries to make your agents more resilient.

```python
portkey_config = {
siddharthsambharia-portkey marked this conversation as resolved.
Show resolved Hide resolved
"retry": {
"attempts": 5
},
"strategy": {
"mode": "loadbalance" # Options: "loadbalance" or "fallback"
},
"targets": [
{
"provider": "openai",
"api_key": "OpenAI_API_Key"
},
{
"provider": "anthropic",
"api_key": "Anthropic_API_Key"
}
]
}
```

### Metrics

Agent runs are complex. Portkey automatically logs **40+ comprehensive metrics** for your AI agents, including cost, tokens used, latency, etc. Whether you need a broad overview or granular insights into your agent runs, Portkey's customizable filters provide the metrics you need.

<details>
<summary><b>Portkey's Observability Dashboard</b></summary>
<img src=https://github.com/siddharthsambharia-portkey/Portkey-Product-Images/blob/main/Portkey-Dashboard.png?raw=true width=70%" alt="Portkey Dashboard" />
</details>

### Comprehensive Logging

Access detailed logs and traces of agent activities, function calls, and errors. Filter logs based on multiple parameters for in-depth analysis.

<details>
<summary><b>Traces</b></summary>
<img src="https://raw.githubusercontent.com/siddharthsambharia-portkey/Portkey-Product-Images/main/Portkey-Traces.png" alt="Portkey Logging Interface" width=70% />
</details>

<details>
<summary><b>Logs</b></summary>
<img src="https://raw.githubusercontent.com/siddharthsambharia-portkey/Portkey-Product-Images/main/Portkey-Logs.png" alt="Portkey Metrics Visualization" width=70% />
</details>

### Guardrails
Autogen agents, while powerful, can sometimes produce unexpected or undesired outputs. Portkey's Guardrails feature helps enforce agent behavior in real-time, ensuring your Autogen agents operate within specified parameters. Verify both the **inputs** to and *outputs* from your agents to ensure they adhere to specified formats and content guidelines. Learn more about Portkey's Guardrails [here](https://docs.portkey.ai/product/guardrails)
gagb marked this conversation as resolved.
Show resolved Hide resolved

### Continuous Improvement

Capture qualitative and quantitative user feedback on your requests to continuously enhance your agent performance.

### Caching

Reduce costs and latency with Portkey's built-in caching system.

```python
portkey_config = {
"cache": {
"mode": "semantic" # Options: "simple" or "semantic"
}
}
```

### Security and Compliance

Set budget limits on provider API keys and implement fine-grained user roles and permissions for both your application and the Portkey APIs.

## Additional Resources

- [📘 Portkey Documentation](https://docs.portkey.ai)
- [🐦 Twitter](https://twitter.com/portkeyai)
- [💬 Discord Community](https://discord.gg/JHPt4C7r)
- [📊 Portkey App](https://app.portkey.ai)

For more information on using these features and setting up your Config, please refer to the [Portkey documentation](https://docs.portkey.ai).