Tasks: Local AI Stack (Ollama + LangGraph + Checkpointers + Phoenix)¶
Each task references one or more
FR-*/NFR-*/AC-*IDs from spec.md.scripts/spec_validator.pyenforces full coverage.
Conventions¶
- Status:
[ ]todo /[~]in-progress /[x]done. - Owner:
@copilotunless a human handle is given. - Each task lists exact files to touch and how to verify.
T-001 — Add deps + settings for local-AI substrate¶
- Refs: FR-1, NFR-OSS-1
- Owner: @copilot
- Status:
[x] - Files:
backend/pyproject.tomlbackend/app/core/config.py.env.example- Steps:
- Add to base
dependencies:langchain-ollama>=0.2.0,arize-phoenix-otel>=0.6.0,opentelemetry-instrumentation-fastapi>=0.48b0,opentelemetry-instrumentation-httpx>=0.48b0. - Add
[project.optional-dependencies].local-aiwithlanggraph-checkpoint-postgres>=2.0.0,langgraph-checkpoint-redis>=0.0.5. - Confirm each license (MIT / Apache-2.0 / Elastic-2.0) and record in PR description.
- Add
OLLAMA_DEFAULT_MODEL(defaultmistral:7b-instruct-q4_K_M),LANGGRAPH_CHECKPOINTER(defaultpostgres),PHOENIX_COLLECTOR_ENDPOINT(defaulthttp://phoenix:6006/v1/traces),PHOENIX_UI_URL(defaulthttp://localhost:6006) toSettings. - Mirror new env vars into
.env.examplewith comments. - Verify:
cd backend && pip install -e ".[dev,local-ai]"succeeds.python -c "from app.core.config import get_settings; print(get_settings().PHOENIX_COLLECTOR_ENDPOINT)"prints the default.
T-002 — build_checkpointer() factory¶
- Refs: FR-2, NFR-RESILIENCE-1
- Owner: @copilot
- Status:
[x] - Files:
backend/app/agents/graphs/__init__.py(new)backend/app/agents/graphs/runtime.py(new)backend/app/db/checkpointer.py(new)backend/tests/agents/graphs/__init__.py(new)backend/tests/agents/graphs/test_runtime.py(new)- Steps:
- Implement
build_checkpointer()returningPostgresSaver/RedisSaver/MemorySaverbased onsettings.LANGGRAPH_CHECKPOINTER. app.db.checkpointer.ensure_schema()callsPostgresSaver.from_conn_string(...).setup()once and is safe to re-call.- Unit test covers all three branches (Postgres + Redis branches mocked).
- Verify:
pytest backend/tests/agents/graphs/test_runtime.py -qgreen.mypy app/ --strictclean for new modules.
T-003 — Telemetry: Phoenix + OTEL wiring¶
- Refs: FR-4, NFR-AUDIT-1, NFR-PRIVACY-1
- Owner: @copilot
- Status:
[x] - Files:
backend/app/core/telemetry.py(new)backend/app/main.py(lifespan)backend/tests/core/test_telemetry.py(new)backend/tests/core/test_local_ai_privacy.py(new)- Steps:
init_tracing(app)is a no-op whenPHOENIX_COLLECTOR_ENDPOINTunset; otherwise registers tracer provider with OTLP/HTTP exporter, instruments FastAPI + httpx, registers LangChain OTEL callback.- Call from
app.mainlifespan startup. - Privacy test monkey-patches
httpx.AsyncClient.sendand asserts allowlist (localhost,ollama,phoenix). - Verify:
pytest backend/tests/core/test_telemetry.py backend/tests/core/test_local_ai_privacy.py -qgreen.- With
PHOENIX_COLLECTOR_ENDPOINTunset, no spans are exported (tested).
T-004 — @logged_node provenance decorator¶
- Refs: FR-5, NFR-AUDIT-1
- Owner: @copilot
- Status:
[x] - Files:
backend/app/core/provenance.pybackend/tests/core/test_provenance_logged_node.py(new)- Steps:
- Add
@logged_node(name: str)decorator supporting both sync and async node functions. - Compute
input_hash/output_hash(blake2b 16-char hex) from JSON-serializable state diffs. - Pull
trace_idfrom current OTEL span; pass through torecord(...). - Add nullable
trace_idcolumn to provenance store (back-compat). - Verify:
- Decorator round-trips state unchanged.
- Recorded row contains all FR-5 fields including
trace_idwhen an OTEL span is active.
T-005 — LegalWorkflow LangGraph (3 nodes)¶
- Refs: FR-3, NFR-PERF-1, NFR-HITL-1, NFR-TEST-COV-1, AC-2, AC-5, AC-6
- Owner: @copilot
- Status:
[x] - Files:
backend/app/agents/graphs/legal_workflow.py(new)backend/app/agents/prompts/legal_workflow/{retrieve,analyze,cite_check}.md(new, versioned)backend/app/models/analysis.py(extend response models withphoenix_trace_url,langgraph_thread_id)backend/tests/agents/graphs/test_legal_workflow.py(new)- Steps:
- Define
LegalWorkflowStateTypedDict andLegalWorkflowOutputPydantic model. - Build graph:
retrieve(Cypher + vector) →analyze(ChatOllama) →cite_check(verifies citations againstapp.db.citation_resolver). - Wire each node with
@logged_node(...)(T-004) and the checkpointer (T-002). - Unit tests use a fake
ChatOllama(returns canned tool calls) andMemorySaver; assert node order, output schema, HITL flag set when an unverified citation is injected (AC-6). - Verify:
pytest backend/tests/agents/graphs/test_legal_workflow.py -q --cov=app.agents.graphs --cov=app.core.telemetry≥ 80% (NFR-TEST-COV-1).- Manual:
POST /api/analysis {"question":"...","use_langgraph":true}returnsphoenix_trace_url+langgraph_thread_id(AC-2).
T-006 — LegalAnalyst opt-in delegation¶
- Refs: FR-3, AC-2
- Owner: @copilot
- Status:
[x] - Files:
backend/app/agents/crews/legal_analyst.pybackend/app/api/analysis.py(or wherever/api/analysislives)backend/tests/agents/crews/test_legal_analyst.py- Steps:
- Add
use_langgraph: bool = Falseto request schema; default unchanged. - When true, delegate to
LegalWorkflow.invoke(...)and surfacephoenix_trace_url+langgraph_thread_id. - Update one existing test to cover the new path with mocked workflow.
- Verify:
- All existing tests still pass.
- New test asserts delegation occurs only when flag is true.
T-007 — Postgres-backed resilience integration test¶
- Refs: NFR-RESILIENCE-1, AC-3
- Owner: @copilot
- Status:
[x] - Files:
backend/tests/agents/graphs/test_legal_workflow_postgres.py(new,@pytest.mark.integration)backend/scripts/init-db.sh(addCREATE EXTENSION IF NOT EXISTS pg_trgm;)- Steps:
- Spin up against
docker compose up postgres ollama phoenix; skip when env vars unreachable. - Run
LegalWorkflow.invokewith threadT, capture state. - Recreate
LegalWorkflowinstance (simulates restart) and assertget_state(...)matches snapshot. - Verify:
pytest -m integration backend/tests/agents/graphs/test_legal_workflow_postgres.py -qgreen when stack is up.
T-008 — Compose: Phoenix service + Ollama bootstrap script¶
- Refs: FR-6, FR-7, AC-1
- Owner: @copilot
- Status:
[x] - Files:
docker-compose.ymlbackend/scripts/ollama-bootstrap.sh(new,chmod +x)- Steps:
- Add
phoenixservice (arizephoenix/phoenix:<pinned-tag>, port6006:6006, named volume). - Backend
depends_on: [..., phoenix]; add envPHOENIX_COLLECTOR_ENDPOINT,PHOENIX_UI_URL. - Replace inline Ollama
command:withcommand: ["/bin/sh", "/scripts/ollama-bootstrap.sh"]and mount./backend/scripts/ollama-bootstrap.sh:/scripts/ollama-bootstrap.sh:ro. - Bootstrap script idempotently pulls
mistral:7b-instruct-q4_K_M,llama3.1:8b-instruct-q4_K_M,nomic-embed-text; smallest model gates readiness. - Verify:
docker compose up -d phoenix ollama→ both healthy indocker compose ps.curl localhost:6006returns Phoenix HTML;curl localhost:11434/api/tagslists ≥ 1 model on first boot, all three after warm-up.
T-009 — Health endpoint + Make/VS Code wiring¶
- Refs: FR-8, FR-9, AC-1
- Owner: @copilot
- Status:
[x] - Files:
backend/app/api/agents.pybackend/app/models/health.py(new or extend)backend/tests/api/test_local_ai_health.py(new)Makefile.vscode/tasks.json- Steps:
- Implement
GET /api/agents/health/local-aireturning theLocalAIHealthschema (FR-9). - Add
local-ai-up,local-ai-down,local-ai-pullMake targets calling docker compose with the right service set. - Add
Start Local AI StackVS Code task. - Verify:
- Unit test mocks subsystem probes and asserts response shape.
make local-ai-up && curl -s localhost:8000/api/agents/health/local-ai | jqshows all three subsystemsreachable: trueagainst a live stack (AC-1).
T-010 — Documentation¶
- Refs: FR-10, NFR-OSS-1, AC-4
- Owner: @copilot
- Status:
[x] - Files:
docs/local-ai.md(new)docs/data-model.md(append "LangGraph Checkpointer Tables" subsection)docs/agent-roles.md(append "Stateful Workflows" subsection)README.md(one-line pointer)- Steps:
docs/local-ai.mdcovers: architecture diagram (reuse plan §1), env var matrix, hardware tier table (laptop / workstation / server — only laptop is configured today; the other two link to BACKLOG items), Phoenix license summary, troubleshooting (model OOM, Phoenix port collision, checkpointer reset).- Document how to read a Phoenix trace URL returned in API responses (AC-4).
- Cross-link from
README.md"Local development" section. - Verify:
python tests/test_docs.py(or whichever doc lint exists) passes.- Manual review: every env var introduced in T-001 appears in the docs.
Done-When (Definition of Done)¶
- All tasks
[x]. - All
AC-1…AC-7fromspec.mdcovered by passing tests. make lint && make testgreen;mypy app/ --strictclean for new modules.Run LegalBench Evalshows ≥ 0 pp delta oncore_reasoningandprecedent_retrieval; recorded in PR description.- Phoenix UI reachable at
http://localhost:6006aftermake local-ai-up; trace ids in API responses resolve to a span tree (AC-4). - Provenance rows for new LangGraph nodes include
trace_idmatching Phoenix. ## Follow-ups Discoveredpopulated below and mirrored to BACKLOG.md.
Follow-ups Discovered¶
Append-only. Mirror each item into BACKLOG.md with a
BL-YYYYMMDD-NNid.
- BL-20260502-01 — feature, med — Self-host LangGraph API + Studio container (
langchain/langgraph-api) so designers can step throughLegalWorkflowruns visually. Phase 5 oflocal-ai-plan.md(since deleted); deferred per NG1. - BL-20260502-02 — infra, med — Linux + NVIDIA workstation tier: GPU runtime in compose, optional vLLM service, default model upgraded to
llama3.1:70b-q4_K_M. Phase 2 / 3 of source plan; deferred per NG2. - BL-20260502-03 — infra, low — Server / multi-GPU tier with Prometheus + Grafana for token/sec, GPU util, queue depth. Phase 8 of source plan; deferred per NG5.
- BL-20260502-04 — feature, med — Backfill
LegalAnalyst(BL-20260430-03) andPrecedentHunter(BL-20260430-04) ontoLegalWorkflowonce parity proven on LegalBench. - BL-20260502-05 — feature, low —
AgentTrace.tsxsurfacesphoenix_trace_url+langgraph_thread_idreturned by/api/analysisso users can deep-link from the UI. - BL-20260502-06 — infra, low — Air-gapped deployment hardening: bundle pre-pulled Ollama models into a tarball + offline install script. Phase 8 extension.
- BL-20260502-07 — feature, low — Langfuse fallback path if Phoenix license terms change; abstract the OTEL exporter behind
settings.OBSERVABILITY_BACKEND. - BL-20260502-08 — test-gap, low — CI matrix entry that runs the integration test from T-007 against a real Postgres + Ollama (currently only locally executable).