1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
//! Conversation messages.
//!
//! The message data model implements serde serialization / deserialization:
//! session persistence and cross-process transport (tool definitions and
//! messages) serialize these types directly, no manual mapping needed.
//!
//! A full conversation history is expressed as a [`Message`] sequence; each
//! message consists of [content blocks](ContentBlock), currently text only.
//! The structured entry point of the content model is [`ContentBlock`] — to
//! add multimodal content (images / files), add a variant there; the shape
//! of [`Message`] stays unchanged, and consumers just match the new variant.
use ;
/// 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"));
/// ```
/// A single message in a conversation.
///
/// This type carries context uniformly between Provider / Memory / Agent:
/// what Memory stores and returns, and what Provider sends and receives,
/// are all [`Message`] sequences; Provider implementations map them to the
/// vendor's wire format.
///
/// Note: the model may request several tools in one turn, and these requests
/// **must stay in a single [`Message::Assistant`] message** — splitting them
/// across messages breaks vendor wire validation (some vendors require tool
/// results to immediately follow the assistant message carrying them, e.g.
/// DeepSeek).
///
/// # Example
///
/// Organize a conversation history with the convenience constructors (in
/// real scenarios the agent loop and Memory do this automatically):
///
/// ```
/// use molo::Message;
///
/// let history = vec![
/// Message::system("You are a helpful assistant"),
/// Message::user("How is the weather in Beijing today?"),
/// Message::assistant("Let me check the weather."),
/// Message::tool_result("call_1", "Sunny, 23°C"),
/// ];
///
/// assert_eq!(history.len(), 4);
/// assert_eq!(history[1], Message::user("How is the weather in Beijing today?"));
/// ```
/// A content block within a message.
///
/// The structured entry point of the content model: currently text only; to
/// add multimodal content (images / files), add a variant here — the shape
/// of [`Message`] stays unchanged, and consumers just match the new variant.
///
/// # Example
///
/// ```
/// use molo::{ContentBlock, Message};
///
/// let msg = Message::user_blocks(vec![
/// ContentBlock::Text("How is the weather in Beijing today?".into()),
/// ]);
///
/// assert_eq!(msg, Message::user("How is the weather in Beijing today?"));
/// ```