Files
gcp_solution_architecture_a…/app/execution/checkpointing.py
Jonathan Boniface d9214c671a feat: add the hierarchical Execution engine on LangGraph
Increment 4 of .scratch/solution-architect-agent/spec.md, test-first.

- app/agents/runtime.py: framework-neutral AgentRuntime interface
  (RoleSpec, AgentTask, ToolSpec, outcomes); fake_runtime.py replays
  scripted tool calls through the real tools with step budgets.
- app/execution/graph.py: Orchestrator turn fans out to parallel
  Specialist tasks (Send), pauses with interrupt() for questions,
  Approvals and cloud-read permission, and finalizes or ends with
  warnings. Only the Orchestrator turn writes the Ledger.
- app/execution/tools.py: Orchestrator tools, Specialist submit and
  needs_input, and the cloud-read permission gate.
- app/execution/engine.py: ExecutionEngine.start/resume returning an
  Interaction; the single interface for A2A, /generate and eval.
- Recorders (in-memory, DatabaseManager), configurable checkpointer
  (memory, sqlite, postgres), engine settings, langgraph checkpoint
  dependencies.
- 19 new tests; full suite 121 passed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 09:38:13 +01:00

39 lines
1.2 KiB
Python

"""The configured LangGraph checkpointer that makes paused Executions resumable."""
from __future__ import annotations
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
from langgraph.checkpoint.base import BaseCheckpointSaver
from langgraph.checkpoint.memory import InMemorySaver
from app.config import Settings
@asynccontextmanager
async def open_checkpointer(settings: Settings) -> AsyncIterator[BaseCheckpointSaver]:
"""Yield a checkpointer per CHECKPOINTER: memory | sqlite | postgres."""
kind = settings.CHECKPOINTER
if kind == "memory":
yield InMemorySaver()
elif kind == "sqlite":
from langgraph.checkpoint.sqlite.aio import AsyncSqliteSaver
async with AsyncSqliteSaver.from_conn_string(
settings.CHECKPOINT_DB_PATH
) as saver:
yield saver
elif kind == "postgres":
from langgraph.checkpoint.postgres.aio import AsyncPostgresSaver
async with AsyncPostgresSaver.from_conn_string(
settings.get_database_url()
) as saver:
await saver.setup()
yield saver
else:
raise ValueError(
f"CHECKPOINTER must be memory, sqlite or postgres, not {kind!r}"
)