Agno is a powerful framework for building autonomous AI agents that can reason, use tools, maintain memory, and access knowledge bases. Portkey enhances Agno agents with enterprise-grade capabilities for production deployments.Portkey transforms your Agno agents into production-ready systems by providing:
Complete observability of agent reasoning, tool usage, and knowledge retrieval
Access to 1600+ LLMs through a unified interface
Built-in reliability with fallbacks, retries, and load balancing
Cost tracking and optimization across all agent operations
Advanced guardrails for safe and compliant agent behavior
Enterprise governance with budget controls and access management
Agno AI Official Documentation
Learn more about Agno’s agent framework and core concepts
If this is your first time using Portkey, you will need to connect your LLM Provider in the app to use them in your Agno AI agents.
1
Create an Integration
Navigate to the Integrations section on Portkey’s Sidebar. This is where you’ll connect your LLM providers.
Find your preferred provider (e.g., OpenAI, Anthropic, etc.)
Click Connect on the provider card
In the “Create New Integration” window:
Enter a Name for reference
Enter a Slug for the integration
Enter your API Key and other provider specific details for the provider
Click Next Step
In your next step you’ll see workspace provisioning options. You can select the default “Shared Team Workspace” if this is your first time OR chose your current one.
2
Configure Models
On the model provisioning page:
Leave all models selected (or customize)
Toggle Automatically enable new models if desired
Click Create Integration to complete the integration
Portkey API Key & Portkey AI Provider slug from Step 1
1
Install required packages
pip install -U agno portkey-ai
2
Get your Portkey API Key
Sign up at app.portkey.ai to get your API key.Once you are on the Portkey follow this guide to create your first AI provider and integration that will help us connect Agno to any LLM provider.
3
Configure Portkey with Agno
Agno makes integration incredibly simple - just use the OpenAILike model class with Portkey’s configuration:
from agno.models.openai.like import OpenAILikeportkey_model = OpenAILike( id="@opeani-provider-slug/gpt-4o", # you need to use "@provider-slug/model-name" for any provider api_key="YOUR_PORTKEY_API_KEY", base_url="https://api.portkey.ai/v1",)
Let’s create a simple Agno agent that uses Portkey for LLM calls:
simple_agent.py
from agno.agent import Agentfrom agno.models.openai.like import OpenAILike# Configure Portkey as the model providerportkey_model = OpenAILike( id="@opeani-provider-slug/gpt-4o", # You can use any model available on Portkey api_key="YOUR_PORTKEY_API_KEY", base_url="https://api.portkey.ai/v1",)# Create an Agno agent with Portkeyagent = Agent( model=portkey_model, instructions="Be concise and informative.", markdown=True,)# Run the agentagent.print_response("What is Portkey AI?", stream=True)
Visit your Portkey dashboard to see detailed logs of your agent’s execution, including tool calls and model responses!
Portkey provides comprehensive observability for your Agno agents, helping you understand exactly what’s happening during each execution.
Traces
Logs
Metrics & Dashboards
Metadata Filtering
Traces provide a hierarchical view of your agent’s execution, showing the sequence of LLM calls, tool invocations, and state transitions.
from agno.agent import Agentfrom agno.models.openai.like import OpenAILikefrom portkey_ai import createHeaders# Add tracing to your Agno agentsportkey_model = OpenAILike( id="@opeani-provider-slug/gpt-4o", api_key="YOUR_PORTKEY_API_KEY", base_url="https://api.portkey.ai/v1", default_headers=createHeaders( trace_id="unique_execution_trace_id", # Add unique trace ID ))agent = Agent( model=portkey_model, instructions="You are a helpful assistant.", markdown=True)
Portkey logs every interaction with LLMs, including:
Complete request and response payloads
Latency and token usage metrics
Cost calculations
Tool calls and function executions
All logs can be filtered by metadata, trace IDs, models, and more, making it easy to debug specific agent runs.
Portkey provides built-in dashboards that help you:
Track cost and token usage across all agent runs
Analyze performance metrics like latency and success rates
Identify bottlenecks in your agent workflows
Compare different agent configurations and LLMs
You can filter and segment all metrics by custom metadata to analyze specific agent types, user groups, or use cases.
Add custom metadata to your Agno agent calls to enable powerful filtering and segmentation:
from agno.agent import Agentfrom agno.models.openai.like import OpenAILikefrom portkey_ai import createHeaders# Add metadata to your Agno agentsportkey_model = OpenAILike( id="@opeani-provider-slug/gpt-4o", api_key="YOUR_PORTKEY_API_KEY", base_url="https://api.portkey.ai/v1", default_headers=createHeaders( metadata={"agent_type": "research_agent"}, # Add custom metadata ))agent = Agent( model=portkey_model, name="Research Agent", instructions="You are a research assistant.", markdown=True)
This metadata can be used to filter logs, traces, and metrics on the Portkey dashboard, allowing you to analyze specific agent runs, users, or environments.
2. Reliability - Keep Your Agents Running Smoothly
When running agents in production, things can go wrong - API rate limits, network issues, or provider outages. Portkey’s reliability features ensure your agents keep running smoothly even when problems occur.It’s this simple to enable fallback in your Agno agents:
from agno.agent import Agentfrom agno.models.openai.like import OpenAILikefrom portkey_ai import createHeaders# Create a config with fallbacks# It's recommended that you create the Config in Portkey App rather than hard-code the config JSON directlyconfig = { "strategy": { "mode": "fallback" }, "targets": [ { "override_params": {"model": "@opeani-provider-slug/gpt-4o"} }, { "override_params": {"model": "claude-3-opus-20240229"} } ]}# Configure Portkey model with fallback configportkey_model = OpenAILike( id="@opeani-provider-slug/gpt-4o", api_key="YOUR_PORTKEY_API_KEY", base_url="https://api.portkey.ai/v1", default_headers=createHeaders(config=config))agent = Agent( model=portkey_model, instructions="You are a helpful assistant.", markdown=True)
This configuration will automatically try Claude if the GPT-4o request fails, ensuring your agent can continue operating.
Automatic Retries
Handles temporary failures automatically. If an LLM call fails, Portkey will retry the same request for the specified number of times - perfect for rate limits or network blips.
Request Timeouts
Prevent your agents from hanging. Set timeouts to ensure you get responses (or can fail gracefully) within your required timeframes.
Conditional Routing
Send different requests to different providers. Route complex reasoning to GPT-4, creative tasks to Claude, and quick responses to Gemini based on your needs.
Fallbacks
Keep running even if your primary provider fails. Automatically switch to backup providers to maintain availability.
Load Balancing
Spread requests across multiple API keys or providers. Great for high-volume agent operations and staying within rate limits.
Portkey’s Prompt Engineering Studio helps you create, manage, and optimize the prompts used in your Agno agents. Instead of hardcoding prompts or instructions, use Portkey’s prompt rendering API to dynamically fetch and apply your versioned prompts.
Prompt Playground
Using Prompt Templates
Prompt Versioning
Mustache Templating for variables
Prompt Playground is a place to compare, test and deploy perfect prompts for your AI application. It’s where you experiment with different models, test variables, compare outputs, and refine your prompt engineering strategy before deploying to production. It allows you to:
Iteratively develop prompts before using them in your agents
Test prompts with different variables and models
Compare outputs between different prompt versions
Collaborate with team members on prompt development
This visual environment makes it easier to craft effective prompts for each step in your Agno agent’s workflow.
The Prompt Render API retrieves your prompt templates with all parameters configured:
from agno.agent import Agentfrom agno.models.openai.like import OpenAILikefrom portkey_ai import Portkey, createHeaders# Initialize Portkey clientportkey_client = Portkey(api_key="PORTKEY_API_KEY")# Retrieve prompt using the render APIprompt_data = portkey_client.prompts.render( prompt_id="YOUR_PROMPT_ID", variables={ "user_input": "Tell me about artificial intelligence" })# Configure Agno model with Portkeyportkey_model = OpenAILike( id="@opeani-provider-slug/gpt-4o", api_key="YOUR_PORTKEY_API_KEY", base_url="https://api.portkey.ai/v1",)# Use the rendered prompt in your Agno agentagent = Agent( name="Assistant", model=portkey_model, instructions=prompt_data.data.messages[0]["content"], # Use the rendered prompt as instructions markdown=True)agent.print_response("Tell me about artificial intelligence", stream=True)
You can:
Create multiple versions of the same prompt
Compare performance between versions
Roll back to previous versions if needed
Specify which version to use in your code:
# Use a specific prompt versionprompt_data = portkey_client.prompts.render( prompt_id="YOUR_PROMPT_ID@version_number", variables={ "user_input": "Tell me about quantum computing" })
Portkey prompts use Mustache-style templating for easy variable substitution:
You are an AI assistant helping with {{task_type}}.User question: {{user_input}}Please respond in a {{tone}} tone and include {{required_elements}}.
When rendering, simply pass the variables:
prompt_data = portkey_client.prompts.render( prompt_id="YOUR_PROMPT_ID", variables={ "task_type": "research", "user_input": "Tell me about quantum computing", "tone": "professional", "required_elements": "recent academic references" })
Prompt Engineering Studio
Learn more about Portkey’s prompt management features
Guardrails ensure your Agno agents operate safely and respond appropriately in all situations.Why Use Guardrails?Agno agents can experience various failure modes:
Generating harmful or inappropriate content
Leaking sensitive information like PII
Hallucinating incorrect information
Generating outputs in incorrect formats
Portkey’s guardrails protect against these issues by validating both inputs and outputs.Implementing Guardrails
from agno.agent import Agentfrom agno.models.openai.like import OpenAILikefrom portkey_ai import createHeaders# Create a config with input and output guardrails# It's recommended you create Config in Portkey App and pass the config ID in the clientconfig = { "input_guardrails": ["guardrails-id-xxx", "guardrails-id-yyy"], "output_guardrails": ["guardrails-id-xxx"]}# Configure Agno model with guardrailsportkey_model = OpenAILike( id="@opeani-provider-slug/gpt-4o", api_key="YOUR_PORTKEY_API_KEY", base_url="https://api.portkey.ai/v1", default_headers=createHeaders( config=config, ))agent = Agent( model=portkey_model, instructions="You are a helpful assistant that provides safe responses.", markdown=True)
Portkey’s guardrails can:
Detect and redact PII in both inputs and outputs
Filter harmful or inappropriate content
Validate response formats against schemas
Check for hallucinations against ground truth
Apply custom business logic and rules
Learn More About Guardrails
Explore Portkey’s guardrail features to enhance agent safety
Track individual users through your Agno agents using Portkey’s metadata system.What is Metadata in Portkey?Metadata allows you to associate custom data with each request, enabling filtering, segmentation, and analytics. The special _user field is specifically designed for user tracking.
from agno.agent import Agentfrom agno.models.openai.like import OpenAILikefrom portkey_ai import createHeaders# Configure model with user trackingportkey_model = OpenAILike( id="@opeani-provider-slug/gpt-4o", api_key="YOUR_PORTKEY_API_KEY", base_url="https://api.portkey.ai/v1", default_headers=createHeaders( metadata={ "_user": "user_123", # Special _user field for user analytics "user_name": "John Doe", "user_tier": "premium", "user_company": "Acme Corp" } ))agent = Agent( model=portkey_model, user_id="user_123", # Also use Agno's user_id for agent-level tracking instructions="You are a personalized assistant.", markdown=True)
Filter Analytics by UserWith metadata in place, you can filter analytics by user and analyze performance metrics on a per-user basis:
This enables:
Per-user cost tracking and budgeting
Personalized user analytics
Team or organization-level metrics
Environment-specific monitoring (staging vs. production)
Learn More About Metadata
Explore how to use custom metadata to enhance your analytics
Reliability: Ensuring consistent service across all users
Portkey adds a comprehensive governance layer to address these enterprise needs. Let’s implement these controls step by step.Enterprise Implementation GuidePortkey allows you to use 1600+ LLMs with your Agno AI agents setup, with minimal configuration required. Let’s set up the core components in Portkey that you’ll need for integration.
As your AI usage scales, controlling which teams can access specific models becomes crucial. You can simply manage AI models in your org by provisioning model at the top integration level.
Step 4: Set Routing Configuration
Portkey allows you to control your routing logic very simply with it’s Configs feature. Portkey Configs provide this control layer with things like:
Data Protection: Implement guardrails for sensitive code and data
After distributing API keys to your engineering teams, your enterprise-ready Cline setup is ready to go. Each developer can now use their designated API keys with appropriate access levels and budget controls.
Apply your governance setup using the integration steps from earlier sections
Monitor usage in Portkey dashboard:
Portkey adds production-grade features to Agno agents including comprehensive observability (traces, logs, analytics), reliability (fallbacks, retries, load balancing), access to 1600+ LLMs, cost management, and enterprise governance - all without changing your agent logic.
Can I use any LLM with Agno through Portkey?
Yes! Portkey provides access to 1600+ LLMs from providers like OpenAI, Anthropic, Google, Cohere, and many more. Just change the model ID in your configuration to switch between providers.
How do I track costs for different agents?
Portkey automatically tracks costs for all LLM calls. You can segment costs by agent type, user, or custom metadata. Set up AI Provider integrations with budget limits to control spending on Model Catalog.
Does Portkey support all Agno features?
Yes! Portkey works seamlessly with all Agno features including tools, reasoning, memory, knowledge bases, and storage. It adds observability and reliability without limiting any Agno functionality.
How do I debug agent failures?
Portkey’s detailed logs and traces make debugging easy. You can see the complete execution flow, including failed tool calls, LLM errors, and retry attempts. Filter by trace ID or metadata to find specific issues.