Sagents.Modes.AgentExecution (Sagents v0.8.0-rc.13)

Copy Markdown

Standard sagents execution mode.

Replaces the separate execute_chain_with_state_updates and execute_chain_with_hitl loops with a single composable pipeline.

Pipeline

  1. Call the LLM
  2. Check for HITL interrupts (if HumanInTheLoop middleware present)
  3. Execute tools
  4. Propagate state updates from tool results
  5. Check if target tool was called (if until_tool is set)
  6. Loop if needs_response is 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 (default false). When true, 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_until_tool(until_tool, until_tool_success)

@spec collapse_until_tool(term(), term()) :: {term() | nil, boolean()}

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.