AI / LangGraph LangChain Interview questions
How do you build multi-agent systems with LangGraph?
Multi-agent systems in LangGraph are built by representing each agent as a node (or subgraph) and connecting them with edges that define how work is handed off. The most common architecture is the supervisor pattern: one supervisor agent receives the user request, decides which specialist agent should handle it, routes to that agent, and continues routing until the task is complete.
from langgraph.graph import StateGraph, START, END from typing import Literal class MultiAgentState(TypedDict): messages: Annotated[list, operator.add] next_agent: str def supervisor(state): # Supervisor LLM decides which agent goes next response = supervisor_llm.invoke(state["messages"]) return {"next_agent": response.next} # 'researcher', 'coder', or 'FINISH' def route_from_supervisor(state) -> Literal["researcher", "coder", END]: return state["next_agent"] if state["next_agent"] != "FINISH" else END graph = StateGraph(MultiAgentState) graph.add_node("supervisor", supervisor) graph.add_node("researcher", researcher_agent) graph.add_node("coder", coder_agent) graph.add_conditional_edges("supervisor", route_from_supervisor) graph.add_edge("researcher", "supervisor") # always report back graph.add_edge("coder", "supervisor") graph.add_edge(START, "supervisor")
An alternative is the network pattern where agents can hand off directly to each other without a central supervisor. Both patterns use shared state in the TypedDict to pass context between agents.
More Related questions...