Skip to content

feat(agent): add fail-open capture hooks for raw stream chunks and plan snapshots - #683

Draft
William Lyon (johnymontana) wants to merge 2 commits into
langchain-ai:mainfrom
johnymontana:reasoning-memory
Draft

feat(agent): add fail-open capture hooks for raw stream chunks and plan snapshots#683
William Lyon (johnymontana) wants to merge 2 commits into
langchain-ai:mainfrom
johnymontana:reasoning-memory

Conversation

@johnymontana

Copy link
Copy Markdown

Motivation

External tooling (memory systems, telemetry, evaluation harnesses) cannot faithfully
observe an OpenWiki run through the public onEvent contract: the projected
tool_end event carries only {id, name, status} — tool outputs and error bodies are
dropped — subgraph namespaces are collapsed into a main/subgraph flag, and the
agent's explicit planning artifact (openwiki/_plan.md) is deleted on both the success
and error paths before a caller can read it.

This PR adds the narrowest possible seam for lossless observation, without changing
any existing behavior.

What's added

Two optional callbacks on OpenWikiRunOptions (+57 lines across 3 files, no new
dependencies):

  • onRawStreamChunk?: (chunk: unknown) => void | Promise<void> — invoked inside
    the stream loop before parseAgentStreamChunk strips fields, so consumers see the
    raw LangGraph [namespace, mode, payload] tuples (tool inputs and outputs/errors,
    subgraph namespaces, message chunks).
  • onPlanSnapshot?: (plan: string) => void | Promise<void> — backed by a new
    readTemporaryPlanFile helper; captures _plan.md immediately before cleanup on
    both the error path and the finalize path. chat runs are unaffected (no plan file).

Design constraints

  • Fail-open: every hook invocation is wrapped; a throwing consumer only emits a
    debug line ("telemetry and memory capture must never change the OpenWiki run").
  • Zero cost when unused: optional chaining; no behavior change for existing callers.
  • No reasoning exposure: the hooks surface what the stream already carries; the
    type docs instruct consumers to redact and bound data before persistence.
  • Consumers must return quickly (the hook is awaited in the stream loop) — documented
    on the option.

Testing

pnpm typecheck and pnpm build pass; the hooks are exercised end-to-end by
openwiki-graph-reasoning-memory-demo,
which builds Neo4j-backed reasoning memory and an A/B recall evaluation on top of them
(crash-safe journaling, interleaved-subagent correlation, plan-snapshot ordering).

Ports openwiki-v0.3.3-reasoning-hooks.patch onto main @ ea80ddc:
- OpenWikiRunOptions.onRawStreamChunk: lossless LangGraph stream seam,
  invoked before parseAgentStreamChunk inside the stream loop
- OpenWikiRunOptions.onPlanSnapshot + readTemporaryPlanFile: capture the
  observable _plan.md before cleanup on both the error and finalize paths

All hooks are fail-open; a throwing consumer never alters the OpenWiki run.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Aug 19, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 51f5bba

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@johnymontana
William Lyon (johnymontana) marked this pull request as draft August 19, 2026 23:20
Adds OpenWikiRunOptions.recallReasoningMemory: when the host integration
supplies a recall function, the agent gains a single recall_reasoning_memory
tool added beside — never through — createOpenWikiConnectorTools, so the
repository-mode connector gate stays intact. The tool is read-only,
bounded (8k chars), capped at two recalls per run, labels results as
untrusted historical data, and fails open: recall errors return an
explanatory string and never alter the run. Absent the option, behavior
is unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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