#[non_exhaustive]pub struct Turn {
pub role: Role,
pub content: String,
pub parts: Vec<Part>,
pub tool_calls: Vec<ToolCall>,
pub tool_results: Vec<ToolResult>,
}Expand description
One message of the conversation a Prompt carries.
#[non_exhaustive]: a turn grew its tool fields in issue #665 and its
image Parts in issue #628 and will grow again, so it is built with
Turn::user, Turn::user_parts, Turn::assistant,
Turn::assistant_tool_calls or Turn::tool_results rather than a
struct literal.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.role: Role§content: String§parts: Vec<Part>The turn’s content as ordered Parts, where it carries any
(issue #628). When non-empty it is the whole content, in order,
and content is empty; a text-only turn keeps it
empty so it serialises exactly as before images existed.
tool_calls: Vec<ToolCall>The calls an assistant turn asked for. Carried on a
Role::Assistant turn; empty on every other turn.
tool_results: Vec<ToolResult>The results a user turn carries back for the previous assistant
turn’s calls. Carried on a Role::User turn; empty otherwise.
Implementations§
Source§impl Turn
impl Turn
Sourcepub fn user(content: impl Into<String>) -> Self
pub fn user(content: impl Into<String>) -> Self
A turn spoken by the Role::User side.
Sourcepub fn user_parts(parts: impl IntoIterator<Item = Part>) -> Self
pub fn user_parts(parts: impl IntoIterator<Item = Part>) -> Self
A user turn carrying parts — text and images in order — with an
empty content (issue #628). The way a prompt
sends an image: providers expect text and image in one message, so
the parts travel together rather than across two turns.
Sourcepub fn assistant(content: impl Into<String>) -> Self
pub fn assistant(content: impl Into<String>) -> Self
A turn spoken by the Role::Assistant side — a previous
completion, quoted back as context.
Sourcepub fn assistant_tool_calls(
content: impl Into<String>,
calls: Vec<ToolCall>,
) -> Self
pub fn assistant_tool_calls( content: impl Into<String>, calls: Vec<ToolCall>, ) -> Self
An assistant turn that asked to call calls. content is the text
the model wrote alongside the calls (often empty).
Sourcepub fn tool_results(results: Vec<ToolResult>) -> Self
pub fn tool_results(results: Vec<ToolResult>) -> Self
A user turn carrying the results of the previous assistant turn’s
tool calls — the shape a provider expects the tool answers back in.