Skip to main content
This tutorial takes you from zero to a working agent with tool use, streaming, and state persistence. By the end, you’ll have a running Aegra server with an agent you can talk to through the SDK and any Agent Protocol frontend.

What you’ll build

A ReAct agent that can search the web and hold multi-turn conversations with full state persistence. You’ll learn how to:
  • Scaffold a project with the CLI
  • Write a LangGraph agent
  • Register it as an assistant
  • Create threads and run conversations
  • Stream responses in real time
  • Inspect thread state and history

Prerequisites

  • Python 3.12+
  • Docker (for PostgreSQL)
  • An OpenAI API key

Step 1: Create the project

When prompted, choose the react-agent template. Then configure your environment:
Open .env and set your OPENAI_API_KEY.

Step 2: Understand the project structure

The CLI generated this structure:
The key file is aegra.json, which tells Aegra where to find your graph:
The "agent" key is your graph ID — you’ll use it when creating assistants.

Step 3: Start the server

This starts PostgreSQL in Docker, runs migrations, and launches the server with hot reload. You should see:
Visit http://localhost:2026/docs to see all available endpoints.

Step 4: Create an assistant

An assistant is a configured instance of a graph. You create one via the SDK:
Aegra also creates a default assistant for each graph on startup, so you can skip this step and use the graph ID directly in runs and crons.

Step 5: Create a thread and run a conversation

A thread represents a conversation. Each run executes the agent within a thread, and state is persisted between runs.
The agent processes your message, potentially uses tools, and streams the response back as Server-Sent Events.

Step 6: Continue the conversation

Because state is persisted in the thread, you can send follow-up messages:
The agent has full access to the conversation history from the thread’s checkpoint.

Step 7: Inspect thread state

You can inspect the full state of any thread at any point:

Step 8: Connect a frontend

Your server implements the Agent Protocol, so you can connect any compatible frontend. Try Agent Chat UI:
Open http://localhost:5173, point it at http://localhost:2026, and you have a full chat interface.

What’s next

You’ve got a working agent with persistence, streaming, and tool use. Here’s where to go from here:

Human-in-the-loop

Add approval gates before tool execution.

Streaming

Understand stream modes and reconnection.

Authentication

Add JWT, OAuth, or Firebase auth.

Deployment

Deploy to Docker, PaaS, or Kubernetes.