hi @eric-burel
Yes - create_agent constructs a LangGraph StateGraph that implements a ReAct-style loop (model → tools → model …) and runs until a stop condition is met. The loop is built-in.
How to control the loop:
- Limit iterations via the LangGraph executor’s
recursion_limitconfig when invoking/streaming the agent:
assert app.invoke(
{"messages": [HumanMessage(content="what is weather in sf")]},
{"recursion_limit": 2},
debug=True,
) == {
"messages": [
_AnyIdHumanMessage(content="what is weather in sf"),
_AnyIdAIMessage(content="Sorry, need more steps to process this request."),
]
}
- Exit early when a tool has
return_direct=Trueor when a structured output tool completes (see code excerpts above). - Skip the loop entirely by passing no tools; the graph becomes a single
modelnode (no tool-calling loop). - Programmatic control with middleware: set
state["jump_to"]to"model" | "tools" | "end"to steer or terminate the loop (see_resolve_jumpand the conditional edges around it in the same file). - Pause/resume specific nodes with
interrupt_before/interrupt_after(useful for human-in-the-loop UIs); these are exposed increate_agent(...).compile(...)arguments.