aegra.json) to define graphs, authentication, HTTP settings, the semantic store, and checkpointer settings (thread TTL and the default checkpoint durability).
Config file resolution
Aegra resolves configuration files in this order:AEGRA_CONFIGenvironment variable — absolute or relative pathaegra.jsonin the current working directorylanggraph.jsonin the current working directory (compatibility fallback)
Complete example
dependencies
Add shared utility module paths to sys.path before graphs are loaded.
- Relative paths are resolved from the config file’s directory
- Paths are added in order (first has highest import priority)
- Non-existent paths generate a warning but don’t prevent startup
graphs
Define your LangGraph agents.
The variable can be:
- A compiled graph — result of
builder.compile()(static, cached once at startup) - A 0-arg callable — called once at startup to produce the graph (e.g., for MCP adapter setup)
- A factory function — called per-request with
configand/orServerRuntimeto produce a graph customized for the current user or request context
Static graphs
Factory graphs
Export a callable that acceptsconfig (a RunnableConfig dict), runtime (a ServerRuntime), or both:
def graph()— 0-arg, called once at startupdef graph(config: dict)— receives theRunnableConfigper-requestdef graph(runtime: ServerRuntime)— receives runtime with user, store, and access contextdef graph(config: dict, runtime: ServerRuntime)— receives both (any parameter order)
Typed context with Runtime[T] (node-level)
When a run is created with a context dict, Aegra passes it to graph.astream(context=...). LangGraph core coerces it to a typed object and injects it into nodes via Runtime[T]. This works for both static and factory graphs:
BaseModel and dataclass types are both supported. Declare context_schema= on StateGraph and add a runtime: Runtime[T] parameter to any node that needs it.
Factory-level context with ServerRuntime[T]
For factory graphs, ServerRuntime[T] provides typed context at graph-build time — before execution starts. Use this for structural decisions that change the graph topology (adding/removing nodes, selecting tools, managing resource lifecycle):
runtime.execution_runtime to check whether the factory is being called for actual execution (returns the execution runtime with .context) or for introspection like schema extraction (returns None).
When to use which:
For a complete example combining both layers, see
examples/factory/.
auth
Configure authentication and authorization.
The
path supports multiple formats:
./auth.py:auth— Load from a file relative to the config./src/auth/jwt.py:auth— Nested pathmypackage.auth:auth— Load from an installed package
auth is not configured, Aegra runs in no-auth mode where all requests are allowed.
See authentication guide for details.
http
Configure custom routes and CORS.
When
allow_origin_regex is non-null, it is passed to Starlette’s CORSMiddleware and matched against the complete origin. If allow_origins is also provided, either the list or regex can authorize an origin. An explicit allow_origins: ["*"] remains a wildcard. An empty string still counts as configured; it does not match normal non-empty origins.
Note: the allow_credentials default only recognizes an exact ["*"] or "*". A wildcard mixed with other concrete origins (e.g. ["*", "https://example.com"]) currently still defaults allow_credentials to true, even though Starlette treats that list as allow-all — tracked in #633. Set allow_credentials explicitly if you use a mixed list.
See custom routes guide for details.
store
Configure semantic store with vector embeddings.
If
store is not configured, Aegra operates in basic key-value mode.
See semantic store guide for details.
checkpointer
Configure thread retention (TTL) and the default checkpoint durability.
ttl
When a ttl block is present, every newly created thread gets an expiry, and
a background sweep deletes or compacts expired threads.
Notes:
- Threads with pending or running runs are skipped and swept once their runs settle.
- Deleting an expired thread cascades to its runs and thread-bound crons.
- Individual threads can override the default via the
ttlfield onPOST /threads; expired threads can be cleaned immediately withPOST /threads/prune. See the threads guide. - The
AEGRA_THREAD_TTLenvironment variable replaces this block entirely when set — see environment variables.
checkpointer.ttl nor AEGRA_THREAD_TTL is configured, threads never expire.
durability
Sets when checkpoints are written for runs that do not choose a mode themselves.
Resolution order for each run:
- The run’s
durabilityfield (or the deprecatedcheckpoint_during). - The
AEGRA_CHECKPOINT_DURABILITYenvironment variable. checkpointer.durabilityinaegra.json.- LangGraph’s default.