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.