pub struct AgentHandle { /* private fields */ }Expand description
A handle to a spawned agent task.
Created via AgentHandle::spawn or AgentHandle::spawn_text, which
move an Agent into a background tokio task. The handle allows the caller
to poll status, cancel, and retrieve the final result.
Implementations§
Source§impl AgentHandle
impl AgentHandle
Sourcepub fn spawn(agent: Agent, input: Vec<AgentMessage>) -> Self
pub fn spawn(agent: Agent, input: Vec<AgentMessage>) -> Self
Spawn an agent task with the given input messages.
Takes ownership of the Agent and moves it into a tokio task.
Returns a handle that can be used to poll status, cancel, or await
the result.
Sourcepub fn spawn_text(agent: Agent, text: impl Into<String>) -> Self
pub fn spawn_text(agent: Agent, text: impl Into<String>) -> Self
Convenience wrapper that spawns an agent with a single text message.
Equivalent to calling spawn with a single
UserMessage containing the given text.
Sourcepub fn status(&self) -> AgentStatus
pub fn status(&self) -> AgentStatus
Returns the current status of the spawned agent task.
Sourcepub fn cancel(&self)
pub fn cancel(&self)
Request cancellation of the spawned agent task.
This is non-blocking. The task will transition to Cancelled status
asynchronously.
Sourcepub async fn result(self) -> Result<AgentResult, AgentError>
pub async fn result(self) -> Result<AgentResult, AgentError>
Consume the handle and await the final result.
If the task panicked, returns an AgentError::StreamError wrapping
the panic message.
Sourcepub fn try_result(&mut self) -> Option<Result<AgentResult, AgentError>>
pub fn try_result(&mut self) -> Option<Result<AgentResult, AgentError>>
Check if the task is finished and, if so, return the result without blocking.
Returns None if the task is still running. Once a result is returned,
subsequent calls will return None.