Skip to main content

ToolCall

Struct ToolCall 

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

A complete model-initiated tool invocation.

use reef_core::opaque;
use reef_core::value::tool_call;
let call = tool_call::ToolCall::new(
    tool_call::Id::new("call-1".into()),
    tool_call::Name::new("search".into()),
    opaque::Payload::copy_from_slice(br#"{"q":"reef"}"#),
);
assert_eq!(call.id().as_str(), "call-1");
assert_eq!(call.name().as_str(), "search");
assert_eq!(call.arguments().as_bytes(), br#"{"q":"reef"}"#);

§Equality

Field-wise content: same Id, same Name, and a Payload equal by the byte-wise rule that type documents. It is not correlation identity. Correlation identity is Id. ToolCallDecision::Modify can replace the call before execution and change the name and arguments; the runtime preserves the model-assigned id as correlation identity. Two values that share an id are not therefore equal, and two values that differ in id are not therefore “the same call in a later edit.”

Empty Id and Name values compare equal at this leaf; the event layer still rejects empty identities. The relation is total, so this is an Eq. Nothing here is normalized before the comparison: two argument payloads a provider would read as the same JSON are unequal whenever their bytes differ, for the same reason Payload documents.

use reef_core::opaque;
use reef_core::value::tool_call;

let call = |id: &str, name: &str, arguments: &[u8]| {
    tool_call::ToolCall::new(
        tool_call::Id::new(id.into()),
        tool_call::Name::new(name.into()),
        opaque::Payload::copy_from_slice(arguments),
    )
};

assert_eq!(
    call("call-1", "search", br#"{"q":"reef"}"#),
    call("call-1", "search", br#"{"q":"reef"}"#)
);
// Same correlation identity; different name, so a different call.
assert_ne!(
    call("call-1", "search", br#"{"q":"reef"}"#),
    call("call-1", "lookup", br#"{"q":"reef"}"#)
);
// Same JSON to a provider; different bytes, so a different call.
assert_ne!(
    call("call-1", "search", br#"{"q":"reef"}"#),
    call("call-1", "search", br#"{ "q" : "reef" }"#)
);
// Empty leaves compare equal here; the event layer still rejects empty ids.
assert_eq!(call("", "", b""), call("", "", b""));

Implementations§

Source§

impl ToolCall

Source

pub const fn new(id: Id, name: Name, arguments: Payload) -> Self

Creates a call from owned identity, name, and opaque arguments.

Source

pub const fn id(&self) -> &Id

Returns the model-assigned identity.

Source

pub const fn name(&self) -> &Name

Returns the selected tool name.

Source

pub const fn arguments(&self) -> &Payload

Returns the opaque model-supplied arguments.

Source

pub fn into_parts(self) -> (Id, Name, Payload)

Transfers every call field.

Trait Implementations§

Source§

impl Clone for ToolCall

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ToolCall

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ToolCall

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for ToolCall

Source§

impl PartialEq for ToolCall

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ToolCall

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ToolCall

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.