pub struct Agent { /* private fields */ }Expand description
Minimal agent builder/runtime.
Implementations§
Source§impl Agent
impl Agent
Sourcepub async fn run(
&self,
prompt: impl Into<AgentInput>,
) -> Result<AgentResult, AgentError>
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.
Sourcepub async fn run_iter(
&self,
prompt: impl Into<AgentInput>,
) -> Result<AgentIterResult, AgentError>
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.
Sourcepub async fn run_stream(
&self,
prompt: impl Into<AgentInput>,
) -> Result<AgentStreamResult, AgentError>
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.
Sourcepub async fn run_with_history_iter(
&self,
prompt: impl Into<AgentInput>,
message_history: Vec<ModelMessage>,
) -> Result<AgentIterResult, AgentError>
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.
Sourcepub async fn run_with_stream_events(
&self,
prompt: impl Into<AgentInput>,
events: &mut Vec<AgentStreamRecord>,
) -> Result<AgentResult, AgentError>
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.
Sourcepub async fn run_with_history_and_stream_events(
&self,
prompt: impl Into<AgentInput>,
message_history: Vec<ModelMessage>,
events: &mut Vec<AgentStreamRecord>,
) -> Result<AgentResult, AgentError>
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.
Sourcepub async fn run_with_history(
&self,
prompt: impl Into<AgentInput>,
message_history: Vec<ModelMessage>,
) -> Result<AgentResult, AgentError>
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.
Sourcepub async fn run_with_context_iter(
&self,
prompt: impl Into<AgentInput>,
context: &mut AgentContext,
) -> Result<AgentIterResult, AgentError>
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.
Sourcepub async fn run_with_context_and_stream_events(
&self,
prompt: impl Into<AgentInput>,
context: &mut AgentContext,
events: &mut Vec<AgentStreamRecord>,
) -> Result<AgentResult, AgentError>
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.
Sourcepub async fn run_with_context(
&self,
prompt: impl Into<AgentInput>,
context: &mut AgentContext,
) -> Result<AgentResult, AgentError>
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
impl Agent
Sourcepub fn new(model: Arc<dyn ModelAdapter>) -> Self
pub fn new(model: Arc<dyn ModelAdapter>) -> Self
Create an agent with a model adapter.
Sourcepub const fn agent_id(&self) -> &AgentId
pub const fn agent_id(&self) -> &AgentId
Return the default agent id used when this agent creates a context.
Sourcepub fn agent_name(&self) -> &str
pub fn agent_name(&self) -> &str
Return the default human-readable agent name.
Sourcepub fn with_agent_id(self, agent_id: AgentId) -> Self
pub fn with_agent_id(self, agent_id: AgentId) -> Self
Set the default agent id used when this agent creates a context.
Sourcepub fn with_agent_name(self, agent_name: impl Into<String>) -> Self
pub fn with_agent_name(self, agent_name: impl Into<String>) -> Self
Set the default human-readable agent name.
Sourcepub fn with_agent_identity(
self,
agent_id: AgentId,
agent_name: impl Into<String>,
) -> Self
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.
Sourcepub fn new_context(&self) -> AgentContext
pub fn new_context(&self) -> AgentContext
Create a fresh context using this agent’s configured identity.
Sourcepub fn with_instruction(self, instruction: impl Into<String>) -> Self
pub fn with_instruction(self, instruction: impl Into<String>) -> Self
Add a static instruction.
Sourcepub fn with_dynamic_instruction(
self,
instruction: DynDynamicInstruction,
) -> Self
pub fn with_dynamic_instruction( self, instruction: DynDynamicInstruction, ) -> Self
Add a dynamic instruction.
Sourcepub fn with_model_settings(self, settings: ModelSettings) -> Self
pub fn with_model_settings(self, settings: ModelSettings) -> Self
Set default model settings.
Sourcepub fn with_request_params(self, params: ModelRequestParameters) -> Self
pub fn with_request_params(self, params: ModelRequestParameters) -> Self
Set default request parameters.
Sourcepub fn with_tools(self, tools: ToolRegistry) -> Self
pub fn with_tools(self, tools: ToolRegistry) -> Self
Set runtime tools.
Sourcepub fn with_toolset(self, toolset: DynToolset) -> Self
pub fn with_toolset(self, toolset: DynToolset) -> Self
Add one runtime toolset that is materialized for each agent context.
Sourcepub fn with_toolsets(
self,
toolsets: impl IntoIterator<Item = DynToolset>,
) -> Self
pub fn with_toolsets( self, toolsets: impl IntoIterator<Item = DynToolset>, ) -> Self
Add many runtime toolsets that are materialized for each agent context.
Sourcepub fn with_appended_tools(self, tools: &ToolRegistry) -> Self
pub fn with_appended_tools(self, tools: &ToolRegistry) -> Self
Merge additional runtime tools into this agent.
Sourcepub fn tools(&self) -> ToolRegistry
pub fn tools(&self) -> ToolRegistry
Return a clone of the runtime tool registry.
Sourcepub async fn prepare_tools_for_context(
&self,
context: &mut AgentContext,
) -> Result<ToolRegistry, AgentError>
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.
Sourcepub async fn close_toolsets_for_context(&self, context: &mut AgentContext)
pub async fn close_toolsets_for_context(&self, context: &mut AgentContext)
Close context-aware toolsets after host-side execution outside the normal run loop.
Sourcepub const fn with_tool_retries(self, max_retries: usize) -> Self
pub const fn with_tool_retries(self, max_retries: usize) -> Self
Set the agent-level retry default for runtime tools.
Sourcepub fn with_output_schema(self, schema: OutputSchema) -> Self
pub fn with_output_schema(self, schema: OutputSchema) -> Self
Set structured output schema.
Sourcepub fn with_output_policy(self, policy: OutputPolicy) -> Self
pub fn with_output_policy(self, policy: OutputPolicy) -> Self
Apply a complete output policy.
Sourcepub fn with_output_validator(self, validator: Arc<dyn OutputValidator>) -> Self
pub fn with_output_validator(self, validator: Arc<dyn OutputValidator>) -> Self
Add an output validator.
Sourcepub fn with_output_function(self, function: DynOutputFunction) -> Self
pub fn with_output_function(self, function: DynOutputFunction) -> Self
Add an output function.
Sourcepub const fn with_usage_limits(self, limits: UsageLimits) -> Self
pub const fn with_usage_limits(self, limits: UsageLimits) -> Self
Set usage limits.
Sourcepub fn with_model_config(self, model_config: ModelConfig) -> Self
pub fn with_model_config(self, model_config: ModelConfig) -> Self
Set the full model config exposed to AgentContext.
Sourcepub fn with_tool_config(self, tool_config: ToolConfig) -> Self
pub fn with_tool_config(self, tool_config: ToolConfig) -> Self
Set tool-level configuration exposed to runtime tools.
Sourcepub fn with_context_window(self, context_window: u64) -> Self
pub fn with_context_window(self, context_window: u64) -> Self
Set the model context window exposed to AgentContext runtime instructions.
Sourcepub fn with_capability(self, capability: Arc<dyn AgentCapability>) -> Self
pub fn with_capability(self, capability: Arc<dyn AgentCapability>) -> Self
Add a capability hook.
Sourcepub fn with_stream_observer(self, observer: Arc<dyn AgentCapability>) -> Self
pub fn with_stream_observer(self, observer: Arc<dyn AgentCapability>) -> Self
Add a stream observer hook.
Sourcepub fn with_cancellation_token(self, token: CancellationToken) -> Self
pub fn with_cancellation_token(self, token: CancellationToken) -> Self
Set a cooperative cancellation token used by streaming callers.
Sourcepub fn with_capability_bundle(self, bundle: &dyn CapabilityBundle) -> Self
pub fn with_capability_bundle(self, bundle: &dyn CapabilityBundle) -> Self
Apply a composable capability bundle.
Sourcepub fn with_executor(self, executor: DynAgentExecutor) -> Self
pub fn with_executor(self, executor: DynAgentExecutor) -> Self
Set durable execution checkpoint handler.
Sourcepub fn with_trace_recorder(self, recorder: DynTraceRecorder) -> Self
pub fn with_trace_recorder(self, recorder: DynTraceRecorder) -> Self
Set runtime trace recorder.
Sourcepub const fn with_policy(self, policy: AgentRuntimePolicy) -> Self
pub const fn with_policy(self, policy: AgentRuntimePolicy) -> Self
Set runtime policy.
Sourcepub fn inspect_graph(
&self,
start: AgentNode,
state: &AgentRunState,
) -> Result<AgentGraphTrace, GraphError>
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.
Sourcepub fn override_config(&self) -> AgentOverride
pub fn override_config(&self) -> AgentOverride
Create a scoped override builder for tests and alternate run contexts.