🛡️ fix: validate edge agent refs early in MultiAgentGraph#111
Merged
danny-avila merged 1 commit intomainfrom Apr 19, 2026
Merged
🛡️ fix: validate edge agent refs early in MultiAgentGraph#111danny-avila merged 1 commit intomainfrom
danny-avila merged 1 commit intomainfrom
Conversation
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.
Owner
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Breezy! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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
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.
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Safety-net fix for the root failure mode seen in LibreChat #12726: when a host passes
edgesinto amulti-agentrun without including every referenced agent inagents,StateGraph.compile()throws the opaqueFound 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
MultiAgentGraphconstructor 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
src/graphs/__tests__/MultiAgentGraph.test.ts— 6 cases covering valid graphs, unknownto, unknownfrom, multiple unknowns reported together, array-formfrom/to, and empty-edges case.npx jest src/graphs/__tests__/MultiAgentGraph.test.ts.npx tsc --noEmitclean.