Skip to content

docs(examples): LangGraph tutorial refactors as GOAP screencasts - #83

Merged
bsbodden merged 22 commits into
mainfrom
examples/langgraph-refactors
Nov 15, 2026
Merged

bsbodden merged 22 commits into
mainfrom
examples/langgraph-refactors

Conversation

@bsbodden

@bsbodden bsbodden commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

Three LangGraph tutorials rewritten as GOAP, each as a before / after / after-disrupted screencast with a generated, executed notebook and an integration test. Everything is hermetic (no API keys).

Upstream Hand-wired pieces GOAP replacement Tests
LLMCompiler (official tutorial; replan branch reported broken in langgraph #274, #1459, #1513, #1565) $N dependency parser, thread-pool scheduler, joiner emitting Replan as a SystemMessage, routing on isinstance(messages[-1], AIMessage), recursion_limit preconditions, executor="parallel" (3 executor invocations vs 4 sequential), observer blacklist-and-replan, no_plan with an explanation 7
executive-ai-assistant (langchain-ai, 2.2k stars) route_after_triage / take_action / enter_after_human with raise ValueError fall-throughs, four Agent Inbox handlers, bad_tool_name patch loop a triage sensor, seven actions, require_human_approval=True on send_email, a Pydantic form on send_cal_invite; a denied send or declined form is blacklisted and re-planned to escalate_to_user; an invalid form is asked again with the errors; a new process resumes a paused thread 13
GenAI_Agents weather disaster management (25k-star repo) route_response with an unreachable "send_email_alert" literal, input() approval node that auto-approves anything not low/medium, swallowed SMTP failure a grading sensor, eight actions, approve_alert gate, ActionQos retry + SMS fallback, FunctionalStuckHandler relaxing the goal on denial 14

Each before.py is a condensed version of the upstream control flow and is itself tested so the contrast stays faithful (the ValueError, the dead literal, the auto-approval of "Assessment Failed", the swallowed SMTP error are all reproduced).

Notebooks are built by _build_notebook.py from the scripts (so they cannot drift), executed with nbconvert, and registered in docs/copy_notebooks.py / docs/examples/index.md under a new "LangGraph tutorial refactors" section. Output cells were read against the narrative.

Four least-surprise defects surfaced while writing these and are fixed in #84 (typed forms that fail validation are asked again with the errors and can be declined explicitly; the boolean gate asks again instead of reading "no" as approval; every bookkeeping key is present in every result; GoalSpec(conditions={...}) type-checks). A fifth, the no-plan explanation calling an operator's denial a transient failure, is fixed on #82. This branch carries both #84 and #82 via merges so the notebooks show the corrected behaviour and CI runs against it; the three notebooks were re-executed on the merged code. Merge order: #84 → #82 → #83.

No library code changes beyond the #84 and #82 commits it carries. make check-equivalent run locally: 2119 passed (the two local failures are the stale importlib.metadata version of a 0.2.0 editable install against this branch's 0.1.2, and a benchmark test that --ignore=tests/benchmarks excludes by default).

…rafter policy

The version moved to langgoap/_version.py with ``dynamic = ["version"]``
(#44), but release.yml and test-release.yml still read
``[project].version`` from pyproject.toml, so the first job of a release
would fail with KeyError. Both now parse the version file; the mismatch
hint names the right file.

Release Drafter: the autolabeler only sees pull-request events, so the
workflow also runs on pull_request_target; a breaking change bumps the
minor version while the project is pre-1.0 (it resolved to major, which
would have drafted v1.0.0); docs PRs get their own category instead of
landing uncategorised.
…dd_goap_subgraph (#19)

The 0.2.0 notes say every on-ramp rejects an unknown compile keyword with
a TypeError naming the compile options and the GoapGraph options, but
only create_goap_agent did; GoapSubgraph.compile and add_goap_subgraph
forwarded the kwargs raw and surfaced Python's generic message. The check
now lives in integrations/_compile_options.py and all three call it;
prebuilt re-exports the names for existing importers.
Bump __version__ to 0.2.0 and date the CHANGELOG entry. The entry opens
with a "Breaking changes" summary (JSON-native state, the strict
defaults, termination and reporting changes) and gains a "Removed"
section for LangGOAPRedisSerializer; the Deprecated section no longer
claims that LANGGOAP_ALLOWED_MSGPACK_TYPES warns on access, which a
module constant cannot do. Stale "v0.1.0" wording in an error message
and three docstrings, the Jupyter image's minimum version and the bug
template placeholder are updated.

tests/test_release_pipeline.py pins the release mechanics: the workflows
read the version file, the version file matches the top CHANGELOG entry,
a dated release with breaking changes says so, the Jupyter image installs
the current minor, no package text names a stale release, and the
release drafter follows the pre-1.0 policy.
A can_rerun=False action that already ran is blacklisted like a failed
one, so the no_plan explanation told users to raise max_retries or
attach an ActionQos "for transient failures" when nothing had failed;
the personal-shopper NirvanaGoal run ended with exactly that advice. The
suggestion now separates actions blacklisted after failures from spent
ones (listed under spent_actions) and gives each its own advice, noting
that a NirvanaGoal run ends this way by design. The log line no longer
credits A* for every planning failure.
…ult budget to 8 (#12)

Reading the re-executed tutorial outputs showed the objective-driven
selection of #12 could not reach plans two swaps away: alternatives were
produced by excluding one action of the A* plan at a time, so at most
len(plan) candidates existed whatever max_alternatives said. With
uniform action costs the cloud-balancing objective settled on a $1,506
placement while a feasible $1,092 one existed, and the project-scheduling
soft budget of $20 looked unattainable although a two-swap plan meets it
exactly.

enumerate_alternatives now widens breadth-first over exclusion sets
(one swap away, then two, ...) and deduplicates by action sequence;
max_alternatives bounds how far it reaches and its default rises from 5
to 8. The job-shop tutorial constants and tests follow the plan the
wider search selects ($120, two standard prepares, 7 h makespan) and
also pin the limits honestly: the all-standard $57 minimum lies six swaps
away and is reached by widening the budget to 63 or by encoding cost_usd
as the A* cost. The CHANGELOG and concepts page describe the bounded
neighbourhood.
…and correct their narratives

Twenty notebooks were re-executed against main: the objective tutorials
(cloud balancing, nurse rostering, task assigning, vehicle routing,
temporal match cellar, project scheduling, flexible job shop, content
builder), the sequential MultiGoal launch, the NirvanaGoal shopper, and
the partially executed primers and comparisons. Every output cell was
read against its prose. Narratives that the 0.2.0 defaults made false
are corrected: infeasible plans are reported and not executed by default
(GoalPolicy(on_infeasible="execute") opts in), objectives compare the A*
plan against alternatives enumerated breadth-first within
max_alternatives rather than "picking the cheapest", the job-shop and
project-scheduling tables show the plans the wider search selects, the
shopper explains that no_plan is the normal end of a NirvanaGoal run, and
the remaining "v0.1.0" wording is version-neutral. The job-shop notebook
gains a section showing that the $57 global minimum lies beyond the
default budget and how to reach it.
Adds examples/screencast/llm_compiler/ with a condensed hermetic before.py
($N dependency resolver, thread-pool scheduler, Replan via SystemMessage),
after.py (dependencies as preconditions, executor="parallel"),
after_disrupted.py (index down for one city, for every city, and with the
archive down too), a generated and executed notebook rendered in the docs,
and an integration test that pins the wave count, the answer, the replan
behaviour and the async path.
Adds examples/screencast/email_assistant/ with a condensed hermetic before.py
(the upstream routers with their ValueError fall-throughs, one Agent Inbox
round trip, the bad_tool_name patch loop, a scripted drafter), after.py (a
triage sensor, seven actions whose preconditions carry the paths,
require_human_approval=True on send_email and a Pydantic form on
send_cal_invite), after_disrupted.py (a denied send and an invalid form are
blacklisted and re-planned to escalate_to_user; a new process resumes a
paused thread), a generated and executed notebook rendered in the docs, and
an integration test covering the four paths, both gate payloads, the
disruptions, crash-resume and the async path.
…GOAP screencast

Adds examples/screencast/weather_alert/ with a condensed hermetic before.py
(the upstream nodes and both routers verbatim, unreachable literal included;
the input() approval node; the swallowed SMTP failure), after.py (a sensor
grades the forecast once, eight actions whose preconditions carry the
departments, require_human_approval=True on approve_alert, an ActionQos retry
on send_email_alert with send_sms_alert as the dearer fallback, and a
FunctionalStuckHandler that relaxes the goal to decision_logged when the
operator denies the alert), after_disrupted.py (denial, a dropped SMTP
connection, a dead relay), a generated and executed notebook rendered in the
docs, and an integration test covering the four paths, the gate payload, the
denial-and-relax path, both relay failures, the async path and the upstream
behaviours the hand-wired version keeps.
@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown

✅ Code Quality Report

Metric Score Status
MFCQI Score 0.8119005243014936 ✅ Good
Test Coverage 94% ✅ Good
Security Issues 0 ✅ Clean

Quality Gates

  • MFCQI Score: ✅ Minimum 0.75 (Current: 0.8119005243014936)
  • Test Coverage: ✅ Minimum 80% (Current: 94%)
  • Security: ✅ Zero vulnerabilities (Current: 0)

🎉 All quality gates passed! This PR maintains high code quality standards.

📊 View detailed MFCQI breakdown

Run uv run python -m mfcqi analyze langgoap locally to see detailed metrics breakdown.

A resume payload rejected by the Pydantic model (or of the wrong shape) was
recorded as a human_form_invalid failure with the count pre-set past
max_retries, so a typo blacklisted the action and, with no alternative,
ended the run in no_plan. It is an input error, not a decision: the gate
now raises the interrupt again with attempt, validation_errors and
rejected_payload in the payload. A form can be declined explicitly with
False or {"approved": False, "reason": ...}, recorded and blacklisted like
a denied boolean gate; the form gate had no way to say no before.
LangGraph returns only the channels a run wrote to, so
result["blacklisted_actions"] and result["action_failure_counts"] raised
KeyError precisely when nothing had gone wrong. The defaults now live in
one table, STATE_DEFAULTS: GoapGraph.initial_state seeds them, the planner
fills any that a hand-built input left out, and rehydrate_state fills them
on the way out.
…e email screencast

An invalid invite form is now asked again with the validation errors in
the payload, and declining it is blacklisted like a denied send; the
disruption script, notebook, README and test follow. Both disruption
scripts index blacklisted_actions and replan_count directly now that every
result carries them.
A boolean gate asks a yes/no question, but any non-empty string, non-zero
number, dict without approved or with a non-boolean approved counted as
approval, so Command(resume="no") approved the action. Only True / False
and {"approved": <bool>, "reason": ...} are decisions now; anything else
re-raises the interrupt with attempt, validation_errors and
rejected_payload, exactly like the typed-form gate. Both gate payloads
carry attempt and effects. _is_approved is replaced by
_approval_decision, which returns approved / denied / invalid.
GoalSpec.conditions, SoftGoal.conditions and GoalSpec.objectives were
annotated as MappingProxyType although every caller passes a dict and
__post_init__ converts it, so GoalSpec(conditions={...}) was a mypy error
in user code. The fields are annotated as Mapping (what a caller writes)
and still converted to an immutable MappingProxyType at construction.
…nt failure

When every remaining path to the goal needs an action a human declined,
the no-plan explanation advised raising max_retries or attaching an
ActionQos for transient failures. It now lists the action under
denied_actions with the operator's reason and points at what applies: an
alternative action, a stuck handler that relaxes the goal, or running
again once the decision changes.
The denial in the weather screencast is now explained as a denial, and the
planner's no-plan log line no longer attributes the failure to A*.
@github-actions github-actions Bot added documentation Improvements or additions to documentation maintenance CI/build/tooling maintenance labels Nov 15, 2026
@bsbodden
bsbodden merged commit 43690cd into main Nov 15, 2026
20 checks passed
@bsbodden
bsbodden deleted the examples/langgraph-refactors branch November 15, 2026 22:54
@bsbodden bsbodden removed the maintenance CI/build/tooling maintenance label Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant