Principle:24mlight A Share investment Agent LangGraph DAG Orchestration
| Knowledge Sources | |
|---|---|
| Domains | AI_Agents, Workflow_Orchestration |
| Last Updated | 2026-10-10 14:00 GMT |
Overview
A Directed Acyclic Graph (DAG) orchestration pattern using LangGraph's StateGraph to coordinate multiple agents with parallel fan-out/fan-in edges, shared state accumulation, and a typed state structure.
Description
LangGraph DAG orchestration provides a structured way to define multi-agent workflows as graphs. The key concepts:
- StateGraph: A graph where each node is an agent function and edges define execution order. The graph compiles into an executable that invokes agents in topological order.
- Parallel Fan-Out/Fan-In: Multiple agents can execute in parallel after a single entry point. Results are accumulated into shared state. Fan-in nodes wait for all predecessors to complete before executing.
- Shared State (AgentState): A TypedDict with three fields:
messages: Accumulates HumanMessage objects viaoperator.add(list concatenation)data: Merges dictionaries via a custommerge_dictsreducermetadata: Merges dictionaries via the samemerge_dictsreducer
- DAG Structure: The 12-agent workflow follows this topology:
market_data → [technical, fundamentals, sentiment, valuation, macro_news] (parallel) → [bull_researcher, bear_researcher] (fan-in) → debate_room → risk_management → macro_analyst → portfolio_management → END
Usage
Use this principle when:
- Building multi-agent workflows with parallel execution and synchronization points
- Requiring shared state accumulation across agents (messages, data, metadata)
- Orchestrating complex analysis pipelines with fan-out and fan-in patterns
Theoretical Basis
StateGraph definition pattern:
# Abstract pattern (simplified)
from langgraph.graph import StateGraph, END
workflow = StateGraph(AgentState)
workflow.add_node("agent_a", agent_a_func)
workflow.add_node("agent_b", agent_b_func)
workflow.add_node("agent_c", agent_c_func)
# Fan-out: one source to multiple targets
workflow.add_edge("agent_a", "agent_b")
workflow.add_edge("agent_a", "agent_c")
# Fan-in: multiple sources to one target
workflow.add_edge(["agent_b", "agent_c"], "agent_d")
workflow.set_entry_point("agent_a")
workflow.add_edge("agent_d", END)
app = workflow.compile()
# Execute
final_state = app.invoke(initial_state)
State reducers:
operator.add: Concatenates lists (used for messages)merge_dicts: Shallow-merges dictionaries ({**a, **b}), later values overwrite earlier ones