Skip to main content

StreamingFunctionTool

Struct StreamingFunctionTool 

Source
pub struct StreamingFunctionTool { /* private fields */ }
Expand description

A tool wrapping a Rust function that returns a stream of text chunks.

Implementations§

Source§

impl StreamingFunctionTool

Source

pub fn new<Args, F, S>( cfg: FunctionToolConfig, f: F, ) -> Result<Arc<dyn Tool>, ToolError>
where Args: DeserializeOwned + JsonSchema + Send + 'static, F: Fn(Context, Args) -> S + Send + Sync + 'static, S: Stream<Item = Result<String, ToolError>> + Send + 'static,

Wraps the streaming handler f.

Fails with ToolError::InvalidArgument when Args is not an object type or the input schema cannot be compiled.

Source

pub fn with_confirmation_provider<Args, F, S, P>( cfg: FunctionToolConfig, f: F, provider: P, ) -> Result<Arc<dyn Tool>, ToolError>
where Args: DeserializeOwned + JsonSchema + Send + 'static, F: Fn(Context, Args) -> S + Send + Sync + 'static, S: Stream<Item = Result<String, ToolError>> + Send + 'static, P: Fn(&Args) -> bool + Send + Sync + 'static,

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

Source§

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::Panic item (text panic 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

Source§

fn origin_kind(&self) -> ToolOriginKind

FunctionToolConfig::origin (default ToolOriginKind::Local: a streaming function tool is a function tool too).

Source§

fn name(&self) -> &str

The name of the tool.
Source§

fn description(&self) -> &str

A description of the tool.
Source§

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>

The function declaration sent to the model.
Source§

fn as_streaming(&self) -> Option<&dyn StreamingTool>

The streaming capability.
Source§

fn as_any(&self) -> &dyn Any

Downcasting support.
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,

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>

The runnable capability.
Source§

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

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>

The finish_task wrapper key.
Source§

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>>

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>>

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 StreamingFunctionTool
where *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
where RawVecInner: Send, NodeRef<Owned, String, Value, LeafOrInternal>: Send, BoxRaw<(String, Value)>: Send, Arc<CompiledSchema>: Send, Arc<dyn Fn(Context, Value) -> Result<Pin<Box<dyn Stream<Item = Result<String, ToolError>> + Send>>, ToolError> + Sync + Send>: Send,

§

impl Sync for StreamingFunctionTool
where RawVecInner: Sync, NodeRef<Owned, String, Value, LeafOrInternal>: Sync, BoxRaw<(String, Value)>: Sync, Arc<CompiledSchema>: Sync, Arc<dyn Fn(Context, Value) -> Result<Pin<Box<dyn Stream<Item = Result<String, ToolError>> + Send>>, ToolError> + Sync + Send>: Sync,

§

impl Unpin for StreamingFunctionTool
where *const u8 is !null: Unpin, *const LeafNode<String, Value> is !null: Unpin, Box<(String, Value)>: Unpin, Arc<CompiledSchema>: Unpin, Arc<dyn Fn(Context, Value) -> Result<Pin<Box<dyn Stream<Item = Result<String, ToolError>> + Send>>, ToolError> + Sync + Send>: Unpin,

§

impl UnsafeUnpin for StreamingFunctionTool
where *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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more