Skip to main content

Module loop_runner

Module loop_runner 

Source
Expand description

Agent loop implementation with Phase-based plugin execution.

The agent loop orchestrates the conversation between user, LLM, and tools:

User Input → LLM → Tool Calls? → Execute Tools → LLM → ... → Final Response

§Phase Execution

Each phase dispatches to its typed plugin hook:

RunStart (once)
    │
    ▼
┌─────────────────────────┐
│      StepStart          │ ← plugins can apply state patches
├─────────────────────────┤
│    BeforeInference      │ ← plugins can inject prompt context, filter tools
├─────────────────────────┤
│      [LLM CALL]         │
├─────────────────────────┤
│    AfterInference       │
├─────────────────────────┤
│  ┌───────────────────┐  │
│  │ BeforeToolExecute │  │ ← plugins can block/pending
│  ├───────────────────┤  │
│  │   [TOOL EXEC]     │  │
│  ├───────────────────┤  │
│  │ AfterToolExecute  │  │ ← plugins can add reminders
│  └───────────────────┘  │
├─────────────────────────┤
│       StepEnd           │
└─────────────────────────┘
    │
    ▼
RunEnd (once)

Re-exports§

pub use crate::runtime::run_context::await_or_cancel;
pub use crate::runtime::run_context::is_cancelled;
pub use crate::runtime::run_context::CancelAware;
pub use crate::runtime::run_context::RunCancellationToken;
pub use crate::runtime::run_context::StateCommitError;
pub use crate::runtime::run_context::StateCommitter;

Structs§

BaseAgent
Standard Agent implementation.
ChannelStateCommitter
GenaiLlmExecutor
Default LLM executor backed by genai::Client.
LlmRetryPolicy
Retry strategy for LLM inference calls.
LoopOutcome
Unified terminal state for loop execution.
LoopStats
Aggregated runtime metrics for one loop run.
LoopUsage
Aggregated token usage for one loop run.
ParallelToolExecutor
Executes all tool calls concurrently.
ResolvedRun
Fully resolved agent wiring ready for execution.
SequentialToolExecutor
Executes tool calls one-by-one in call order.
StepToolInput
Input context passed to per-step tool providers.
StepToolSnapshot
Tool snapshot resolved for one step.

Enums§

AgentLoopError
Error type for agent loop operations.
ExecuteToolsOutcome
Outcome of the public execute_tools* family of functions.
ParallelToolExecutionMode
Executes all tool calls concurrently.

Traits§

Agent
The sole interface the agent loop sees.
LlmExecutor
Abstraction over LLM inference backends.
StepToolProvider
Provider that resolves the tool snapshot for each step.
ToolExecutor
Strategy abstraction for tool execution.

Functions§

execute_tools
Execute tool calls (simplified version without plugins).
execute_tools_with_behaviors
Execute tool calls with behavior hooks.
execute_tools_with_config
Execute tool calls with phase-based plugin hooks.
run_loop
Run the full agent loop until completion, suspension, cancellation, or error.
run_loop_stream
Run the agent loop with streaming output.
run_loop_stream_with_context
run_loop_with_context
Run the full agent loop until completion, suspension, cancellation, or error.
tool_map
Helper to create a tool map from an iterator of tools.
tool_map_from_arc
Helper to create a tool map from Arc.

Type Aliases§

LlmEventStream
Boxed stream of LLM chat events.