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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
