Skip to content

🛡️ fix: validate edge agent refs early in MultiAgentGraph#111

Merged
danny-avila merged 1 commit intomainfrom
claude/multi-agent-edge-validation
Apr 19, 2026
Merged

🛡️ fix: validate edge agent refs early in MultiAgentGraph#111
danny-avila merged 1 commit intomainfrom
claude/multi-agent-edge-validation

Conversation

@danny-avila
Copy link
Copy Markdown
Owner

Summary

Safety-net fix for the root failure mode seen in LibreChat #12726: when a host passes edges into a multi-agent run without including every referenced agent in agents, StateGraph.compile() throws the opaque Found edge ending at unknown node "<id>" error — with no indication that the true cause is a missing agent config.

This change validates the edges up-front in the MultiAgentGraph constructor and throws a descriptive error naming every missing agent id, pointing callers at the real fix (include the agent or filter the orphan edge).

Why in the SDK as well as the host?

LibreChat's own controllers now pre-load handoff sub-agents (see the companion PR), so this SDK guard is not load-bearing for the LibreChat bug. It's here because the same class of mistake is easy for any downstream consumer to make, and the LangGraph error message gives them nothing actionable. Failing fast with a clear message saves the next person a long debugging session.

Test plan

  • New unit test file: src/graphs/__tests__/MultiAgentGraph.test.ts — 6 cases covering valid graphs, unknown to, unknown from, multiple unknowns reported together, array-form from/to, and empty-edges case.
  • All pass: npx jest src/graphs/__tests__/MultiAgentGraph.test.ts.
  • npx tsc --noEmit clean.

Adds a `validateEdgeAgents()` check in the `MultiAgentGraph` constructor
that throws a descriptive error when any edge (on `from` or `to`) points
at an agent not present in `agentContexts`.

Without this guard, `StateGraph.compile()` later throws the opaque
`Found edge ending at unknown node "<id>"` error that gives callers no
indication of why — this was the surface error from LibreChat's
#12726 where the host passed `edges` into a multi-agent run without
also loading the sub-agents. The new error explicitly instructs callers
to include every referenced agent or filter orphaned edges upstream.
@danny-avila
Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Breezy!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila danny-avila merged commit c40f605 into main Apr 19, 2026
4 checks passed
danny-avila added a commit that referenced this pull request Apr 19, 2026
Adds a `validateEdgeAgents()` check in the `MultiAgentGraph` constructor
that throws a descriptive error when any edge (on `from` or `to`) points
at an agent not present in `agentContexts`.

Without this guard, `StateGraph.compile()` later throws the opaque
`Found edge ending at unknown node "<id>"` error that gives callers no
indication of why — this was the surface error from LibreChat's
#12726 where the host passed `edges` into a multi-agent run without
also loading the sub-agents. The new error explicitly instructs callers
to include every referenced agent or filter orphaned edges upstream.
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