pub struct Agent { /* private fields */ }Expand description
A headless model/tool loop over caller-supplied context and capabilities.
Resource lifetime belongs to ToolExecutor; persistence belongs to the
caller. The context-window setting is informational and does not enforce a
token limit or perform automatic compaction.
Implementations§
Source§impl Agent
impl Agent
pub fn new( model: Arc<dyn GenerativeModel>, tools: Arc<dyn ToolExecutor>, sink: Arc<dyn EventSink>, ) -> Self
pub fn with_context( model: Arc<dyn GenerativeModel>, tools: Arc<dyn ToolExecutor>, sink: Arc<dyn EventSink>, context: TraceContext, ) -> Self
Sourcepub fn set_tools(&mut self, tools: Arc<dyn ToolExecutor>)
pub fn set_tools(&mut self, tools: Arc<dyn ToolExecutor>)
Replace dispatch capabilities without rebuilding the model’s tool catalog. Keep both in sync when adding or removing advertised tools.
pub fn set_context(&mut self, context: TraceContext)
Sourcepub fn set_checkpoint(&mut self, checkpoint: Option<Checkpoint>)
pub fn set_checkpoint(&mut self, checkpoint: Option<Checkpoint>)
Install the durable effect checkpoint (see Checkpoint).
pub fn set_before_generation_notice( &mut self, notice: Option<BeforeGenerationNotice>, )
pub fn checkpoint_failed(&self) -> bool
Sourcepub fn checkpoint(&self) -> Result<(), AgentInteractionError>
pub fn checkpoint(&self) -> Result<(), AgentInteractionError>
Retry persistence without advancing or replaying an effect.
pub fn history(&self) -> &[Message]
Sourcepub fn replace_context(
&mut self,
history: Vec<Message>,
usage: Option<TokenUsage>,
) -> Result<(), StateError>
pub fn replace_context( &mut self, history: Vec<Message>, usage: Option<TokenUsage>, ) -> Result<(), StateError>
Replace model context and its usage estimate without changing live tool state.
pub fn state(&self) -> &AgentState
pub fn set_retry_policy(&mut self, retry_policy: RetryPolicy)
Sourcepub fn set_model(&mut self, model: Arc<dyn GenerativeModel>)
pub fn set_model(&mut self, model: Arc<dyn GenerativeModel>)
Swap the generative model (e.g. mid-session /effort rebuild). History is kept.
Sourcepub fn append_input(
&mut self,
message: Message,
) -> Result<(), AgentInteractionError>
pub fn append_input( &mut self, message: Message, ) -> Result<(), AgentInteractionError>
Append input at a well-formed context boundary and checkpoint it.
pub fn append_system( &mut self, parts: Vec<Content>, ) -> Result<(), AgentInteractionError>
pub fn truncate_history( &mut self, index: usize, ) -> Result<Vec<Message>, AgentInteractionError>
Sourcepub fn set_context_window_tokens(&mut self, tokens: u64)
pub fn set_context_window_tokens(&mut self, tokens: u64)
Set the model context budget available to callers.
pub fn context_window_tokens(&self) -> u64
Sourcepub fn set_max_truncated_resumes(&mut self, resumes: u32)
pub fn set_max_truncated_resumes(&mut self, resumes: u32)
Set how many consecutive max_tokens truncations one turn resumes
through (the active model’s max_truncated_resumes; 0 never resumes).
Sourcepub fn last_usage(&self) -> Option<TokenUsage>
pub fn last_usage(&self) -> Option<TokenUsage>
Last observed prompt/context token usage (from the provider), if any.
pub fn context(&self) -> &TraceContext
Sourcepub async fn run(
&mut self,
cancel: CancelToken,
) -> Result<Vec<Content>, AgentInteractionError>
pub async fn run( &mut self, cancel: CancelToken, ) -> Result<Vec<Content>, AgentInteractionError>
Drive the existing model context to completion. The caller supplies input separately. The supplied tool executor determines the lifetime of live resources.
Returns answer content from the final generation; intervening responses
and tool rounds remain in Self::history. Emits AgentEvent::TurnFinished
on success, error, or cooperative cancellation. Checkpoints persist both
pending effects and the final settled state.
Sourcepub async fn run_with_outcome(
&mut self,
cancel: CancelToken,
) -> Result<RunOutcome, AgentInteractionError>
pub async fn run_with_outcome( &mut self, cancel: CancelToken, ) -> Result<RunOutcome, AgentInteractionError>
Drive context and retain the stop reason and measured usage for evaluators.
pub fn start_run(&mut self) -> Result<(), AgentInteractionError>
Sourcepub async fn continue_run(
&mut self,
cancel: CancelToken,
) -> Result<RunOutcome, AgentInteractionError>
pub async fn continue_run( &mut self, cancel: CancelToken, ) -> Result<RunOutcome, AgentInteractionError>
Continue after a checkpoint failure without repeating completed effects.
A dropped in-flight effect requires explicit recover_interrupted first.
pub fn replace_at_boundary( &mut self, history: Vec<Message>, usage: Option<TokenUsage>, ) -> Result<(), StateError>
pub fn recover_interrupted(&mut self) -> Result<(), AgentInteractionError>
pub fn cancel_at_boundary(&mut self) -> Result<(), AgentInteractionError>
Sourcepub async fn step(
&mut self,
cancel: CancelToken,
) -> Result<Option<RunOutcome>, AgentInteractionError>
pub async fn step( &mut self, cancel: CancelToken, ) -> Result<Option<RunOutcome>, AgentInteractionError>
Execute one generation or tool batch and checkpoint its outcome. None
yields to the caller at the next effect, allowing compaction or inspection.