Skip to main content

Agent

Struct Agent 

Source
pub struct Agent { /* private fields */ }
Expand description

Minimal agent builder/runtime.

Implementations§

Source§

impl Agent

Source

pub async fn run( &self, prompt: impl Into<AgentInput>, ) -> Result<AgentResult, AgentError>

Run the agent with a user prompt.

§Errors

Returns an error when the model, capabilities, validation, tools, or runtime policy fails.

Source

pub async fn run_iter( &self, prompt: impl Into<AgentInput>, ) -> Result<AgentIterResult, AgentError>

Run the agent and collect a compact iteration trace.

§Errors

Returns an error when the model, capabilities, validation, tools, or runtime policy fails.

Source

pub async fn run_stream( &self, prompt: impl Into<AgentInput>, ) -> Result<AgentStreamResult, AgentError>

Run the agent and collect typed stream events emitted during execution.

§Errors

Returns an error when the model, capabilities, validation, tools, or runtime policy fails.

Source

pub async fn run_with_history_iter( &self, prompt: impl Into<AgentInput>, message_history: Vec<ModelMessage>, ) -> Result<AgentIterResult, AgentError>

Run the agent with prior history and collect a compact iteration trace.

§Errors

Returns an error when the model, capabilities, validation, tools, or runtime policy fails.

Source

pub async fn run_with_stream_events( &self, prompt: impl Into<AgentInput>, events: &mut Vec<AgentStreamRecord>, ) -> Result<AgentResult, AgentError>

Run the agent with an explicit typed stream event collector.

§Errors

Returns an error when the model, capabilities, validation, tools, or runtime policy fails.

Source

pub async fn run_with_history_and_stream_events( &self, prompt: impl Into<AgentInput>, message_history: Vec<ModelMessage>, events: &mut Vec<AgentStreamRecord>, ) -> Result<AgentResult, AgentError>

Run the agent with prior history and collect typed stream events.

§Errors

Returns an error when the model, capabilities, validation, tools, or runtime policy fails.

Source

pub async fn run_with_history( &self, prompt: impl Into<AgentInput>, message_history: Vec<ModelMessage>, ) -> Result<AgentResult, AgentError>

Run the agent with prior canonical message history.

§Errors

Returns an error when the model, capabilities, validation, tools, or runtime policy fails.

Source

pub async fn run_with_context_iter( &self, prompt: impl Into<AgentInput>, context: &mut AgentContext, ) -> Result<AgentIterResult, AgentError>

Run the agent using a lifecycle-wide context and collect a compact iteration trace.

§Errors

Returns an error when the model, capabilities, validation, tools, or runtime policy fails.

Source

pub async fn run_with_context_and_stream_events( &self, prompt: impl Into<AgentInput>, context: &mut AgentContext, events: &mut Vec<AgentStreamRecord>, ) -> Result<AgentResult, AgentError>

Run the agent using a lifecycle-wide context and typed stream event collector.

§Errors

Returns an error when the model, capabilities, validation, tools, or runtime policy fails.

Source

pub async fn run_with_context( &self, prompt: impl Into<AgentInput>, context: &mut AgentContext, ) -> Result<AgentResult, AgentError>

Run the agent using a lifecycle-wide context.

§Errors

Returns an error when the model, capabilities, validation, tools, or runtime policy fails.

Source§

impl Agent

Source

pub fn new(model: Arc<dyn ModelAdapter>) -> Self

Create an agent with a model adapter.

Source

pub const fn agent_id(&self) -> &AgentId

Return the default agent id used when this agent creates a context.

Source

pub fn agent_name(&self) -> &str

Return the default human-readable agent name.

Source

pub fn with_agent_id(self, agent_id: AgentId) -> Self

Set the default agent id used when this agent creates a context.

Source

pub fn with_agent_name(self, agent_name: impl Into<String>) -> Self

Set the default human-readable agent name.

Source

pub fn with_agent_identity( self, agent_id: AgentId, agent_name: impl Into<String>, ) -> Self

Set both the default agent id and human-readable agent name.

Source

pub fn new_context(&self) -> AgentContext

