Skip to content

feat(adapters/langgraph): support ManagerWorkers and Swarm orchestration - #19

Closed
spichen wants to merge 1 commit into
mainfrom
feat/swarm-adapter
Closed

feat(adapters/langgraph): support ManagerWorkers and Swarm orchestration#19
spichen wants to merge 1 commit into
mainfrom
feat/swarm-adapter

Conversation

@spichen

@spichen spichen commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Summary

Adds LangGraph-adapter support for multi-agent orchestration on top of the existing ManagerWorkers / Swarm spec types:

  • ManagerWorkers → hierarchical LangGraph. A manager react-agent plus worker subgraphs, wired through synthesized delegate_to_<worker> tools. The manager's tool call is intercepted by the parent graph's conditional edge, which fans out one Send per delegation so a single turn can delegate to several workers at once; each worker runs in an isolated message context and replies with a ToolMessage matched to its tool_call_id. Recursive ManagerWorkers compose for free.
  • ManagerWorkers as a flow step. An AgentNode whose agent is a ManagerWorkers runs as a hierarchical graph over MessagesState; node inputs are rendered into the group-manager prompt. ManagerWorkers now infers its inputs/outputs from its group manager so data-flow edges resolve.
  • ManagerWorkers as a Swarm member. A Command(graph=PARENT) from inside a ManagerWorkers only reaches the ManagerWorkers graph, so handoff is re-emitted at the MW parent boundary via a __handoff__ node, keeping the Swarm transcript a valid tool-call/result sequence.
  • Middleware plumbing. Forward LangChain agent middleware from the AgentSpecLoader/converter through create_agent and every nested conversion path (agents, flow nodes, MW, swarm).
  • Clean event view. The synthetic delegation protocol is hidden from astream_events (tool calls, their lifecycle events, and the worker's reply ToolMessage) without touching graph state, so the manager's react loop is unaffected and the workers' real token events still stream.

Structure

The MW/Swarm compilation subsystem (constants, delegation/handoff tool builders, routing, worker-subgraph wrapping, and the astream_events scrubber) lives in its own _managerworkers.py module rather than bloating _langgraphconverter.py; the two _*_convert_to_langgraph methods stay on the converter alongside their siblings.

Testing

  • Offline ManagerWorkers / Swarm / middleware unit suites pass (SKIP_LLM_TESTS=1): helpers, routing precedence, the handoff node, delegation event scrubbing, and the middleware-forwarding contract.
  • black / isort / pyflakes clean on the changed adapter modules.

@spichen
spichen force-pushed the feat/swarm-adapter branch 3 times, most recently from 12d06f6 to 7875c24 Compare June 30, 2026 13:32
Compile a ManagerWorkers spec into a hierarchical LangGraph (manager
react-agent + worker subgraphs wired via synthesized delegate_to_<worker>
tools), run a ManagerWorkers as a flow step, and let a ManagerWorkers
participate as a Swarm member (handoff re-emitted at the MW parent
boundary so Command(graph=PARENT) jumps reach the Swarm).

Includes the supporting middleware plumbing: forward LangChain agent
middleware from the AgentSpecLoader/converter through create_agent and
every nested conversion path (agents, flow nodes, MW, swarm).

Delegation protocol is hidden from astream_events, worker events stream
under the worker node, every delegation in a turn is answered, and
delegate tool-calls are stripped from state snapshots.
@spichen

spichen commented Jul 25, 2026

Copy link
Copy Markdown
Owner Author

Superseded by a three-PR stack — same change, split for reviewability:

  1. feat(adapters/langgraph): make agent structured output not hang or silently vanish #29 feat/agent-single-string-output — single string agent output taken from the final message. Independent of the other two; base main.
  2. feat(adapters/langgraph): compile ManagerWorkers into a hierarchical graph #30 feat/managerworkers-adapter — ManagerWorkers → hierarchical LangGraph. Base feat(adapters/langgraph): make agent structured output not hang or silently vanish #29.
  3. feat(adapters/langgraph): allow ManagerWorkers members and flow steps in a Swarm #31 feat/swarm-composite-members — ManagerWorkers as a Swarm member, Swarm as a flow step, Swarm input/output inference. Base feat(adapters/langgraph): compile ManagerWorkers into a hierarchical graph #30.

The tip of #31 is byte-identical to this branch's head (a6f62a2), so nothing was dropped in the split.

Why split this way: Swarm was already supported here (top-level, plain Agent members), so bundling it with the new ManagerWorkers compiler under one title obscured what actually changed. The single-string-output change was also agent-wide rather than multi-agent-specific, which is why it leads the stack on its own.

The feat/swarm-adapter branch is left in place.

@spichen spichen closed this Jul 25, 2026
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