Agent API Cookiecutter
repository·main·Indexed 41 days ago
https://github.com/neural-maze/agent-api-cookiecutterA 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.
What's inside Agent API Cookiecutter
- {{ cookiecutter.project_short_description }}
Access API documentation
mainOnce the server is running, you can access the interactive Swagger/OpenAPI documentation at the/docsURL to explore and test the available endpoints.Configure the OpenAI API Key
mainSet the
OPENAI_API_KEYenvironment variable to provide authentication for OpenAI services used by the agent API. This key is required for making requests to OpenAI models.OPENAI_API_KEY=Configure application settings via environment variables and .env files
mainThe application uses
pydantic-settingsto manage configuration. Settings are loaded from environment variables or a.envfile located in the project root. TheSettingsclass is instantiated as a singleton namedsettingsand can be imported throughout the package to access configuration values.To customize settings, you can define a
.envfile in your project directory. The configuration is set to ignore extra environment variables that are not explicitly defined in theSettingsclass.from {{cookiecutter.project_slug}}.config import settings # Accessing a setting (assuming 'API_KEY' was defined in Settings) api_key = settings.API_KEYConfigure the agent-api service with docker-compose.yaml
mainThe
docker-compose.yamlfile defines the deployment configuration for theagent-apiservice. By default, it maps port8000on the host to port8000in the container and loads environment variables from a.envfile located in the project root. The service is built from the localDockerfileand 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 }}-networkRun the Agent API server
mainThe API can be started directly using Python if the file is executed as a script. It uses
uvicornto serve the FastAPI application on0.0.0.0:8000by default.python src/{{cookiecutter.project_slug}}/infrastructure/api/main.pyUse the Agent API endpoints
mainThe 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