pub struct AgentLoopBuilder<Ctx, P, H, M, S> { /* private fields */ }Expand description
Implementations§
Source§impl<Ctx, P, H, M, S> AgentLoopBuilder<Ctx, P, H, M, S>
impl<Ctx, P, H, M, S> AgentLoopBuilder<Ctx, P, H, M, S>
Sourcepub fn provider<P2: LlmProvider>(
self,
provider: P2,
) -> AgentLoopBuilder<Ctx, P2, H, M, S>
pub fn provider<P2: LlmProvider>( self, provider: P2, ) -> AgentLoopBuilder<Ctx, P2, H, M, S>
Set the LLM provider.
Sourcepub fn tools(self, tools: ToolRegistry<Ctx>) -> Self
pub fn tools(self, tools: ToolRegistry<Ctx>) -> Self
Set the tool registry.
Sourcepub fn hooks<H2: AgentHooks>(
self,
hooks: H2,
) -> AgentLoopBuilder<Ctx, P, H2, M, S>
pub fn hooks<H2: AgentHooks>( self, hooks: H2, ) -> AgentLoopBuilder<Ctx, P, H2, M, S>
Set the agent hooks.
Sourcepub fn message_store<M2: MessageStore>(
self,
message_store: M2,
) -> AgentLoopBuilder<Ctx, P, H, M2, S>
pub fn message_store<M2: MessageStore>( self, message_store: M2, ) -> AgentLoopBuilder<Ctx, P, H, M2, S>
Set the message store.
Sourcepub fn state_store<S2: StateStore>(
self,
state_store: S2,
) -> AgentLoopBuilder<Ctx, P, H, M, S2>
pub fn state_store<S2: StateStore>( self, state_store: S2, ) -> AgentLoopBuilder<Ctx, P, H, M, S2>
Set the state store.
Sourcepub fn event_store(self, store: Arc<dyn EventStore>) -> Self
pub fn event_store(self, store: Arc<dyn EventStore>) -> Self
Set the authoritative event store for the loop lifecycle.
Set the event authority for envelope creation.
When set, the authority governs how events are wrapped in envelopes (sequence numbers, event IDs, timestamps). In server mode the authority seeds sequences from durable storage so ordering is continuous across turns within a thread.
When not set, a fresh LocalEventAuthority
starting at sequence 0 is created for each run.
Sourcepub fn execution_store(self, store: impl ToolExecutionStore + 'static) -> Self
pub fn execution_store(self, store: impl ToolExecutionStore + 'static) -> Self
Set the execution store for tool idempotency.
When set, tool executions will be tracked using a write-ahead pattern:
- Record execution intent BEFORE calling the tool
- Update with result AFTER completion
- On retry, return cached result if execution already completed
§Example
use agent_sdk::{builder, stores::InMemoryExecutionStore};
let agent = builder()
.provider(my_provider)
.execution_store(InMemoryExecutionStore::new())
.build();Set the execution store from a shared Arc.
Use this when the caller needs to retain a handle to the store
(for inspection, pre-population, or sharing across loops). See
Self::execution_store for the standard owned form.
Sourcepub fn audit_sink(self, sink: impl ToolAuditSink + 'static) -> Self
pub fn audit_sink(self, sink: impl ToolAuditSink + 'static) -> Self
Set the authoritative tool audit sink.
When set, the agent loop emits a
ToolAuditRecord at every tool
lifecycle transition — blocked, requires-confirmation, cached,
replayed, invalidated, completed, and persistence-failed. This
gives servers a complete audit trail without relying on the weaker
post_tool_use hook.
Defaults to NoopAuditSink when
not set.
Set the audit sink from a shared Arc.
Use this when the caller needs to retain a handle to the sink
(e.g. to inspect captured records from tests, or to share a
single durable sink across multiple agent loops). Passing an
Arc<dyn ToolAuditSink> here avoids the Arc<Arc<S>> double
wrap that happens when callers Arc::clone(&sink) a sink they
already wrapped and hand it to Self::audit_sink.
See Self::audit_sink for the standard owned form.
Sourcepub fn observability_store(
self,
store: impl ObservabilityStore + 'static,
) -> Self
Available on crate feature otel only.
pub fn observability_store( self, store: impl ObservabilityStore + 'static, ) -> Self
otel only.Set the observability store for GenAI payload capture.
Sourcepub fn config(self, config: AgentConfig) -> Self
pub fn config(self, config: AgentConfig) -> Self
Set the agent configuration.
Sourcepub const fn with_compaction(self, config: CompactionConfig) -> Self
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();Sourcepub fn with_auto_compaction(self) -> Self
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())Sourcepub fn with_custom_compactor(
self,
compactor: impl ContextCompactor + 'static,
) -> Self
pub fn with_custom_compactor( self, compactor: impl ContextCompactor + 'static, ) -> Self
Override the default compactor with a custom implementation.
Sourcepub fn with_skill(self, skill: Skill) -> Self
Available on crate feature skills only.
pub fn with_skill(self, skill: Skill) -> Self
skills only.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.
Available when the skills feature is enabled.
§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, (), (), ()>
impl<Ctx, P> AgentLoopBuilder<Ctx, P, (), (), ()>
Sourcepub fn build(
self,
) -> AgentLoop<Ctx, P, DefaultHooks, InMemoryStore, InMemoryStore>
pub fn build( self, ) -> AgentLoop<Ctx, P, DefaultHooks, InMemoryStore, InMemoryStore>
Build the agent loop with default hooks and in-memory message/state stores.
This is a convenience method that uses:
DefaultHooksfor hooksInMemoryStorefor message storeInMemoryStorefor state storeInMemoryEventStorefor the event store, when none was setAgentConfig::default()if no config is set
Supplying an event_store is optional for this
convenience build — a fresh InMemoryEventStore
is used by default so the 30-second path needs no Arc ceremony. Wire
a durable store explicitly when you need persistence across process
restarts.
§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,
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,
Sourcepub fn build_with_stores(self) -> AgentLoop<Ctx, P, H, M, S>
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:
providerhooksmessage_storestate_storeevent_store