pub struct Agent<Deps = (), Output = String> { /* private fields */ }Expand description
The main agent type.
An agent wraps a model and provides:
- System prompts and instructions
- Tool registration and execution
- Structured output parsing and validation
- Retry logic for failures
- Usage tracking and limits
§Type Parameters
Deps: Dependencies injected into tools and instruction functions.Output: The output type (default:String).
Implementations§
Source§impl<Deps, Output> Agent<Deps, Output>
impl<Deps, Output> Agent<Deps, Output>
Sourcepub fn model_arc(&self) -> Arc<dyn Model>
pub fn model_arc(&self) -> Arc<dyn Model>
Get the model as an Arc (for cloning into spawned tasks).
Sourcepub fn model_settings(&self) -> &ModelSettings
pub fn model_settings(&self) -> &ModelSettings
Get model settings.
Sourcepub fn tools(&self) -> Vec<&ToolDefinition>
pub fn tools(&self) -> Vec<&ToolDefinition>
Get registered tools.
Sourcepub fn output_mode(&self) -> OutputMode
pub fn output_mode(&self) -> OutputMode
Get the output mode.
Sourcepub fn usage_limits(&self) -> Option<&UsageLimits>
pub fn usage_limits(&self) -> Option<&UsageLimits>
Get usage limits.
Sourcepub fn parallel_tool_calls(&self) -> bool
pub fn parallel_tool_calls(&self) -> bool
Check if parallel tool execution is enabled.
Sourcepub fn max_concurrent_tools(&self) -> Option<usize>
pub fn max_concurrent_tools(&self) -> Option<usize>
Get the maximum number of concurrent tool calls.
Sourcepub async fn run(
&self,
prompt: impl Into<UserContent>,
deps: Deps,
) -> Result<AgentRunResult<Output>, AgentRunError>
pub async fn run( &self, prompt: impl Into<UserContent>, deps: Deps, ) -> Result<AgentRunResult<Output>, AgentRunError>
Sourcepub async fn run_with_options(
&self,
prompt: impl Into<UserContent>,
deps: Deps,
options: RunOptions,
) -> Result<AgentRunResult<Output>, AgentRunError>
pub async fn run_with_options( &self, prompt: impl Into<UserContent>, deps: Deps, options: RunOptions, ) -> Result<AgentRunResult<Output>, AgentRunError>
Run with options.
Sourcepub fn run_sync(
&self,
prompt: impl Into<UserContent>,
deps: Deps,
) -> Result<AgentRunResult<Output>, AgentRunError>
pub fn run_sync( &self, prompt: impl Into<UserContent>, deps: Deps, ) -> Result<AgentRunResult<Output>, AgentRunError>
Run synchronously (blocking).
Note: This requires a Tokio runtime to be available.
Sourcepub async fn start_run(
&self,
prompt: impl Into<UserContent>,
deps: Deps,
options: RunOptions,
) -> Result<AgentRun<'_, Deps, Output>, AgentRunError>
pub async fn start_run( &self, prompt: impl Into<UserContent>, deps: Deps, options: RunOptions, ) -> Result<AgentRun<'_, Deps, Output>, AgentRunError>
Start a run that can be iterated.
This allows stepping through the agent’s execution manually.
Sourcepub async fn run_stream(
&self,
prompt: impl Into<UserContent>,
deps: Deps,
) -> Result<AgentStream, AgentRunError>
pub async fn run_stream( &self, prompt: impl Into<UserContent>, deps: Deps, ) -> Result<AgentStream, AgentRunError>
Run with streaming output.
Sourcepub async fn run_stream_with_options(
&self,
prompt: impl Into<UserContent>,
deps: Deps,
options: RunOptions,
) -> Result<AgentStream, AgentRunError>
pub async fn run_stream_with_options( &self, prompt: impl Into<UserContent>, deps: Deps, options: RunOptions, ) -> Result<AgentStream, AgentRunError>
Run stream with options.
Sourcepub fn static_system_prompt(&self) -> &str
pub fn static_system_prompt(&self) -> &str
Get the static system prompt.
Trait Implementations§
Auto Trait Implementations§
impl<Deps, Output> Freeze for Agent<Deps, Output>
impl<Deps = (), Output = String> !RefUnwindSafe for Agent<Deps, Output>
impl<Deps, Output> Send for Agent<Deps, Output>
impl<Deps, Output> Sync for Agent<Deps, Output>
impl<Deps, Output> Unpin for Agent<Deps, Output>
impl<Deps = (), Output = String> !UnwindSafe for Agent<Deps, Output>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more