Demonstrates the ReAct agent pattern (think -> act -> observe -> repeat) as a natural while loop using LangGraph's @task and @entrypoint decorators.
- The ReAct loop as a natural
while Trueloop in Python @taskfunctions for agent thinking and tool execution- How the Functional API makes agent loops readable and extensible
- The
agent_thinktask examines the query and tool history, deciding the next action. - If a tool is needed,
execute_toolruns it and the result is appended to history. - The loop continues until
agent_thinkreturns a final answer.
while True:
decision = await agent_think(query, history)
if decision["action"] == "final":
return decision["answer"]
result = await execute_tool(decision["tool_name"], decision["tool_input"])
history.append(result)Prerequisites: uv sync --group langgraph and a running Temporal dev server (temporal server start-dev).
# Terminal 1
uv run langgraph_plugin/functional_api/react_agent/run_worker.py
# Terminal 2
uv run langgraph_plugin/functional_api/react_agent/run_workflow.py| File | Description |
|---|---|
workflow.py |
@task functions (agent_think, execute_tool), @entrypoint, and ReactAgentFunctionalWorkflow |
run_worker.py |
Registers tasks and entrypoint with LangGraphPlugin, starts worker |
run_workflow.py |
Executes the agent workflow and prints the answer |