Skip to main content

Aegra core API - Self-hosted Agent Protocol server

Project description

aegra-api

Aegra API - Self-hosted Agent Protocol server.

Aegra is an open-source, self-hosted alternative to LangGraph Platform. This package provides the core API server that implements the Agent Protocol, allowing you to run AI agents on your own infrastructure without vendor lock-in.

Features

  • Agent Protocol Compliant: Works with Agent Chat UI, LangGraph Studio, CopilotKit
  • Drop-in Replacement: Compatible with the LangGraph SDK
  • Self-Hosted: Run on your own PostgreSQL database
  • Streaming Support: Real-time streaming of agent responses
  • Human-in-the-Loop: Built-in support for human approval workflows
  • Vector Store: Semantic search capabilities with PostgreSQL

Installation

pip install aegra-api

Quick Start

The easiest way to get started is with the aegra-cli:

# Install the CLI
pip install aegra-cli

# Initialize a new project
aegra init --docker

# Start services
aegra up

# Apply migrations
aegra db upgrade

# Start development server
aegra dev

Manual Setup

If you prefer manual setup:

# Install dependencies
pip install aegra-api

# Set environment variables
export POSTGRES_USER=aegra
export POSTGRES_PASSWORD=aegra_secret
export POSTGRES_HOST=localhost
export POSTGRES_DB=aegra

# Run migrations
alembic upgrade head

# Start server
uvicorn aegra_api.main:app --reload

Configuration

aegra.json

Define your agent graphs in aegra.json:

{
  "graphs": {
    "agent": "./graphs/my_agent/graph.py:graph",
    "assistant": "./graphs/assistant/graph.py:graph"
  },
  "http": {
    "app": "./custom_routes.py:app"
  }
}

Environment Variables

# Database
POSTGRES_USER=aegra
POSTGRES_PASSWORD=aegra_secret
POSTGRES_HOST=localhost
POSTGRES_DB=aegra

# Authentication
AUTH_TYPE=noop  # Options: noop, custom

# Server
HOST=0.0.0.0
PORT=8000

# Configuration
AEGRA_CONFIG=aegra.json

# LLM (for example agents)
OPENAI_API_KEY=sk-...

# Observability (optional)
OTEL_TARGETS=LANGFUSE,PHOENIX

API Endpoints

Endpoint Method Description
/assistants POST Create assistant from graph_id
/assistants GET List user's assistants
/assistants/{id} GET Get assistant details
/threads POST Create conversation thread
/threads/{id}/state GET Get thread state
/threads/{id}/runs POST Execute graph (streaming/background)
/runs/{id}/stream POST Stream run events
/store PUT Save to vector store
/store/search POST Semantic search
/health GET Health check

Creating Graphs

Agents are Python modules exporting a compiled graph variable:

# graphs/my_agent/graph.py
from typing import TypedDict
from langgraph.graph import StateGraph, START, END

class State(TypedDict):
    messages: list[str]

def process_node(state: State) -> State:
    messages = state.get("messages", [])
    messages.append("Processed!")
    return {"messages": messages}

# Build the graph
builder = StateGraph(State)
builder.add_node("process", process_node)
builder.add_edge(START, "process")
builder.add_edge("process", END)

# Export as 'graph'
graph = builder.compile()

Architecture

+---------------------------------------------------------+
|  FastAPI HTTP Layer (Agent Protocol API)                |
|  - /assistants, /threads, /runs, /store endpoints       |
+---------------------------------------------------------+
|  Middleware Stack                                        |
|  - Auth, CORS, Structured Logging, Correlation ID       |
+---------------------------------------------------------+
|  Service Layer (Business Logic)                          |
|  - LangGraphService, AssistantService, StreamingService |
+---------------------------------------------------------+
|  LangGraph Runtime                                       |
|  - Graph execution, state management, tool execution    |
+---------------------------------------------------------+
|  Database Layer (PostgreSQL)                             |
|  - AsyncPostgresSaver (checkpoints), AsyncPostgresStore |
+---------------------------------------------------------+

Package Structure

libs/aegra-api/
├── src/aegra_api/
│   ├── api/              # Agent Protocol endpoints
│   │   ├── assistants.py # /assistants CRUD
│   │   ├── threads.py    # /threads and state management
│   │   ├── runs.py       # /runs execution and streaming
│   │   └── store.py      # /store vector storage
│   ├── services/         # Business logic layer
│   ├── core/             # Infrastructure (database, auth, orm)
│   ├── models/           # Pydantic request/response schemas
│   ├── middleware/       # ASGI middleware
│   ├── observability/    # OpenTelemetry tracing
│   ├── utils/            # Helper functions
│   ├── main.py           # FastAPI app entry point
│   ├── config.py         # HTTP/store config loading
│   └── settings.py       # Environment settings
├── tests/                # Test suite
├── alembic/              # Database migrations
└── pyproject.toml

Related Packages

  • aegra-cli: Command-line interface for project management
  • aegra: Meta-package that installs both aegra-api and aegra-cli

Documentation

For full documentation, see the CLAUDE.md file in the repository root.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aegra_api-0.1.0.tar.gz (353.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aegra_api-0.1.0-py3-none-any.whl (98.5 kB view details)

Uploaded Python 3

File details

Details for the file aegra_api-0.1.0.tar.gz.

File metadata

  • Download URL: aegra_api-0.1.0.tar.gz
  • Upload date:
  • Size: 353.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aegra_api-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2ff6677d9b7bc3709690f7c9ae0823cad32eecb359c16946e6d81cc841031bfe
MD5 164e842f4df75f03a8d17c50d1c5113c
BLAKE2b-256 3395eede6cddea384a4b7fea68b5b52f180511c5b36dad68d2e99952c8e0a31a

See more details on using hashes here.

File details

Details for the file aegra_api-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: aegra_api-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 98.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aegra_api-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c98b4ebb098fd6cc03268747321f9dc1175ef0e2ebebfa760d13c00371ef6679
MD5 a365206786253fec4264f98be8e5ff70
BLAKE2b-256 a8164faf5240bea65d44a9c5b79d5ef22e9385d72ad81f74cc95b8eaf12965fa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page