Create a fresh context using this agent’s configured identity.

Source

pub fn with_instruction(self, instruction: impl Into<String>) -> Self

Add a static instruction.

Source

pub fn with_dynamic_instruction( self, instruction: DynDynamicInstruction, ) -> Self

Add a dynamic instruction.

Source

pub fn with_model_settings(self, settings: ModelSettings) -> Self

Set default model settings.

Source

pub fn with_request_params(self, params: ModelRequestParameters) -> Self

Set default request parameters.

Source

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

Set runtime tools.

Source

pub fn with_toolset(self, toolset: DynToolset) -> Self

Add one runtime toolset that is materialized for each agent context.

Source

pub fn with_toolsets( self, toolsets: impl IntoIterator<Item = DynToolset>, ) -> Self

Add many runtime toolsets that are materialized for each agent context.

Source

pub fn with_appended_tools(self, tools: &ToolRegistry) -> Self

Merge additional runtime tools into this agent.

Source

pub fn tools(&self) -> ToolRegistry

Return a clone of the runtime tool registry.

Source

pub async fn prepare_tools_for_context( &self, context: &mut AgentContext, ) -> Result<ToolRegistry, AgentError>

Prepare this agent’s static tools and context-aware toolsets for a concrete context.

This uses the same lifecycle-aware path as the normal run loop and is intended for host operations that need to execute a previously suspended tool call.

§Errors

Returns an agent error when a context-aware toolset cannot be prepared.

Source

pub async fn close_toolsets_for_context(&self, context: &mut AgentContext)

Close context-aware toolsets after host-side execution outside the normal run loop.

Source

pub const fn with_tool_retries(self, max_retries: usize) -> Self

Set the agent-level retry default for runtime tools.

Source

pub fn with_output_schema(self, schema: OutputSchema) -> Self

Set structured output schema.

Source

pub fn with_output_policy(self, policy: OutputPolicy) -> Self

Apply a complete output policy.

Source

pub fn with_output_validator(self, validator: Arc<dyn OutputValidator>) -> Self

Add an output validator.

Source

pub fn with_output_function(self, function: DynOutputFunction) -> Self

Add an output function.

Source

pub const fn with_usage_limits(self, limits: UsageLimits) -> Self

Set usage limits.

Source

pub fn with_model_config(self, model_config: ModelConfig) -> Self

Set the full model config exposed to AgentContext.

Source

pub fn with_tool_config(self, tool_config: ToolConfig) -> Self

Set tool-level configuration exposed to runtime tools.

Source

pub fn with_context_window(self, context_window: u64) -> Self

Set the model context window exposed to AgentContext runtime instructions.

Source

pub fn with_capability(self, capability: Arc<dyn AgentCapability>) -> Self

Add a capability hook.

Source

pub fn with_stream_observer(self, observer: Arc<dyn AgentCapability>) -> Self

Add a stream observer hook.

Source

pub fn with_cancellation_token(self, token: CancellationToken) -> Self

Set a cooperative cancellation token used by streaming callers.

Source

pub fn with_capability_bundle(self, bundle: &dyn CapabilityBundle) -> Self

Apply a composable capability bundle.

Source

pub fn with_executor(self, executor: DynAgentExecutor) -> Self

Set durable execution checkpoint handler.

Source

pub fn with_trace_recorder(self, recorder: DynTraceRecorder) -> Self

Set runtime trace recorder.

Source

pub const fn with_policy(self, policy: AgentRuntimePolicy) -> Self

Set runtime policy.

Source

pub fn inspect_graph( &self, start: AgentNode, state: &AgentRunState, ) -> Result<AgentGraphTrace, GraphError>

Inspect graph transitions from a state snapshot.

§Errors

Returns an error when the inspected transition is invalid for the provided state.

Source

pub fn override_config(&self) -> AgentOverride

Create a scoped override builder for tests and alternate run contexts.

Trait Implementations§

Source§

impl Clone for Agent

Source§

fn clone(&self) -> Agent

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Agent

§

impl !UnwindSafe for Agent

§

impl Freeze for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl UnsafeUnpin for Agent

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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: Sized + 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: Sized + 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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