The Problem
Running and managing LangGraph agents on an internal stack is difficult when the official LangSmith Deployments are locked into a cloud platform. Organizations need full control over persistence, authentication, and observability without vendor lock‑in.
What This Does
Aegra delivers a drop‑in replacement for LangSmith Deployments.
- The FastAPI backend in
libs/aegra-api/src/aegra_api/main.pyexposes the same REST endpoints that the LangGraph SDK expects, so existing agents continue to work unchanged. - Database schema migrations live in
libs/aegra-api/alembic/versions/…; the repo ships a PostgreSQL‑only persistence layer. - Custom authentication is wired through middleware in
libs/aegra-api/src/aegra_api/core/auth_middleware.py, allowing JWT or other handlers to be plugged in. - Observation hooks in
libs/aegra-api/src/aegra_api/observability/metrics.pyexpose Prometheus metrics, and the SSE framework inlibs/aegra-api/src/aegra_api/core/sse.pyimplements Agent Protocol v2 streaming.
How It Is Wired
Entry point → FastAPI app
libs/aegra-api/src/aegra_api/main.pyimportsapp_routerfromlibs/aegra-api/src/aegra_api/api/and mounts it on the FastAPI instance.- Each router module (
assistants.py,threads.py,runs.py, …) registers routes that call service classes inlibs/aegra-api/src/aegra_api/services/.
Service → ORM → Database
libs/aegra-api/src/aegra_api/services/assistant_service.pycallsAssistant.create()fromlibs/aegra-api/src/aegra_api/models/assistants.py.- The model uses SQLAlchemy declarative mappings defined in
libs/aegra-api/src/aegra_api/core/orm.py. - Calls ultimately hit the PostgreSQL session created in
libs/aegra-api/src/aegra_api/core/database.py.
Observability & Streaming
libs/aegra-api/src/aegra_api/core/sse.pyexposes a generator that yields SSE events.libs/aegra-api/src/aegra_api/services/event_streaming/native_stream.pyformats content‑block events for Agent Protocol v2.- Metrics are pushed from
services/assistant_service.pythrough themetricstarget inlibs/aegra-api/src/aegra_api/observability/targets/.
Lifecycle
- A run starts at the FastAPI route, enters the service layer, persists a
Runrecord, triggers the executor (services/executor.py), and streams back via SSE. - The whole flow touches only
main.py, the router, the service, the ORM, and the database: 5 distinct modules, with the router being the widest blast radius because it defines the API surface.
How To Use It
Setup
git clone https://github.com/moses-y/aegra
cd aegra
cp .env.example .env # set OPENAI_API_KEY and other vars
uv sync # install deps (uv from pyproject.toml)
Configuration
- Environment variables are listed in
.env.example. docker-compose.ymlstarts PostgreSQL and the FastAPI server;docker-compose.dev.ymladds a development overlay.
Running it
docker compose up
or via the CLI:
pip install aegra-cli
aegra init # scaffolds a new project
cd <project>
cp .env.example .env
uv sync
uv run aegra dev # starts dev server + DB
Calling the API
from langgraph_sdk import get_client
client = get_client(url="http://localhost:2026")
assistant = await client.assistants.create(graph_id="agent")
thread = await client.threads.create()
async for chunk in client.runs.stream(
thread_id=thread["thread_id"],
assistant_id=assistant["assistant_id"],
input={"messages": [{"type":"human","content":"Hi!"}]},
):
print(chunk)
Real-World Use
A data‑science team can spin up an on‑premise Aegra instance, add custom JWT auth via auth_registry.py, and run LangGraph agents that ingest internal data pipelines. The same SDK code that talks to LangSmith now talks to http://<host>:2026.
Code Health & Issues
- Low (Non‑reproducible builds) –
libs/aegra-api/pyproject.tomldeclares dependencies without a lockfile. - 233 test files – tests are present in
tests/and are run in CI. - CI –
/.github/workflows/ci.ymlruns unit tests and linting. - License – MIT, see
LICENSE.
No critical security or linting failures were detected in the static analysis run.
The Bottom Line
Aegra is a solid, well‑structured self‑hosted alternative to LangSmith Deployments. It preserves API compatibility, offers full control over persistence and auth, and ships with streaming support out of the box. The code base is mature, with a clear separation of concerns, but the absence of a dependency lockfile means builds can drift. It is suitable for teams that need on‑premise control and are comfortable managing a PostgreSQL backend.