LangGraph Workflows

Use LangGraph when you need fixed steps, branches, and parallel workers beyond create_agent.


Core concepts

ConceptMeaning
StateGraphStateful directed graph
NodeFunction reading/writing state
EdgeTransitions (fixed or conditional)
START / ENDEntry and exit
CheckpointerPersistence and interrupts
from typing_extensions import TypedDict
from langgraph.graph import StateGraph, START, END

class State(TypedDict):
    topic: str
    draft: str
    final: str

def write_draft(state: State) -> dict:
    return {"draft": f"Draft about {state['topic']}"}

def polish(state: State) -> dict:
    return {"final": state["draft"] + " (polished)"}

graph = StateGraph(State)
graph.add_node("write", write_draft)
graph.add_node("polish", polish)
graph.add_edge(START, "write")
graph.add_edge("write", "polish")
graph.add_edge("polish", END)

app = graph.compile()
app.invoke({"topic": "LangChain"})

Prompt chaining

Fixed multi-step LLM pipelines (translate → polish → QA)—predictable and testable.


Routing

add_conditional_edges picks the next node from state or structured LLM output.


Orchestrator-worker

Split work with the Send API; workers run in isolated state; orchestrator merges results—great for multi-section reports.


Agents as nodes

researcher = create_agent("openai:gpt-4.1-mini", tools=[search], name="researcher")
graph.add_node("research", researcher)

Compose LangChain agents inside LangGraph graphs.


ToolNode

from langgraph.prebuilt import ToolNode

graph.add_node("tools", ToolNode([multiply, search]))

Handles parallel tool calls and error propagation.


Workflows vs agents

Workflows: you define control flow. Agents: model defines it. Production often mixes routing, agents, and deterministic checks.


Streaming & deployment

app.stream(..., stream_mode="updates") + LangSmith traces. See official Deployment docs for LangGraph Platform.


Next steps