Sagents.Modes.AgentExecution (Sagents v0.9.0)
Copy MarkdownStandard sagents execution mode.
Replaces the separate execute_chain_with_state_updates and
execute_chain_with_hitl loops with a single composable pipeline.
Pipeline
- Call the LLM
- Check for HITL interrupts (if HumanInTheLoop middleware present)
- Execute tools
- Propagate state updates from tool results
- Check if target tool was called (if
until_toolis set) - Loop if
needs_responseis true, or error if until_tool contract violated
Options
:middleware— Agent's middleware list (for HITL checking):should_pause?— Zero-arity function for infrastructure pause:max_runs— Maximum LLM calls (default: 50):until_tool— Tool name (string) or list of tool names. When set, the mode returns{:ok, chain, tool_result}once the target tool is called, or{:error, chain, %LangChainError{}}if the LLM stops without calling it.:require_tool_success— Boolean (defaultfalse). Whentrue, the mode terminates only when the target tool returns a successful (non-error) result; an error result keeps the loop running so the LLM can correct the call, bounded by:max_runs.
These two are the mode's internal representation. Callers using
Sagents.Agent.execute/3 pass the friendlier mutually-exclusive
:until_tool / :until_tool_success (each naming the target tool), which are
collapsed into the pair above via collapse_until_tool/2.
Summary
Functions
Collapse the public :until_tool / :until_tool_success either-or spelling
into the internal {tool_name | nil, require_success_boolean} representation.
Functions
Collapse the public :until_tool / :until_tool_success either-or spelling
into the internal {tool_name | nil, require_success_boolean} representation.
The friendly either-or options are mutually exclusive (validated at the public
boundary in Sagents.Agent / Sagents.SubAgent.Config). If both are non-nil
when this is called, the success variant wins.
Used at the two collapse points — Sagents.Agent.execute/3 (opts → mode opts)
and Sagents.Middleware.SubAgent (config → sub-agent construction) — so the
rest of the system carries only :until_tool + :require_tool_success.