Skip to main content

Agent

Trait Agent 

Source
pub trait Agent: Send + Sync {
    // Required methods
    fn id(&self) -> &str;
    fn model(&self) -> &str;
    fn system_prompt(&self) -> &str;
    fn max_rounds(&self) -> usize;
    fn chat_options(&self) -> Option<&ChatOptions>;
    fn fallback_models(&self) -> &[String];
    fn llm_retry_policy(&self) -> &LlmRetryPolicy;
    fn tool_executor(&self) -> Arc<dyn ToolExecutor>;
    fn behavior(&self) -> &dyn AgentBehavior;

    // Provided methods
    fn step_tool_provider(&self) -> Option<Arc<dyn StepToolProvider>> { ... }
    fn llm_executor(&self) -> Option<Arc<dyn LlmExecutor>> { ... }
    fn state_action_deserializer_registry(
        &self,
    ) -> Arc<StateActionDeserializerRegistry> { ... }
}
Expand description

The sole interface the agent loop sees.

Agent encapsulates all runtime configuration, execution strategies, and agent behavior into a single trait. The loop calls methods on this trait to obtain LLM settings, tool execution strategies, and phase-hook behavior.

§Three-Layer Architecture

  • Loop: pure engine — calls Agent methods, manages lifecycle
  • Agent: complete agent unit — provides config + behavior
  • AgentOS: assembly — resolves definitions into Agent instances

The default implementation is BaseAgent.

Required Methods§

Source

fn id(&self) -> &str

Unique identifier for this agent.

Source

fn model(&self) -> &str

Model identifier (e.g., “gpt-4”, “claude-3-opus”).

Source

fn system_prompt(&self) -> &str

System prompt for the LLM.

Source

fn max_rounds(&self) -> usize

Loop-budget hint (core loop does not enforce this directly).

Source

fn chat_options(&self) -> Option<&ChatOptions>

Chat options for the LLM.

Source

fn fallback_models(&self) -> &[String]

Fallback model ids used when the primary model fails.

Source

fn llm_retry_policy(&self) -> &LlmRetryPolicy

Retry policy for LLM inference failures.

Source

fn tool_executor(&self) -> Arc<dyn ToolExecutor>

Tool execution strategy (parallel, sequential, or custom).

Source

fn behavior(&self) -> &dyn AgentBehavior

The agent behavior (phase hooks) dispatched by the loop.

Provided Methods§

Source

fn step_tool_provider(&self) -> Option<Arc<dyn StepToolProvider>>

Optional per-step tool provider.

When None, the loop uses a static provider derived from the tool map.

Source

fn llm_executor(&self) -> Option<Arc<dyn LlmExecutor>>

Optional LLM executor override.

When None, the loop uses GenaiLlmExecutor with Client::default().

Source

fn state_action_deserializer_registry( &self, ) -> Arc<StateActionDeserializerRegistry>

Registry for deserializing persisted state-action intents during crash recovery.

Trait Implementations§

Source§

impl Debug for dyn Agent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Implementors§