Skip to main content

Module agent_loop

Module agent_loop 

Source
Expand description

Agent loop — the core execution engine for phi-core agents.

This module is split into focused sub-modules:

  • [config] — Hook type aliases and AgentLoopConfig
  • [core] — Entry points: agent_loop, agent_loop_continue
  • [run] — Core turn engine (run_loop)
  • [streaming] — LLM response streaming
  • [tools] — Tool execution pipeline
  • [parallel] — Evaluational parallelism (agent_loop_parallel)
  • evaluation — Pluggable evaluation strategies for parallel branch selection
  • [helpers] — Utilities (input filters, config derivation, etc.)

Re-exports§

pub use evaluation::ElaborateEvaluation;
pub use evaluation::LlmJudgeEvaluation;
pub use evaluation::PickFirstEvaluation;
pub use evaluation::TokenEfficientEvaluation;
pub use evaluation::TransparentEvaluation;

Modules§

evaluation
Pluggable evaluation strategies for agent_loop_parallel.
script_callback
Script-based callbacks — run shell or Python scripts as lifecycle hooks.

Structs§

AgentLoopConfig
All static settings for a single [agent_loop] / [agent_loop_continue] call.

Functions§

agent_loop
Start an agent loop with new prompt messages.
agent_loop_continue
Resume an agent loop from existing context without new prompts.
agent_loop_parallel
Run multiple agent loop configurations concurrently from a shared base context, evaluate the results with the supplied strategy, and return the selected outcome.

Type Aliases§

AfterCompactionEndFn
Called after compaction completes.
AfterLoopFn
Called once after the entire agent loop ends (after AgentEnd is emitted).
AfterToolExecutionFn
Called after each tool call (after ToolExecutionEnd is emitted).
AfterToolExecutionUpdateFn
Called after each incremental tool update (after ToolExecutionUpdate is emitted).
AfterTurnFn
Called after each LLM turn (after TurnEnd is emitted).
BeforeCompactionStartFn
Called before compaction starts.
BeforeLoopFn
Called once before the entire agent loop begins (before AgentStart is emitted).
BeforeToolExecutionFn
Called before each tool call (before ToolExecutionStart is emitted).
BeforeToolExecutionUpdateFn
Called before each incremental tool update (before ToolExecutionUpdate is emitted).
BeforeTurnFn
Called before each LLM turn (before TurnStart is emitted).
ConvertToLlmFn
All hook types use Arc (shared ownership) so they can be cloned into closures and stored without lifetime complications. Box<dyn Fn> would suffice for single-owner cases but Arc makes it trivially cheap to share across async tasks. Converts AgentMessage[]Message[] before each LLM call.
GetMessagesFn
Returns pending messages (steering interrupts or follow-up work) when polled.
HookFuture
Boxed-future return type used by all 0.9.0 async lifecycle hooks. T is the hook’s logical return value (often bool for veto-returning hooks or () for fire-and-forget hooks).
OnErrorFn
Called when the LLM returns StopReason::Error. Argument: the error message string.
TransformContextFn
Transforms the full context before convert_to_llm (for pruning, reordering, injection).