Skip to content

[Bug]: Agents API (Chat Completions + Responses) fails for multi-agent handoffs #12726

Description

@zachmak

What happened?

Multi-agent orchestrator agents work correctly through the LibreChat web UI but fail with a 500 error when called through the Agents API endpoints (/api/agents/v1/chat/completions and
/api/agents/v1/responses).

Error:
Error: Found edge ending at unknown node agent_q3Yf1J3NqKONncExJKt0F
at StateGraph.validate (node_modules/@langchain/langgraph/dist/graph/graph.cjs:317:23)
at StateGraph.compile (node_modules/@langchain/langgraph/dist/graph/state.cjs:398:14)
at MultiAgentGraph.createWorkflow (node_modules/@librechat/agents/dist/cjs/graphs/MultiAgentGraph.cjs:907:24)
at Run.createMultiAgentGraph (node_modules/@librechat/agents/dist/cjs/run.cjs:126:32)
at Run.create (node_modules/@librechat/agents/dist/cjs/run.cjs:136:16)

Root cause:

The UI path (api/server/services/Endpoints/agents/initialize.js, ~lines 170-240) performs BFS edge discovery via createEdgeCollector(), loading and initializing all sub-agents referenced in the
orchestrator's edges before passing the full agents array to createRun().

The API controllers (api/server/controllers/agents/openai.js and responses.js) skip this entirely. They only load the primary agent and pass agents: [primaryConfig] to createRun(). However, the
primary agent's edges still reference sub-agent IDs. When createRun() detects edges, it sets the graph type to multi-agent and builds a MultiAgentGraph. The graph builder only adds nodes for agents
in the array (just the primary), but the edges point to sub-agent IDs that were never registered as nodes. StateGraph.validate() then fails.

Environment:

  • LibreChat version: 0.8.4
  • Node.js: 20.20.1
  • Deployment: Kubernetes

Version Information

Environment:

  • LibreChat version: 0.8.4
  • Node.js: 20.20.1
  • Deployment: Kubernetes

Steps to Reproduce

Steps to reproduce:

  1. Create a multi-agent orchestrator (Agent A) that delegates to sub-agents (Agent B, Agent C) via edges
  2. Verify it works through the LibreChat web UI
  3. Call Agent A through the Agents API:
    POST /api/agents/v1/chat/completions
    Authorization: Bearer <api_key>
    {"model": "<agent_a_id>", "messages": [{"role": "user", "content": "Hello"}], "stream": true}
  4. Returns HTTP 500 with the Found edge ending at unknown node error

What browsers are you seeing the problem on?

No response

Relevant log output

Error: Found edge ending at unknown node `agent_q3Yf1J3NqKONncExJKt0F`
      at StateGraph.validate (node_modules/@langchain/langgraph/dist/graph/graph.cjs:317:23)
      at StateGraph.compile (node_modules/@langchain/langgraph/dist/graph/state.cjs:398:14)
      at MultiAgentGraph.createWorkflow (node_modules/@librechat/agents/dist/cjs/graphs/MultiAgentGraph.cjs:907:24)
      at Run.createMultiAgentGraph (node_modules/@librechat/agents/dist/cjs/run.cjs:126:32)
      at Run.create (node_modules/@librechat/agents/dist/cjs/run.cjs:136:16)

Screenshots

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions