61 [[nodiscard]] std::string
text()
const;
63 [[nodiscard]] std::vector<const ContentBlock*>
tool_uses()
const;
One JSON value: null, a boolean, a number, a string, an array or an object.
Definition json.hpp:22
A small strict JSON value, parser and deterministic writer (RFC 8259).
StopReason
Why the model stopped.
Definition message.hpp:78
@ EndTurn
it finished its answer
@ StopSequence
it produced a stop sequence
@ ToolUse
it called tools and waits for their results
@ Other
a reason this version doesn't know; see ChatResponse::stop_reason_text
@ PauseTurn
the provider paused a long turn; send the conversation back to continue
@ MaxTokens
it reached max_tokens
bool IsValidToolName(const std::string &name)
Whether name is a valid tool name (^[a-zA-Z0-9_-]{1,128}$).
A request to a provider.
Definition message.hpp:99
std::string system
Definition message.hpp:101
std::vector< Message > messages
Definition message.hpp:102
bool allow_tool_calls
Whether the model may call the tools. False sends them anyway, for the cache, and tells the model not...
Definition message.hpp:109
int64_t max_tokens
Definition message.hpp:104
std::string model
Definition message.hpp:100
std::optional< double > temperature
Definition message.hpp:105
std::vector< ToolSpec > tools
Definition message.hpp:103
A provider's answer.
Definition message.hpp:113
Message message
always an assistant message
Definition message.hpp:114
StopReason stop_reason
Definition message.hpp:115
std::string stop_reason_text
the provider's own word for it, for example end_turn
Definition message.hpp:116
Usage usage
Definition message.hpp:117
std::string request_id
for a support ticket, when the provider sends one
Definition message.hpp:119
std::string model
the model that answered, as the provider reports it
Definition message.hpp:118
One block of a message's content.
Definition message.hpp:17
static ContentBlock Text(std::string text)
bool is_error
Whether a tool result reports a failure.
Definition message.hpp:36
Type
Definition message.hpp:18
@ ToolUse
the model calls a tool: id, name and input
@ ToolResult
the answer to a ToolUse: id (the call's), text and is_error
@ Thinking
the model's reasoning: text, plus the provider's block in raw
@ Opaque
anything else the provider sent: raw only
JsonValue input
A tool call's input, a JSON object.
Definition message.hpp:34
Type type
Definition message.hpp:26
static ContentBlock ToolUse(std::string id, std::string name, JsonValue input)
std::string origin
Definition message.hpp:43
std::string text
Text, a tool result's content, or thinking.
Definition message.hpp:28
std::string name
A tool call's tool name.
Definition message.hpp:32
static ContentBlock ToolResult(std::string tool_use_id, std::string content, bool is_error=false)
std::string id
A tool call's id, or for a result the id of the call it answers.
Definition message.hpp:30
JsonValue raw
For Thinking and Opaque blocks, the block exactly as the provider sent it, and the provider's name in...
Definition message.hpp:42
One turn of a conversation.
Definition message.hpp:51
static Message Assistant(std::string text)
Role
Definition message.hpp:52
static Message User(std::string text)
std::vector< const ContentBlock * > tool_uses() const
The tool calls, in order.
std::vector< ContentBlock > content
Definition message.hpp:55
std::string text() const
The text blocks joined, without thinking or tool calls.
Role role
Definition message.hpp:54
Tokens used by one request, or summed over a tool loop.
Definition message.hpp:89
Usage & operator+=(const Usage &other)
int64_t cache_creation_input_tokens
Definition message.hpp:92
int64_t output_tokens
Definition message.hpp:91
int64_t input_tokens
Definition message.hpp:90
int64_t cache_read_input_tokens
Definition message.hpp:93