Type error on conditional graph compilation #126

Closed
opened 2026-02-15 17:16:01 -05:00 by yindo · 2 comments
Owner

Originally created by @leSullivan on GitHub (Oct 28, 2024).

Argument of type 'LlmAgentName' is not assignable to parameter of type 'LlmAgentName.ORCHESTRATOR | "__start__" | (LlmAgentName.ORCHESTRATOR | "__start__")[]'.ts(2345)

When i compile my graph conditionally i can't set additional edges with the new nodes a add later. Without the typescript as workaround

compileGraph({ availableAgents }: BaseAgentConfig) {
    const workflow = new StateGraph<GraphState>({
      channels: this.graphStateChannels,
    })
      .addNode(LlmAgentName.ORCHESTRATOR, this.generalistNode.bind(this))
      .addEdge(START, LlmAgentName.ORCHESTRATOR)
      .addConditionalEdges(LlmAgentName.ORCHESTRATOR, this.router);

    const agentNodeMap = {
      [LlmAgentName.RETRIEVAL]: this.ragAgent.bind(this),
      ...
    };

    availableAgents.forEach((agent: LlmAgentName) => {
      const node = agentNodeMap[agent];
      if (node) {
        workflow.addNode(agent, node);
        workflow.addEdge(
          //Temporarily fix as type checking doesn't account for added nodes after initial setup
          agent as LlmAgentName.ORCHESTRATOR | '__start__',
          LlmAgentName.ORCHESTRATOR,
        );
      }
    });

    return workflow.compile();
  }
Originally created by @leSullivan on GitHub (Oct 28, 2024). Argument of type 'LlmAgentName' is not assignable to parameter of type 'LlmAgentName.ORCHESTRATOR | "__start__" | (LlmAgentName.ORCHESTRATOR | "__start__")[]'.ts(2345) When i compile my graph conditionally i can't set additional edges with the new nodes a add later. Without the typescript as workaround compileGraph({ availableAgents }: BaseAgentConfig) { const workflow = new StateGraph<GraphState>({ channels: this.graphStateChannels, }) .addNode(LlmAgentName.ORCHESTRATOR, this.generalistNode.bind(this)) .addEdge(START, LlmAgentName.ORCHESTRATOR) .addConditionalEdges(LlmAgentName.ORCHESTRATOR, this.router); const agentNodeMap = { [LlmAgentName.RETRIEVAL]: this.ragAgent.bind(this), ... }; availableAgents.forEach((agent: LlmAgentName) => { const node = agentNodeMap[agent]; if (node) { workflow.addNode(agent, node); workflow.addEdge( //Temporarily fix as type checking doesn't account for added nodes after initial setup agent as LlmAgentName.ORCHESTRATOR | '__start__', LlmAgentName.ORCHESTRATOR, ); } }); return workflow.compile(); }
yindo closed this issue 2026-02-15 17:16:01 -05:00
Author
Owner

@jacoblee93 commented on GitHub (Nov 1, 2024):

Thanks for raising this - this is by design.

@jacoblee93 commented on GitHub (Nov 1, 2024): Thanks for raising this - this is by design.
Author
Owner

@YvodeRooij commented on GitHub (Apr 1, 2025):

@jacoblee93 can you please elaborate. I keep hitting this error, but I dont understand why?

@YvodeRooij commented on GitHub (Apr 1, 2025): @jacoblee93 can you please elaborate. I keep hitting this error, but I dont understand why?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#126