Skip to content

docs: add a step-by-step LangGraph tutorial - #39

Open
how2how2how2-arch wants to merge 2 commits into
utsab345:mainfrom
how2how2how2-arch:docs/langgraph-triage-tutorial
Open

how2how2how2-arch wants to merge 2 commits into
utsab345:mainfrom
how2how2how2-arch:docs/langgraph-triage-tutorial

Conversation

@how2how2how2-arch

Copy link
Copy Markdown
Contributor

Adds the step-by-step tutorial #26 asks for: docs/tutorials/langgraph-triage.md, plus a test that runs every command in it.

What the page does. One small LangGraph triage agent, built in the order the issue names rather than as one lump:

  1. write the agent (scripted chat model, one instrumented tool, fully offline),
  2. record a run — python triage_agent.py → a .sftrace bundle,
  3. validate it — stepfork validate triage.sftrace --verify-integrity, then inspect to show what was captured,
  4. replay it — stepfork replay triage.sftrace --entrypoint triage_agent:run_agent, every recorded boundary substituted,
  5. write the expectation by hand, export a test against it, watch the buggy entrypoint fail with behavior mismatch at 'decision': expected "escalate", got "queue",
  6. correct the decision, export against the fixed entrypoint, watch it pass.

It links to docs/langgraph.md for the adapter semantics and to examples/langgraph_agent for the two-tool example that also diffs and verifies integrity, and restates neither. The scenario is a support-ticket triage agent, deliberately not the refund agent the example already ships. mkdocs.yml gains one nav line for it.

"The documented commands are tested." tests/integration/test_docs_langgraph_tutorial.py extracts both code blocks from the page (the agent, and the correction introduced in step 7), concatenates them, and runs every documented command in a clean subprocess — record, validate with --verify-integrity, inspect, replay, export, and pytest on both the buggy and the fixed entrypoint — asserting the recorded event types, the substituted boundaries, the MATCHED verdict, and the two opposite pytest outcomes. A renamed flag or a removed option fails this test instead of a reader. It is modelled on the existing tests/integration/test_docs_langgraph_example.py, which guards the guide the same way.

What I verified, and what I could not. The full suite passes: 703 passed with this test, 701 passed with it excluded, so nothing else moved. Every output quoted in the page is copied from an actual run on this machine; the numbers that vary per run (event count, timings) appear only inside blocks that are labelled as output of a reference run, and the test asserts the behavioural facts, not those counts.

Not run locally: ruff check, ruff format --check, mypy, and mkdocs build --strict. This machine's wheel CDN throttles to about 19 KB/s, so uv sync could not fetch those wheels at all — I ran the suite out of a venv built from the cached runtime dependencies instead. Line lengths are within the 88-character limit and imports follow the configured isort order, checked by hand, but that is not ruff and I am not claiming it is. The three relative links (../langgraph.md, ../pytest-export.md, ../trace-format.md) resolve to files that exist. CI will be the first place those four checks actually run, and if one of them objects I will fix it rather than argue.

Refs #26.

how2how2how2-arch and others added 2 commits October 30, 2026 16:31
Walks one small LangGraph agent from a recorded run to a regression test: write the
agent, record it, validate the bundle, replay it frozen, export a pytest test, and
watch that test fail on the buggy decision and pass on the corrected one. It links
to docs/langgraph.md for the adapter API and to examples/langgraph_agent for the
larger worked example rather than restating either.

The test extracts both code blocks from the page and runs every documented command
in a clean subprocess, so a command that stops working fails CI instead of a reader.

Refs utsab345#26.
The formatter prefers the quote style that needs no escaping:
assert 'pip install "stepfork[langgraph]"' in text

This branch has not been deployed

No deployments
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