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§
- Base
Agent - Standard
Agentimplementation. - Channel
State Committer - Genai
LlmExecutor - Default LLM executor backed by
genai::Client. - LlmRetry
Policy - Retry strategy for LLM inference calls.
- Loop
Outcome - Unified terminal state for loop execution.
- Loop
Stats - Aggregated runtime metrics for one loop run.
- Loop
Usage - Aggregated token usage for one loop run.
- Parallel
Tool Executor - Executes all tool calls concurrently.
- Resolved
Run - Fully resolved agent wiring ready for execution.
- Sequential
Tool Executor - Executes tool calls one-by-one in call order.
- Step
Tool Input - Input context passed to per-step tool providers.
- Step
Tool Snapshot - Tool snapshot resolved for one step.
Enums§
- Agent
Loop Error - Error type for agent loop operations.
- Execute
Tools Outcome - Outcome of the public
execute_tools*family of functions. - Parallel
Tool Execution Mode - Executes all tool calls concurrently.
Traits§
- Agent
- The sole interface the agent loop sees.
- LlmExecutor
- Abstraction over LLM inference backends.
- Step
Tool Provider - Provider that resolves the tool snapshot for each step.
- Tool
Executor - 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§
- LlmEvent
Stream - Boxed stream of LLM chat events.