activegraph
A persistent world for long-running agents.
A shared graph of beliefs, tasks, evidence, decisions, and dependencies — derived from an append-only event log. Replay, fork, and diff any run.
From Yohei Nakajima, creator of BabyAGI (2023). activegraph is the architectural answer that years of agent infrastructure work kept pointing toward.
from activegraph import Graph, Runtime, behavior, relation_behavior
graph = Graph()
runtime = Runtime(graph, budget={"max_events": 200, "max_seconds": 60})
# Behaviors react to events and write back to the graph.
@behavior(name="planner", on=["goal.created"])
def planner(event, graph, ctx):
research = graph.add_object("task", {"title": "Research", "status": "open"})
memo = graph.add_object("task", {"title": "Draft memo", "status": "blocked"})
graph.add_relation(research.id, memo.id, "depends_on")
# Edges carry logic. This one knows how to unblock its target.
@relation_behavior(name="unblock", relation_type="depends_on", on=["task.completed"])
def unblock(relation, event, graph, ctx):
if event.payload["task_id"] == relation.source:
graph.patch_object(relation.target, {"status": "open"})
runtime.run_goal("Evaluate this idea")
runtime.print_trace()
# Fork the run at any historical event. The shared prefix
# replays from cache — no duplicate LLM calls.
fork = runtime.fork(at_event=4)
The differentiated primitive. Coordination logic lives on the edge, where the meaning is — not duplicated across every node that might emit a relevant event.
Branches the run. The shared prefix replays from cache. Forks don't re-pay for LLM calls already made.
// Try it through your AI assistant
Paste this into Claude, ChatGPT, or your coding agent.
ActiveGraph is designed to be learned by agents as well as humans. The docs, quickstart, trace, and fork/diff primitives give an assistant enough structure to build something real in minutes — not just agent-legible infrastructure, but infrastructure that an agent can pick up and use.
Look up activegraph.ai and docs.activegraph.ai.
Install the activegraph Python package.
Build and run a small experiment that shows why an
event-sourced reactive graph is useful.
Use fork/diff or replay if possible.
Explain what happened and what the trace proves.Works with any agent that can read a webpage, install a pip package, and run Python.
// Agents need more than memory
The event log is the agent. The graph is its world.
Memory
Stores what an agent might want to recall.
Workflows
Define what should happen next.
Logs
Record what happened afterward.
ActiveGraph
Collapses these into one substrate: an append-only event log projected into a live graph. The graph is the agent's world — what exists, what depends on what, what was produced, what was approved, what changed, and why.
// Where it fits
Not another agent framework. The world beneath one.
Bring your model, tools, prompts, and workflows. ActiveGraph gives them durable state.
Workflows model computation. ActiveGraph models the world that computation acts on. Memory remembers conversations. ActiveGraph holds beliefs, evidence, contradictions, decisions, and their lineage.
ActiveGraph is where agent state becomes inspectable infrastructure.
- ModelsReasoning and generation
- Tool frameworksCalling external systems
- WorkflowsSequencing work
- MemoryRetrieval and recall
- ActiveGraphthis layerThe shared world: objects, relations, events, lineage, replay, forks, diffs
// What you can build
Primitives the loop doesn't give you.
Replay, fork, diff, lineage, edge logic — concrete things that become possible once the event log is the substrate, not a debugging artifact.
Auditable agents
Every object, claim, decision, and tool result traces back to the event that created it.
Forkable runs
Ask “what if we changed the threshold, policy, prompt, model, or approval rule?” without destroying the original run.
Reactive systems
Behaviors fire when the graph changes. Coordination happens through shared state, not brittle chains of direct calls.
Edges with meaning
A depends_on, contradicts, supports, or blocks relation can carry behavior. Logic lives where the meaning is.
Long-running operating memory
Not a summary of past chat. A durable graph of what the system believes, what it is doing, and why.
// Research basis
The Log is the Agent.
ActiveGraph is introduced in The Log is the Agent: Event-Sourced Reactive Graphs for Auditable, Forkable Agentic Systems. The core claim: the event log should not be a debugging artifact. It should be the substrate the agent is built from. The graph is a deterministic projection of that log — replay, fork, diff, and end-to-end lineage fall out of the architecture, not an audit layer bolted on top.
Worked example
- 01Write a behavior. Save a run. Inspect it externally.
- 02Fork the run at any historical event. Diff the result against the parent.
- 03Explain where every object in the graph came from — the event, the behavior, the evidence, the LLM call.
Reproduce with activegraph quickstart.
// Learn
From LLM loops to living graphs.
Interactive tutorials for activegraph — the persistent world for long-running agents. Start with the mental model, then build. Same model, tools, and prompts; durable, replayable state underneath.
From LLM Loops to Living Graphs
Take the familiar LLM agent loop, see why it breaks, then refactor it into activegraph one substitution at a time. The core mental model, end to end.
~45 min · 11 lessons · Beginner → Intermediate
- mental model
- refactor
- start here
The ReAct Deep-Research Agent
Build the research agent everyone has built — reason, search, observe — then watch it change on activegraph: full provenance, surfaced contradictions, and a forkable conclusion.
~50 min · 11 lessons · Intermediate
- research
- web search
- provenance
// Example · BabyAGI, rewritten
BabyAGI, as an active graph.
The original BabyAGI (Nakajima, 2023) was a while-true loop with three steps: execute the current task, summarize against the objective, generate follow-ups. State lived in a global list.
This rewrite expresses the same loop as reactive behaviors over a shared graph. The loop IS event propagation. The graph IS the state. Every step is a subscription, not a function call; the trace records every mutation and is queryable after the run.
It's a download-and-run-it-yourself example in the OSS repo — not a bundled pack. Three behaviors: initializer → executor → task_creator, wired by events.
git clone https://github.com/yoheinakajima/activegraph
cd activegraph && pip install -e .
export ANTHROPIC_API_KEY=...
python examples/babyagi.py "Plan a 3-day intro to Rust"@behavior(name="initializer", on=["goal.created"])
def initializer(event, graph, ctx):
goal = event.payload["goal"]
graph.add_object("task", {"title": f"Plan first step toward: {goal}",
"status": "pending"})
@llm_behavior(name="executor", on=["object.created"],
where={"object.type": "task"}, output_schema=TaskResult)
def executor(event, graph, ctx, llm_output: TaskResult):
task = event.payload["object"]
graph.patch_object(task["id"], {"status": "completed"})
graph.emit("task.executed", {"task_id": task["id"],
"result": llm_output.result})
@llm_behavior(name="task_creator", on=["task.executed"],
output_schema=NewTasks)
def task_creator(event, graph, ctx, llm_output: NewTasks):
for title in llm_output.tasks:
graph.add_object("task", {"title": title, "status": "pending"})Three behaviors. The graph queues itself; the event log is the order; an empty follow-up list terminates the loop.