Demonstrates the most common LangGraph pattern: a tool-calling agent that loops between deciding and acting, using conditional edges for routing.
- Defining a
StateGraphwith an agent->tools loop - Using
add_conditional_edgesfor conditional routing (call tool or finish) - Accumulating conversation history with
Annotated[list, operator.add] - The full ReAct cycle: think -> act -> observe -> repeat
- The
agentnode examines the conversation history and decides the next action. - If a tool is needed,
should_continueroutes to thetoolsnode. - The
toolsnode executes the tool and appends the result to history. - Control returns to
agent, which decides again — loop or finish. - When the agent has enough information,
should_continueroutes toEND.
START -> agent -> tools -> agent -> tools -> agent -> END
Prerequisites: uv sync --group langgraph and a running Temporal dev server (temporal server start-dev).
# Terminal 1
uv run langgraph_plugin/graph_api/react_agent/run_worker.py
# Terminal 2
uv run langgraph_plugin/graph_api/react_agent/run_workflow.py| File | Description |
|---|---|
workflow.py |
AgentState, node functions, should_continue router, graph definition, and ReactAgentWorkflow |
run_worker.py |
Builds graph, registers with LangGraphPlugin, starts worker |
run_workflow.py |
Executes the agent workflow and prints the answer |