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;
pub use crate::runtime::run_context::TOOL_SCOPE_CALLER_AGENT_ID_KEY;
pub use crate::runtime::run_context::TOOL_SCOPE_CALLER_MESSAGES_KEY;
pub use crate::runtime::run_context::TOOL_SCOPE_CALLER_STATE_KEY;
pub use crate::runtime::run_context::TOOL_SCOPE_CALLER_THREAD_ID_KEY;

Structs§

AgentConfig
Runtime configuration for the agent loop.
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.

Traits§

LlmExecutor
Provider-neutral LLM execution contract consumed by the loop runtime.
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_config
Execute tool calls with phase-based plugin hooks.
execute_tools_with_plugins
Execute tool calls with plugin hooks.
execute_tools_with_plugins_and_executor
run_loop
Run the full agent loop until completion or a stop condition is met.
run_loop_stream
Run the agent loop with streaming output.
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.