pub struct StreamingFunctionTool { /* private fields */ }Expand description
A tool wrapping a Rust function that returns a stream of text chunks.
Implementations§
Source§impl StreamingFunctionTool
impl StreamingFunctionTool
Sourcepub fn new<Args, F, S>(
cfg: FunctionToolConfig,
f: F,
) -> Result<Arc<dyn Tool>, ToolError>
pub fn new<Args, F, S>( cfg: FunctionToolConfig, f: F, ) -> Result<Arc<dyn Tool>, ToolError>
Wraps the streaming handler f.
Fails with ToolError::InvalidArgument when Args is not an object type or the input schema cannot
be compiled.
Sourcepub fn with_confirmation_provider<Args, F, S, P>(
cfg: FunctionToolConfig,
f: F,
provider: P,
) -> Result<Arc<dyn Tool>, ToolError>
pub fn with_confirmation_provider<Args, F, S, P>( cfg: FunctionToolConfig, f: F, provider: P, ) -> Result<Arc<dyn Tool>, ToolError>
Like StreamingFunctionTool::new, with a confirmation provider: when the call
carries no confirmation, provider(&args) decides whether one is required, overriding
cfg.require_confirmation.
Trait Implementations§
Source§impl StreamingTool for StreamingFunctionTool
impl StreamingTool for StreamingFunctionTool
Source§fn run_stream(
&self,
ctx: Context,
args: Value,
) -> BoxStream<'static, Result<String, ToolError>>
fn run_stream( &self, ctx: Context, args: Value, ) -> BoxStream<'static, Result<String, ToolError>>
Runs the handler and streams its chunks.
- Lazy: nothing runs until the first poll.
- A panic while calling the handler or while polling its stream becomes one final
ToolError::Panicitem (textpanic in tool "<name>": <message>), after which the stream ends. - Dropping the returned stream drops the handler’s stream, which stops the handler.
- Consumer panics and panics raised while dropping the handler stream are never caught: the consumer is not called from inside this stream, and Drop is outside catch_unwind’s poll scope, so consumer panics propagate.
Source§impl Tool for StreamingFunctionTool
impl Tool for StreamingFunctionTool
Source§fn origin_kind(&self) -> ToolOriginKind
fn origin_kind(&self) -> ToolOriginKind
FunctionToolConfig::origin (default ToolOriginKind::Local: a streaming function
tool is a function tool too).
Source§fn description(&self) -> &str
fn description(&self) -> &str
A description of the tool.
Source§fn is_long_running(&self) -> bool
fn is_long_running(&self) -> bool
Whether the tool is a long-running operation, which typically returns a resource id first
and finishes the operation later.
Source§fn declaration(&self) -> Option<FunctionDeclaration>
fn declaration(&self) -> Option<FunctionDeclaration>
The function declaration sent to the model.
Source§fn as_streaming(&self) -> Option<&dyn StreamingTool>
fn as_streaming(&self) -> Option<&dyn StreamingTool>
The streaming capability.
Source§fn process_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 Context,
_req: &'life2 mut LlmRequest,
) -> Pin<Box<dyn Future<Output = Result<(), ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
fn process_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
_ctx: &'life1 Context,
_req: &'life2 mut LlmRequest,
) -> Pin<Box<dyn Future<Output = Result<(), ToolError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Self: 'async_trait,
Extra request edits only. The flow packs a tool that has
a
declaration with pack_tool before this runs; a tool without one
is never packed. Async because implementations may do I/O (artifact listing, memory search).Source§fn as_runnable(&self) -> Option<&dyn RunnableTool>
fn as_runnable(&self) -> Option<&dyn RunnableTool>
The runnable capability.
Source§fn defers_response(&self) -> bool
fn defers_response(&self) -> bool
Whether the tool defers its response: an empty result is then not sent to the model.
Source§fn display_result_on_skip_summarization(&self) -> bool
fn display_result_on_skip_summarization(&self) -> bool
Whether the result is also shown as a text part when the call ends the agent loop with
skip_summarization.Source§fn wrapper_key(&self) -> Option<&str>
fn wrapper_key(&self) -> Option<&str>
The
finish_task wrapper key.Source§fn unwrap(&self) -> Option<Arc<dyn Tool>>
fn unwrap(&self) -> Option<Arc<dyn Tool>>
The tool this one wraps, for a confirmation or delegating wrapper (the agent-analytics
plugin reaches the wrapped tool through it).
None for a tool that wraps nothing.Source§fn origin_agent(&self) -> Option<Arc<dyn Agent>>
fn origin_agent(&self) -> Option<Arc<dyn Agent>>
The agent a
ToolOriginKind::SubAgent tool runs (this tells a sub-agent from a remote
A2A agent).Source§fn origin_agents(&self) -> Vec<Arc<dyn Agent>>
fn origin_agents(&self) -> Vec<Arc<dyn Agent>>
Every agent the tool can hand a call to, in order, for analytics
(e.g. a transfer tool’s supported agents). Defaults to
origin_agent as a list of at most one.Auto Trait Implementations§
impl !RefUnwindSafe for StreamingFunctionTool
impl !UnwindSafe for StreamingFunctionTool
impl Forget for StreamingFunctionTool
impl Freeze for StreamingFunctionToolwhere
*const u8 is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<Value>: Freeze,
*const LeafNode<String, Value> is !null: Freeze,
PhantomData<(Owned, LeafOrInternal)>: Freeze,
PhantomData<Box<(String, Value)>>: Freeze,
*const ArcInner<CompiledSchema> is !null: Freeze,
PhantomData<ArcInner<CompiledSchema>>: Freeze,
*const ArcInner<dyn Fn(Context, Value) -> Result<Pin<Box<dyn Stream<Item = Result<String, ToolError>> + Send>>, ToolError> + Sync + Send> is !null: Freeze,
PhantomData<ArcInner<dyn Fn(Context, Value) -> Result<Pin<Box<dyn Stream<Item = Result<String, ToolError>> + Send>>, ToolError> + Sync + Send>>: Freeze,
impl Move for StreamingFunctionTool
impl Send for StreamingFunctionTool
impl Sync for StreamingFunctionTool
impl Unpin for StreamingFunctionTool
impl UnsafeUnpin for StreamingFunctionToolwhere
*const u8 is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<Value>: UnsafeUnpin,
*const LeafNode<String, Value> is !null: UnsafeUnpin,
PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin,
PhantomData<Box<(String, Value)>>: UnsafeUnpin,
*const ArcInner<CompiledSchema> is !null: UnsafeUnpin,
PhantomData<ArcInner<CompiledSchema>>: UnsafeUnpin,
*const ArcInner<dyn Fn(Context, Value) -> Result<Pin<Box<dyn Stream<Item = Result<String, ToolError>> + Send>>, ToolError> + Sync + Send> is !null: UnsafeUnpin,
PhantomData<ArcInner<dyn Fn(Context, Value) -> Result<Pin<Box<dyn Stream<Item = Result<String, ToolError>> + Send>>, ToolError> + Sync + Send>>: UnsafeUnpin,
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