Agent API Cookiecutter

repository·main·Indexed 41 days ago

https://github.com/neural-maze/agent-api-cookiecutter

A Cookiecutter template for scaffolding projects following the 'agent-api' pattern. It provides a standardized structure for building agent-based APIs using FastAPI, pydantic-settings, and uvicorn, featuring endpoints for chat, evaluation, document ingestion, and memory management. Version 0.1.0 includes Docker Compose configuration and OpenAI API integration.

Tokens
919
Snippets
5
Records
7
Agent score
100%

What's inside Agent API Cookiecutter

  1. Configure application settings via environment variables and .env files

    main

    The application uses pydantic-settings to manage configuration. Settings are loaded from environment variables or a .env file located in the project root. The Settings class is instantiated as a singleton named settings and can be imported throughout the package to access configuration values.

    To customize settings, you can define a .env file in your project directory. The configuration is set to ignore extra environment variables that are not explicitly defined in the Settings class.

    from {{cookiecutter.project_slug}}.config import settings
    
    # Accessing a setting (assuming 'API_KEY' was defined in Settings)
    api_key = settings.API_KEY
  2. Configure the agent-api service with docker-compose.yaml

    main

    The docker-compose.yaml file defines the deployment configuration for the agent-api service. By default, it maps port 8000 on the host to port 8000 in the container and loads environment variables from a .env file located in the project root. The service is built from the local Dockerfile and is attached to a dedicated network named {{ cookiecutter.package_name }}-network.

    services:
      agent-api:
        container_name: {{ cookiecutter.package_name }}
        build:
          context: .
          dockerfile: Dockerfile
        ports:
          - "8000:8000"
        env_file:
          - .env
        networks:
          - {{ cookiecutter.package_name }}-network
    
    volumes:
      data:
    
    networks:
      {{ cookiecutter.package_name }}-network:
        name: {{ cookiecutter.package_name }}-network
  3. Use the Agent API endpoints

    main

    The Agent API provides several POST endpoints to interact with the agent's core services: chat, evaluation, document ingestion, and memory management. The API is built with FastAPI and includes an interactive documentation page at /docs.

    # Example endpoint interactions (conceptual):
    
    # Chat with the agent
    POST /chat
    Payload: ChatRequest
    
    # Evaluate the agent
    POST /eval
    Payload: EvalRequest
    
    # Ingest documents into the agent's knowledge base
    POST /eval
    Payload: IngestDocumentsRequest
    
    # Reset the agent's memory
    POST /reset-memory
    Payload: ResetMemoryRequest