Skip to content

Persistence for Graph runs Provides snapshotting, timing, and history utilities without changing core Graph behavior.#47

Open
shaheerzaman wants to merge 1 commit intoaurelio-labs:mainfrom
shaheerzaman:feat/graph-snapshot
Open

Persistence for Graph runs Provides snapshotting, timing, and history utilities without changing core Graph behavior.#47
shaheerzaman wants to merge 1 commit intoaurelio-labs:mainfrom
shaheerzaman:feat/graph-snapshot

Conversation

@shaheerzaman
Copy link
Copy Markdown
Contributor

**Summary

Adds an in-memory persistence module for GraphAI, modeled after pydantic-ai. Provides snapshotting, timing, and history utilities without changing core Graph behavior.**

Key Changes

graphai/persistence/in_memory.py: Simple and full persistence implementations with:

  • Node/end snapshots: NodeSnapshot, EndSnapshot
  • Status lifecycle: created → pending → running → success|error
  • record_run(snapshot_id): async context manager to track timing/status
  • load_next(): promotes first created node snapshot to pending
  • dump_json()/load_json() (Full): JSON history round-trip (excludes node objects)
  • rebind_nodes(name_lookup) (Full): hydrate nodes from names
  • deep_copy option (Full) for state/result payloads
  • peek_last_id() convenience
  • graphai/persistence/init.py: Exposes public API
  • Typing/compat:
  • NodeSnapshot.node is Any | None to avoid Pydantic forward-ref issues
  • BaseStatePersistence.record_run returns AsyncContextManager[None] (mypy clean)

Tests

  • tests/unit/test_persistence_in_memory.py:
  • Validates SimpleStatePersistence happy/error paths, idempotency, load_next, peek_last_id
  • Validates FullStatePersistence deep-copy behavior, history, JSON round-trip, rebind_nodes, error cases
  • All tests pass locally

Notes

  • Non-breaking: no modifications to graphai.Graph
  • Ready for optional follow-up to wire persistence hooks into Graph execution if desired

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant