Agno Agent API

repository·main·Indexed 43 days ago

https://github.com/agno-agi/agent-api

A production-ready framework for serving AI Agents as an API, combining a FastAPI server with a PostgreSQL backend to manage agent sessions, knowledge bases, and memories. Version 0.1.0 includes prebuilt agents for web search, finance, and Agno assistance, and supports deployment via Docker.

Tokens
1.6K
Snippets
7
Records
9
Agent score
56%

What's inside Agno Agent API

  1. Explore Prebuilt Agents

    main

    The /agents folder contains several pre-configured agents:

    • Web Search Agent: Performs web searches.
    • Agno Assist: Answers questions about Agno. Important: You must load the agno_assist knowledge base via the API before use. The endpoint is: POST /agents/{agent_id}/knowledge/load.
    • Finance Agent: Uses the YFinance API for stock prices and financial data.
  2. Quickstart: Run the Agent API with Docker

    main

    To get the Agent API running locally, ensure Docker Desktop is installed and running. Follow these steps:

    1. Clone the repository:
      git clone https://github.com/agno-agi/agent-api.git
      cd agent-api
    2. Configure API keys: The default model is GPT 4.1. Export your OPENAI_API_KEY:
      export OPENAI_API_KEY="YOUR_API_KEY_HERE"
      Note: You can use other providers by updating the agents in the /agents folder.
    3. Start the application:
      docker compose up -d

    This starts a FastAPI server at http://localhost:8000 and a PostgreSQL database at localhost:5432. You can view the API documentation at http://localhost:8000/docs.

    git clone https://github.com/agno-agi/agent-api.git
    cd agent-api
    export OPENAI_API_KEY="YOUR_API_KEY_HERE"
    docker compose up -d
  3. Manage Python Dependencies

    main

    To add or update dependencies in the development environment and ensure they are included in the Docker image:

    1. Modify pyproject.toml: Add or update packages in the [dependencies] section.
    2. Regenerate requirements.txt: This file is required for the Docker build process.
      ./scripts/generate_requirements.sh
      To upgrade all existing dependencies to their latest compatible versions:
      ./scripts/generate_requirements.sh upgrade
    3. Rebuild Docker images:
      docker compose up -d --build
    ./scripts/generate_requirements.sh
    ./scripts/generate_requirements.sh upgrade
    docker compose up -d --build
  4. Development Setup: Local Virtual Environment

    main

    For local development, use uv for package management.

    1. Install uv (Unix-like systems):
      curl -LsSf https://astral.sh/uv/install.sh | sh
    2. Create environment and install dependencies:
      ./scripts/dev_setup.sh
    3. Activate the environment:
      source .venv/bin/activate
      (On Windows, use .venv\Scripts\activate)
    curl -LsSf https://astral.sh/uv/install.sh | sh
    ./scripts/dev_setup.sh
    source .venv/bin/activate
  5. Deploy to Production

    main

    The project includes a Dockerfile for production-ready container images.

    Build and Push Image

    1. Update scripts/build_image.sh with your desired IMAGE_NAME and IMAGE_TAG.
    2. Run the build script:
      ./scripts/build_image.sh

    Deployment Considerations

    • Environment Variables: Securely manage OPENAI_API_KEY and database connection strings in your cloud provider.
    • Database: In production, replace the local PostgreSQL container with a managed service (e.g., AWS RDS, Google Cloud SQL, Azure Database for PostgreSQL).
    • Port Mapping: The application runs on port 8000 inside the container.
    • Supported Platforms: Works with Serverless Container Platforms (Google Cloud Run, AWS App Runner, Azure Container Apps), Orchestration (GKE, ECS, AKS), or PaaS (Railway, Render, Heroku).
    ./scripts/build_image.sh
  6. Configure the pgvector database service

    main

    The pgvector service provides a PostgreSQL instance with the pgvector extension, which is used for storing vector embeddings. It is configured via the following environment variables:

    • POSTGRES_USER: The database user (defaults to ai).
    • POSTGRES_PASSWORD: The database password (defaults to ai).
    • POSTGRES_DB: The database name (defaults to ai).

    Data is persisted in the pgdata volume.

    services:
      pgvector:
        image: agnohq/pgvector:16
        environment:
          POSTGRES_USER: ${DB_USER:-ai}
          POSTGRES_PASSWORD: ${DB_PASSWORD:-ai}
          POSTGRES_DB: ${DB_NAME:-ai}
  7. Configure the Agent API via environment variables

    main

    The Agent API service uses several environment variables for configuration. When running via Docker Compose, you can set these in your shell or a .env file.

    Database Configuration

    • DB_USER: The username for the PostgreSQL database (defaults to ai).
    • DB_PASSWORD: The password for the PostgreSQL database (defaults to ai).
    • DB_NAME: The name of the database (defaults to ai).
    • DB_HOST: Set to pgvector by default to connect to the internal service.
    • DB_PORT: Set to 5432 by default.

    AI Provider Configuration

    • OPENAI_API_KEY: Required to authenticate with OpenAI services.

    Monitoring and Debugging

    • AGNO_MONITOR: Enables monitoring (set to True).
    • AGNO_API_KEY: The API key for Agno monitoring services.
    • WAIT_FOR_DB: Set to True to ensure the API waits for the pgvector service to be ready.
    • PRINT_ENV_ON_LOAD: Set to True to print environment variables to the logs upon startup for debugging.
    # Example .env file configuration
    OPENAI_API_KEY=sk-...
    AGNO_API_KEY=agno_...
    DB_USER=admin
    DB_PASSWORD=secret_pass
    DB_NAME=agno_db
  8. Initialize the Agent API with create_app()

    main

    The create_app() function is the factory used to instantiate the FastAPI application. It configures the application title and version from api_settings, sets up the /v1 router, and enables CORS middleware based on the api_settings.cors_origin_list.

    If api_settings.docs_enabled is true, the application automatically exposes interactive documentation at /docs (Swagger UI), /redoc (ReDoc), and the OpenAPI schema at /openapi.json.

    from api.main import create_app
    
    app = create_app()