pub struct SubagentHandle { /* private fields */ }Expand description
A live handle to a spawned ACP sub-agent session.
SubagentHandle serialises all ACP operations through a command channel that
is serviced by a background driver task. Concurrent reads are rejected with
AcpClientError::DriverBusy; callers must wait for the in-flight operation
to complete before issuing another read.
Dropping the handle without calling close aborts the driver
task, which in turn kills the subprocess via kill_on_drop.
Implementations§
Source§impl SubagentHandle
impl SubagentHandle
Sourcepub fn session_id(&self) -> &SessionId
pub fn session_id(&self) -> &SessionId
The ACP SessionId assigned by the sub-agent.
Sourcepub async fn send_prompt(
&mut self,
text: impl Into<String>,
) -> Result<(), AcpClientError>
pub async fn send_prompt( &mut self, text: impl Into<String>, ) -> Result<(), AcpClientError>
Send a text prompt to the sub-agent.
Returns immediately after enqueuing the prompt — the sub-agent will
process it asynchronously. Call read_update or
read_to_string to receive the response.
§Errors
Returns AcpClientError::Closed when the session has been closed,
AcpClientError::DriverDied when the background driver has exited
unexpectedly, or AcpClientError::Sdk for protocol errors.
§Examples
use zeph_acp::client::{SubagentConfig, spawn_subagent};
let cfg = SubagentConfig { command: "zeph --acp".to_owned(), ..SubagentConfig::default() };
let mut handle = spawn_subagent(cfg).await?;
handle.send_prompt("What is 2 + 2?").await?;Sourcepub async fn read_update(&mut self) -> Result<SessionMessage, AcpClientError>
pub async fn read_update(&mut self) -> Result<SessionMessage, AcpClientError>
Read one SessionMessage update from the sub-agent.
Blocks until an update arrives or the session closes. A concurrent call
returns AcpClientError::DriverBusy immediately.
§Errors
Returns AcpClientError::Closed or AcpClientError::DriverDied when
the session ends, or AcpClientError::DriverBusy when a concurrent read
is already in progress.
§Examples
use zeph_acp::client::{SubagentConfig, spawn_subagent};
let cfg = SubagentConfig { command: "zeph --acp".to_owned(), ..SubagentConfig::default() };
let mut handle = spawn_subagent(cfg).await?;
handle.send_prompt("hello").await?;
let update = handle.read_update().await?;Sourcepub async fn read_to_string(&mut self) -> Result<RunOutcome, AcpClientError>
pub async fn read_to_string(&mut self) -> Result<RunOutcome, AcpClientError>
Drain all updates until StopReason, collecting text into a RunOutcome.
Equivalent to calling read_update in a loop, filtering for text chunks and
terminating on StopReason. Ignores thought chunks, tool calls, and plans.
A send_cancel issued concurrently will interrupt the
drain and the in-flight read will resolve with StopReason::Cancelled.
§Errors
Returns AcpClientError::Closed or AcpClientError::DriverDied when
the session ends, or AcpClientError::DriverBusy when another read is in
progress.
Sourcepub async fn send_cancel(&mut self) -> Result<(), AcpClientError>
pub async fn send_cancel(&mut self) -> Result<(), AcpClientError>
Send a session/cancel notification to the sub-agent.
This does not close the session; the sub-agent should acknowledge the cancel
by sending a StopReason::Cancelled update on the active read.
The one-poll-cycle preemption guarantee (a cancel delivered while
read_update or read_to_string is blocked
will interrupt the read within one tokio::select! cycle) only applies when one of those
read operations is currently in progress. Calling send_cancel outside of an active read
sends the ACP notification but does not interrupt any future read.
§Errors
Returns AcpClientError::Closed when the session is already closed or
AcpClientError::DriverDied if the driver has exited.
Sourcepub async fn close(&mut self) -> Result<(), AcpClientError>
pub async fn close(&mut self) -> Result<(), AcpClientError>
Close the session and wait for the driver to shut down.
Idempotent: a second call returns AcpClientError::Closed immediately.
§Errors
Returns AcpClientError::DriverDied if the driver exited before the
close acknowledgement was received.
§Examples
use zeph_acp::client::{SubagentConfig, spawn_subagent};
let cfg = SubagentConfig { command: "zeph --acp".to_owned(), ..SubagentConfig::default() };
let mut handle = spawn_subagent(cfg).await?;
handle.close().await?;Trait Implementations§
Auto Trait Implementations§
impl Freeze for SubagentHandle
impl !RefUnwindSafe for SubagentHandle
impl Send for SubagentHandle
impl Sync for SubagentHandle
impl Unpin for SubagentHandle
impl UnsafeUnpin for SubagentHandle
impl !UnwindSafe for SubagentHandle
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoMaybeUndefined<T> for T
impl<T> IntoMaybeUndefined<T> for T
fn into_maybe_undefined(self) -> MaybeUndefined<T>
Source§impl<T> IntoOption<T> for T
impl<T> IntoOption<T> for T
fn into_option(self) -> Option<T>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request