Integrating Agno with Maxim

Maxim AI provides comprehensive agent monitoring, evaluation, and observability for your Agno applications. With Maxim’s one-line integration, you can easily trace and analyse agent interactions, performance metrics, and more.

Prerequisites

  1. Install Dependencies Ensure you have the necessary packages installed:
    pip install agno openai maxim-py
    
    Or install Maxim separately:
    pip install maxim-py
    
  2. Setup Maxim Account
    • Sign up for an account at Maxim.
    • Generate your API key from the Maxim dashboard.
    • Create a repository to store your traces.
  3. Set Environment Variables Configure your environment with the Maxim API key:
    export MAXIM_API_KEY=<your-api-key>
    export MAXIM_LOG_REPO_ID=<your-repo-id>
    export OPENAI_API_KEY=<your-openai-api-key>
    

Sending Traces to Maxim

Example: Basic Maxim Integration

This example demonstrates how to instrument your Agno agent with Maxim and send traces for monitoring and evaluation.
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.yfinance import YFinanceTools

try:
    from maxim import Maxim
    from maxim.logger.agno import instrument_agno
except ImportError:
    raise ImportError(
        "`maxim` not installed. Please install using `pip install maxim-py`"
    )

# Instrument Agno with Maxim for automatic tracing and logging
instrument_agno(Maxim().logger())

# Create and configure the agent
agent = Agent(
    name="Stock Price Agent",
    model=OpenAIChat(id="gpt-4o"),
    tools=[YFinanceTools()],
    instructions="You are a stock price agent. Answer questions in the style of a stock analyst.",
    show_tool_calls=True,
    markdown=True,
)

# Use the agent
response = agent.run("What is the current price of Tesla?")
print(response.content)

Example: Multi-Agent System with Maxim

This example demonstrates how to set up a multi-agent system with comprehensive Maxim tracing using the Team class.
"""
This example shows how to use Maxim to log agent calls and traces.

Steps to get started with Maxim:
1. Install Maxim: pip install maxim-py
2. Add instrument_agno(Maxim().logger()) to initialize tracing
3. Authentication:
 - Go to https://getmaxim.ai and create an account
 - Generate your API key from the settings
 - Export your API key as an environment variable:
    - export MAXIM_API_KEY=<your-api-key>
    - export MAXIM_LOG_REPO_ID=<your-repo-id>
4. All agent interactions will be automatically traced and logged to Maxim
"""

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.team.team import Team
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.yfinance import YFinanceTools

try:
    from maxim import Maxim
    from maxim.logger.agno import instrument_agno
except ImportError:
    raise ImportError(
        "`maxim` not installed. Please install using `pip install maxim-py`"
    )

# Instrument Agno with Maxim for automatic tracing and logging
instrument_agno(Maxim().logger())

# Web Search Agent: Fetches financial information from the web
web_search_agent = Agent(
    name="Web Agent",
    model=OpenAIChat(id="gpt-4o"),
    tools=[DuckDuckGoTools()],
    instructions="Always include sources",
    markdown=True,
)

# Finance Agent: Gets financial data using YFinance tools
finance_agent = Agent(
    name="Finance Agent",
    model=OpenAIChat(id="gpt-4o"),
    tools=[YFinanceTools()],
    instructions="Use tables to display data",
    markdown=True,
)

# Aggregate both agents into a multi-agent system
multi_ai_team = Team(
    members=[web_search_agent, finance_agent],
    model=OpenAIChat(id="gpt-4o"),
    instructions="You are a helpful financial assistant. Answer user questions about stocks, companies, and financial data.",
    markdown=True,
)

if __name__ == "__main__":
    print("Welcome to the Financial Conversational Agent! Type 'exit' to quit.")
    messages = []
    while True:
        print("********************************")
        user_input = input("You: ")
        if user_input.strip().lower() in ["exit", "quit"]:
            print("Goodbye!")
            break
        messages.append({"role": "user", "content": user_input})
        conversation = "\n".join(
            [
                ("User: " + m["content"])
                if m["role"] == "user"
                else ("Agent: " + m["content"])
                for m in messages
            ]
        )
        response = multi_ai_team.run(
            f"Conversation so far:\n{conversation}\n\nRespond to the latest user message."
        )
        agent_reply = getattr(response, "content", response)
        print("---------------------------------")
        print("Agent:", agent_reply)
        messages.append({"role": "agent", "content": str(agent_reply)})
agno.gif

Features

Observability & Tracing

Maxim provides comprehensive observability for your Agno agents:
  • Agent Tracing: Track your agent’s complete lifecycle, including tool calls, agent trajectories, and decision flows
  • Token Usage: Monitor prompt and completion token consumption
  • Model Information: Track which models are being used and their performance
  • Tool Calls: Detailed logging of all tool executions and their results
  • Performance Metrics: Latency, cost, and error rate tracking

Evaluation & Analytics

  • Auto Evaluations: Automatically evaluate captured logs based on filters and sampling
  • Human Evaluations: Use human evaluation or rating to assess log quality
  • Node Level Evaluations: Evaluate any component of your trace for detailed insights
  • Dashboards: Visualize traces over time, usage metrics, latency & error rates

Alerting

Set thresholds on error rates, cost, token usage, user feedback, and latency to get real-time alerts via Slack or PagerDuty.

Notes

  • Environment Variables: Ensure your environment variables are correctly set for the API key and repository ID.
  • Instrumentation Order: Call instrument_agno() before creating or executing any agents to ensure proper tracing.
  • Debug Mode: Enable debug mode to see detailed logging information:
    instrument_agno(Maxim().logger(), {"debug" : True})
    
  • Maxim Docs: For more information on Maxim’s features and capabilities, refer to the Maxim documentation.
By following these steps, you can effectively integrate Agno with Maxim, enabling comprehensive observability, evaluation, and monitoring of your AI agents.