pub struct ToolCall {
pub id: String,
pub name: String,
pub arguments: String,
}Expand description
A tool call requested by the model.
The model requests a tool call via the tool_calls field of
Message::Assistant; after the agent loop executes it, the result is
passed back as a Message::ToolResult message right after, paired
with this call by id (which disambiguates multiple calls to the
same-named tool in one turn).
§Example
Construct a tool request and pair it with the returned execution result (in real flows the request is generated by the model and passed back automatically after the loop executes it):
use molo::{Message, ToolCall};
let request = Message::Assistant {
content: String::new(),
reasoning: None,
tool_calls: vec![ToolCall {
id: "call_1".into(),
name: "weather".into(),
arguments: r#"{"city":"Beijing"}"#.into(),
}],
};
let result = Message::tool_result("call_1", "Sunny, 23°C");
let Message::Assistant { tool_calls, .. } = &request else {
panic!("expected an assistant message");
};
assert_eq!(tool_calls[0].id, "call_1");
assert_eq!(result, Message::tool_result("call_1", "Sunny, 23°C"));Fields§
§id: StringUnique id of this call; the execution result is paired with it via
the id of Message::ToolResult.
name: StringTool name, matching the name of the tool definition
Tool::schema.
arguments: StringModel-generated arguments (JSON text), parsed by the agent loop and handed to the tool for execution.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ToolCall
impl<'de> Deserialize<'de> for ToolCall
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ToolCall, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ToolCall, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for ToolCall
Source§impl Serialize for ToolCall
impl Serialize for ToolCall
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for ToolCall
Auto Trait Implementations§
impl Freeze for ToolCall
impl RefUnwindSafe for ToolCall
impl Send for ToolCall
impl Sync for ToolCall
impl Unpin for ToolCall
impl UnsafeUnpin for ToolCall
impl UnwindSafe for ToolCall
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.