A Pydantic AI agent that remembers across sessions, can create its own tools, and delegates to specialists
Project description
Long Running Agents
A Pydantic AI agent that remembers across sessions, can create its own tools, and delegates to specialists. Memory, sandbox, and tasks in one stack.
Why this exists
Problem: Most agents forget between runs. They can't recall past conversations, and they can't extend their own tool set.
Solution: Long Running Agents gives you persistent memory (SQLite + ChromaDB), cross-session recall, and dynamic tool generation—so your agent remembers, learns, and adapts over time.
Audience: Developers building long-lived, memory-aware agents with Pydantic AI.
What makes it different
| Feature | What it does | Why it stands out |
|---|---|---|
| Cross-session memory | get_recent_conversations(all_sessions=True) + search_memory |
Most agents forget between runs. This one recalls past turns across sessions. |
| Dynamic tool generation | Agent creates new tools at runtime via generate_tool |
Extends its own tool set with AST validation and persistence. |
| Subagent delegation | Code and research specialists | Routes work to focused subagents instead of one monolithic agent. |
| Hybrid retrieval | Vector + keyword module | Optional hybrid search (semantic + keyword) available in the memory layer. |
| Pydantic AI | Typed agent framework | Uses Pydantic AI instead of LangChain/LlamaIndex. |
| Sandbox + memory + tasks | All in one stack | Memory, code execution, and task tracking in a single package. |
What it is (and isn't)
- Is: A chat-driven AI agent with persistent memory, code execution, and task tracking. You interact via a terminal loop; the agent responds using its tools; context is saved across runs.
- Isn't: A workflow automation engine. No schedules, triggers, or DAGs. It's an interactive assistant, not Zapier or Airflow.
Install
Prerequisites: Python 3.10+, OpenAI API key
# From PyPI
pip install long-running-agents
# From GitHub
pip install git+https://github.com/prith27/lra.git
# From source (clone first)
git clone https://github.com/prith27/lra.git
cd lra
pip install -e .
Quick start
export OPENAI_API_KEY=sk-your-key-here # or use lra init to create .env
lra chat
Or run lra init first to create a .env file and see setup instructions.
Note: Basic chat and memory work without the sandbox. For code execution or dynamic tool creation, start the sandbox first in a separate terminal (see Sandbox).
How it works
- Run
lra chatto start the chat loop. - Type a message; the agent may call tools (search memory, run code, create tasks, delegate to subagents).
- Each turn is persisted to SQLite and ChromaDB so the agent can recall past context in future runs.
- Each run gets a new session ID, but
get_recent_conversations(all_sessions=True)andsearch_memoryallow cross-session recall.
Agent tools
| Tool | Purpose |
|---|---|
search_memory |
Semantic search over past summaries and facts (ChromaDB) |
write_memory |
Store facts or summaries for later recall |
get_recent_conversations |
Fetch recent turns (session or all sessions) |
create_task, update_task_status, list_tasks |
Track multi-step work |
create_sandbox, execute_code |
Run Python in isolated containers |
delegate_code_task, delegate_research_task |
Hand off to specialist subagents |
generate_tool |
Create new tools at runtime when no existing tool fits |
Library usage
import asyncio
from long_running_agents import run_agent, AgentDeps, StructuredMemoryStore, VectorMemoryStore
from config import SANDBOX_URL
async def main():
structured = StructuredMemoryStore()
vector = VectorMemoryStore()
await structured.init_db()
deps = AgentDeps(
session_id="my-session",
structured_store=structured,
vector_store=vector,
sandbox_base_url=SANDBOX_URL,
)
output, messages = await run_agent("What can you do?", deps)
print(output)
await structured.close()
asyncio.run(main())
CLI
lra init # Create .env and show setup instructions
lra chat # Start the agent chat loop
lra list-tools # List static and dynamic tools
lra inspect-tool X # Inspect a dynamic tool
lra list-memory -s SESSION # List memory for a session
Configuration
| Variable | Description | Default |
|---|---|---|
| OPENAI_API_KEY | OpenAI API key | (required) |
| SANDBOX_URL | Sandbox API base URL | http://localhost:8000 |
| DATABASE_URL | SQLAlchemy async URL | sqlite+aiosqlite:///./data/agent_memory.db |
| VECTOR_STORE_PATH | ChromaDB path | ./data/chroma_db |
Sandbox (optional)
The sandbox enables code execution and tool validation. It includes requests and httpx for HTTP-fetching tools. Basic chat and memory work without it.
Prerequisites: Docker must be installed and running. The sandbox spawns isolated containers for code execution.
Run order
Start the sandbox before using code execution or creating tools. Run it in a separate terminal from lra chat.
# Terminal 1: Start sandbox (keep running)
python -m uvicorn sandbox.server:app --reload --port 8000
# Terminal 2: Run agent
lra chat
Options
| Option | Command | When to use |
|---|---|---|
| A: Local | python -m uvicorn sandbox.server:app --reload --port 8000 |
Development; run from project root with deps installed |
| B: Docker Compose | docker compose up sandbox |
Fully containerized; no local Python needed for sandbox |
First run
On first start, the kernel image (longrunningagents-kernel:latest) is built automatically. This may take a minute.
Rebuild kernel
If you updated sandbox/Dockerfile (e.g. added packages), rebuild the kernel:
docker rmi longrunningagents-kernel:latest
# Then restart the sandbox
Project structure
├── agents/ # Main agent and subagents
├── tools/ # Memory, sandbox, task tools
├── sandbox/ # Sandbox API and kernel
├── memory/ # Structured and vector stores
├── schemas/ # Pydantic models
├── long_running_agents/ # Package exports
├── cli.py # CLI entry point
├── config.py
├── main.py
└── pyproject.toml
Development
pip install -e ".[dev]"
pytest tests/ -v
mypy agents tools memory schemas
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file long_running_agents-0.1.1.tar.gz.
File metadata
- Download URL: long_running_agents-0.1.1.tar.gz
- Upload date:
- Size: 27.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e350905a622b8b58962ee90ebade112f0eca8780ca73780b90fb9154415ab7f7
|
|
| MD5 |
ee1e5d023ca0f43ce2330e5a8b4ad8d6
|
|
| BLAKE2b-256 |
fbea905b670f15ab773105fe37752b9b1dcf1ebc361ced1072e839b0838300d7
|
File details
Details for the file long_running_agents-0.1.1-py3-none-any.whl.
File metadata
- Download URL: long_running_agents-0.1.1-py3-none-any.whl
- Upload date:
- Size: 32.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6755a32eef97eb0a87ef0b0c25eb6515119a5d1fb9692f0d4bf421668a6bea2
|
|
| MD5 |
ec518b6a451384369e621b77b4373b8e
|
|
| BLAKE2b-256 |
65de689cda5be6213e37fc273e549c1df22d238717ddb35b9c8cc51427c24ba9
|