pub struct TurnToolContext(/* private fields */);Expand description
What the tool calls of one turn are given, whichever loop runs them.
A turn’s tool calls are run by the loop that received the model’s
answer: the stream loop (its serial and its parallel lane) or, for a
model an extension provides, the loop inside the provider round
(runtime::openai::extension_route). The host builds one of these per
turn and each loop makes every call’s ToolContext from it
(Self::for_call). So what one loop’s tools are given, the others’
are given too: there is no second list of fields to keep in step.
Two capabilities belong to one dispatch of the stream loop and are not
part of the turn’s context: tool_activation (the catalog snapshot of
one provider round) and tool_register_tx (a channel that dispatch
drains). The stream loop adds them with Self::for_dispatch. The
extension model’s loop does not have them, on purpose: its tool list is
fixed for the whole provider round, so a tool activated inside it could
not be offered or called there, and nothing would drain a registration.
The event channel is the turn’s too (tx_events of every call): the
stream’s own sender, which outlives a provider round. Only the delta
lane is made per call.
One pointer wide: it rides in ApiOptions and in the stream loop’s
state, where a copy of every capability per clone is stack the loop does
not have to spare in a debug build.
Implementations§
Source§impl TurnToolContext
impl TurnToolContext
Sourcepub fn new(
capabilities: ToolCapabilities,
limits: ToolLimits,
events: Option<UnboundedSender<StreamEvent>>,
) -> Self
pub fn new( capabilities: ToolCapabilities, limits: ToolLimits, events: Option<UnboundedSender<StreamEvent>>, ) -> Self
capabilities as the host has them for this turn. Its
tool_activation and tool_register_tx are per dispatch
(Self::for_dispatch) and are dropped here. events is the
turn’s event channel (None: the turn has no frontend to tell).
Sourcepub fn no_chat() -> Self
pub fn no_chat() -> Self
For a call that belongs to no chat (the public routing facade, used by tests): no capability at all, so the tools run in the process folder with the process environment, for no conversation, and the memory tools refuse.
Sourcepub fn for_dispatch(
&self,
tool_register_tx: UnboundedSender<Vec<Arc<dyn Tool>>>,
tool_activation: ActivationCapability,
) -> Self
pub fn for_dispatch( &self, tool_register_tx: UnboundedSender<Vec<Arc<dyn Tool>>>, tool_activation: ActivationCapability, ) -> Self
This turn’s context for one dispatch of the stream loop: with the round’s activation capability and the dispatch’s registration channel.
Sourcepub fn for_call(&self, tx_delta: Option<DeltaSender>) -> ToolContext
pub fn for_call(&self, tx_delta: Option<DeltaSender>) -> ToolContext
The context of one tool call. tx_delta is the call’s own lane for
partial output (None where the call is not shown as it runs).
pub fn capabilities(&self) -> &ToolCapabilities
pub fn limits(&self) -> &ToolLimits
Trait Implementations§
Source§impl Clone for TurnToolContext
impl Clone for TurnToolContext
Auto Trait Implementations§
impl !RefUnwindSafe for TurnToolContext
impl !UnwindSafe for TurnToolContext
impl Forget for TurnToolContext
impl Freeze for TurnToolContext
impl Move for TurnToolContext
impl Send for TurnToolContext
impl Sync for TurnToolContext
impl Unpin for TurnToolContext
impl UnsafeUnpin for TurnToolContext
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.