Skip to content

About

StateGraph — semantic state provenance for AI agents: which evidence changed the agent's state, and which decisions depended on it. Part of RLRA.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

This repository is part of the Reliable Long-Running Agents (RLRA) research initiative.

StateGraph

A semantic debugger for long-running AI agents.

status: research prototype

StateGraph helps you understand why an agent made a decision — even when the execution trace looks completely correct.

The problem

Your agent tells you to leave home for a meeting that was cancelled an hour ago. Every tool call succeeded; the execution trace looks perfect. But the agent acted on a belief that had already gone stale — and the trace can't show you that. It records what happened, not why the decision was justified.

                Agent Run
                     │
        ┌────────────┴────────────┐
        │                         │
 Operational Trace         Semantic State
        │                         │
  What happened?          Why is it believed?
        │                         │
    AgentTrace              StateGraph

Two commands

stategraph inspect run.yaml     # what does the agent believe now — and what became obsolete?
stategraph explain run.yaml D1  # why does this decision exist — and is it still valid?

Debug a semantic failure

The calendar said the meeting was cancelled. The agent still told you to leave. Run inspect and the stale belief — and the warning — are right there:

$ stategraph inspect examples/meeting.yaml

Current State
  Meeting
    status: cancelled

Superseded Observations
  O1  (superseded by O2)
    Meeting tomorrow at 9:00.

Affected Decisions
  D1  Leave home at 8:00
    depends on: meeting.status = scheduled  [superseded]

Warnings
  ⚠ Decision D1 depends on superseded state.

explain answers the natural follow-up — why?:

$ stategraph explain examples/meeting.yaml D1
...
Superseded By

O2  (2026-07-18 20:00:00+00:00)
  Meeting cancelled.
...
Reasoning

Decision D1 depends on a semantic state that has already been superseded.

Recommendation

Review whether the decision should instead depend on the newer observation (O2).

You understood the bug before learning a single thing about how StateGraph works.

When should I use StateGraph?

Use StateGraph if:

  • ✓ your agent runs for minutes, hours, or days
  • ✓ you need to understand why a decision exists
  • ✓ you suspect stale or unsupported beliefs
  • ✓ execution traces alone aren't enough

Reach for a sibling instead if you need to capture execution (AgentTrace), store memory (TypedMem), or benchmark representations (ReliAgent-Bench).

Quick start

pip install -e '.[dev]'
stategraph inspect examples/meeting.yaml
stategraph explain examples/meeting.yaml D1
pytest -q

A run is a small YAML/JSON file describing what the agent observed and decided — see examples/meeting.yaml.

Starting from a real trace? annotate extracts candidate observations from an operational trace so you don't hand-type them — then you add the beliefs and decisions:

stategraph annotate examples/meeting_trace.json -o run.yaml   # observations only — nothing inferred
# add claims + decisions to run.yaml, then:
stategraph inspect run.yaml

Real traces come in other shapes. A source adapter reshapes them into observations — --source auto detects the format (or name it explicitly):

stategraph annotate corpus/openhands/deploy-timeout/trace.json   # OpenHands trajectory, auto-detected

Adapters do a pure, mechanical reshape — no claims, decisions, or contradictions are ever inferred. Built-in: generic (StateGraph-native JSON/JSONL), openhands, and swe-agent. The growing corpus of real traces + semantic annotations lives under corpus/ and annotations/ — see docs/corpus.md.

annotate performs no semantic reasoning: it never invents claims, decisions, or contradictions. The semantic layer stays explicit and auditable — that's the whole point.

Use it as a library too:

from stategraph import load_run, inspect_text, explain_decision_text

run = load_run("examples/meeting.yaml")
print(inspect_text(run))
print(explain_decision_text(run, "D1"))

How it works

run.yaml → loader → resolve state & provenance → inspector / explainer → terminal

The loader reads the run; queries resolve the active belief state and each decision's provenance; inspect and explain render it. No graph engine, no web UI, no LLM. StateGraph consumes an explicit run — it does not infer beliefs from raw text, which keeps it honest and keeps any benchmark that uses it neutral.

The invariant everything serves: every decision must reference the active claims that justify it, and every active claim must trace back to evidence or an explicitly declared assumption. The warnings above are exactly its violations.

StateGraph vs. AgentTrace

Boundary. StateGraph models semantic provenance and decision justification. It is not an execution tracing system or a benchmark.

AgentTrace records operational execution (tool calls, retries, latency). StateGraph records the semantic state lineage (beliefs, evidence, decisions). They stay independent — StateGraph does not import AgentTrace and keeps its own record model; a future one-way bridge may turn AgentTrace events into candidate evidence, never auto-accepted claims. AgentTrace makes execution observable; StateGraph makes state changes accountable.

The model

A run is built from five node types:

Node Meaning
Evidence something observed — a tool result, a user statement, or an explicit assumption
Claim a proposition, held as active / disputed / superseded / rejected / unknown
Transition an explicit change from one claim to another, with its trigger
Decision an action that depends on one or more claims
Conflict contradictory claims about one subject, and how they resolved

Experiment

The sharpest evidence for semantic provenance is the F6 case: the execution trace shows the correct final action, yet the decision was justified by a superseded belief — invisible operationally. Five failure classes (F1/F3/F4/F5/F6), each localized by a different part of the representation, are in docs/experiments.md (python examples/certificate/experiment.py). The neutral, cross-representation version lives in ReliAgent-Bench — StateGraph doesn't grade itself.

Roadmap

The workflow is annotate → inspect → explain — turn a real operational trace into candidate observations, complete the semantic layer, then debug. The current phase (v0.5, the Real Agent Trace Initiative) validates that loop on real traces: source adapters (OpenHands and SWE-agent live — the latter validated on a captured SWE-bench run; LangGraph and OpenAI Agents SDK planned) plus a public corpus of traces paired with semantic annotations and a Bug Zoo of semantic failure patterns. Data now matters more than new commands: candidates like diff and timeline wait on real feedback, not a fixed pipeline. Every feature must answer one question: does this help an engineer understand an agent's semantic state better than yesterday? If it's "kind of neat," it doesn't ship.

Status & research

Research prototype, tested (pytest, 32 tests). The thesis, design, and open research question — does semantic provenance localize failures better than an operational trace? — are in DESIGN.md.

About

StateGraph — semantic state provenance for AI agents: which evidence changed the agent's state, and which decisions depended on it. Part of RLRA.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages