pub struct ToolParkingLot { /* private fields */ }Expand description
A parking lot for custom tool calls awaiting client-delivered results.
The session loop calls park when agent.custom_tool_use is emitted,
blocking until either:
- The client sends
user.custom_tool_resultand the runtime callsdeliver - The configured timeout elapses, returning
RuntimeError::ToolTimeout
Thread-safe: the internal map is protected by a Mutex.
Implementations§
Source§impl ToolParkingLot
impl ToolParkingLot
Sourcepub fn new(timeout: Duration) -> Self
pub fn new(timeout: Duration) -> Self
Create a new parking lot with the specified timeout.
§Arguments
timeout- Maximum duration to wait for a tool result before returningRuntimeError::ToolTimeout.
Sourcepub fn with_default_timeout() -> Self
pub fn with_default_timeout() -> Self
Create a new parking lot with the default timeout (5 minutes).
Sourcepub async fn park(
&self,
tool_use_id: &str,
) -> Result<Vec<ContentBlock>, RuntimeError>
pub async fn park( &self, tool_use_id: &str, ) -> Result<Vec<ContentBlock>, RuntimeError>
Park the session loop, waiting for a custom tool result.
Creates a oneshot channel, stores the sender under tool_use_id, and
awaits the receiver. Returns the content blocks when delivered, or
RuntimeError::ToolTimeout if the timeout elapses.
§Errors
RuntimeError::ToolTimeoutif no result is delivered within the timeout.RuntimeError::Internalif the sender is dropped unexpectedly.
Sourcepub async fn deliver(
&self,
tool_use_id: &str,
content: Vec<ContentBlock>,
) -> Result<(), RuntimeError>
pub async fn deliver( &self, tool_use_id: &str, content: Vec<ContentBlock>, ) -> Result<(), RuntimeError>
Deliver a result to a parked tool call.
Looks up the sender by tool_use_id and sends the content. Returns an
error if no pending call with this ID exists (e.g., it already timed out
or was never parked).
§Errors
RuntimeError::NotFoundif no pending call exists for the given ID.