AgentLoopBuilder

Struct AgentLoopBuilder 

Source
pub struct AgentLoopBuilder<Ctx, P, H, M, S> { /* private fields */ }
Expand description

Builder for constructing an AgentLoop.

§Example

let agent = AgentLoop::builder()
    .provider(my_provider)
    .tools(my_tools)
    .config(AgentConfig::default())
    .build();

Implementations§

Source§

impl<Ctx> AgentLoopBuilder<Ctx, (), (), (), ()>

Source

pub const fn new() -> Self

Create a new builder with no components set.

Source§

impl<Ctx, P, H, M, S> AgentLoopBuilder<Ctx, P, H, M, S>

Source

pub fn provider<P2: LlmProvider>( self, provider: P2, ) -> AgentLoopBuilder<Ctx, P2, H, M, S>

Set the LLM provider.

Source

pub fn tools(self, tools: ToolRegistry<Ctx>) -> Self

Set the tool registry.

Source

pub fn hooks<H2: AgentHooks>( self, hooks: H2, ) -> AgentLoopBuilder<Ctx, P, H2, M, S>

Set the agent hooks.

Source

pub fn message_store<M2: MessageStore>( self, message_store: M2, ) -> AgentLoopBuilder<Ctx, P, H, M2, S>

Set the message store.

Source

pub fn state_store<S2: StateStore>( self, state_store: S2, ) -> AgentLoopBuilder<Ctx, P, H, M, S2>

Set the state store.

Source

pub fn config(self, config: AgentConfig) -> Self

Set the agent configuration.

Source

pub const fn with_compaction(self, config: CompactionConfig) -> Self

Enable context compaction with the given configuration.

When enabled, the agent will automatically compact conversation history when it exceeds the configured token threshold.

§Example
use agent_sdk::{builder, context::CompactionConfig};

let agent = builder()
    .provider(my_provider)
    .with_compaction(CompactionConfig::default())
    .build();
Source

pub fn with_auto_compaction(self) -> Self

Enable context compaction with default settings.

This is a convenience method equivalent to:

builder.with_compaction(CompactionConfig::default())
Source

pub fn with_skill(self, skill: Skill) -> Self
where Ctx: Send + Sync + 'static,

Apply a skill configuration.

This merges the skill’s system prompt with the existing configuration and filters tools based on the skill’s allowed/denied lists.

§Example
let skill = Skill::new("code-review", "You are a code reviewer...")
    .with_denied_tools(vec!["bash".into()]);

let agent = builder()
    .provider(provider)
    .tools(tools)
    .with_skill(skill)
    .build();
Source§

impl<Ctx, P> AgentLoopBuilder<Ctx, P, (), (), ()>
where Ctx: Send + Sync + 'static, P: LlmProvider + 'static,

Source

pub fn build( self, ) -> AgentLoop<Ctx, P, DefaultHooks, InMemoryStore, InMemoryStore>

Build the agent loop with default hooks and in-memory stores.

This is a convenience method that uses:

  • DefaultHooks for hooks
  • InMemoryStore for message store
  • InMemoryStore for state store
  • AgentConfig::default() if no config is set
§Panics

Panics if a provider has not been set.

Source§

impl<Ctx, P, H, M, S> AgentLoopBuilder<Ctx, P, H, M, S>
where Ctx: Send + Sync + 'static, P: LlmProvider + 'static, H: AgentHooks + 'static, M: MessageStore + 'static, S: StateStore + 'static,

Source

pub fn build_with_stores(self) -> AgentLoop<Ctx, P, H, M, S>

Build the agent loop with all custom components.

§Panics

Panics if any of the following have not been set:

  • provider
  • hooks
  • message_store
  • state_store

Trait Implementations§

Source§

impl<Ctx> Default for AgentLoopBuilder<Ctx, (), (), (), ()>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<Ctx, P, H, M, S> Freeze for AgentLoopBuilder<Ctx, P, H, M, S>
where P: Freeze, H: Freeze, M: Freeze, S: Freeze,

§

impl<Ctx, P, H, M, S> !RefUnwindSafe for AgentLoopBuilder<Ctx, P, H, M, S>

§

impl<Ctx, P, H, M, S> Send for AgentLoopBuilder<Ctx, P, H, M, S>
where P: Send, H: Send, M: Send, S: Send,

§

impl<Ctx, P, H, M, S> Sync for AgentLoopBuilder<Ctx, P, H, M, S>
where P: Sync, H: Sync, M: Sync, S: Sync,

§

impl<Ctx, P, H, M, S> Unpin for AgentLoopBuilder<Ctx, P, H, M, S>
where P: Unpin, H: Unpin, M: Unpin, S: Unpin,

§

impl<Ctx, P, H, M, S> !UnwindSafe for AgentLoopBuilder<Ctx, P, H, M, S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more