ToolModelMessage
Namespace: Vercel.AI.Provider
public sealed class ToolModelMessage : ModelMessageA tool result fed back to the model.
Inheritance: object → ModelMessage
Constructors
Section titled “Constructors”ToolModelMessage(IReadOnlyList<ToolModelMessage>)
Section titled “ToolModelMessage(IReadOnlyList<ToolModelMessage>)”public ToolModelMessage(IReadOnlyList<ToolModelMessage> results)Creates one tool message that carries several tool results, as upstream does for the calls of one step. Its single-result members describe the first result.
Parameters
| Name | Type | Description |
|---|---|---|
results |
IReadOnlyList<ToolModelMessage> |
ToolModelMessage(string, string, IReadOnlyList<UserContentPart>, JsonElement?)
Section titled “ToolModelMessage(string, string, IReadOnlyList<UserContentPart>, JsonElement?)”public ToolModelMessage(string toolCallId, string toolName, IReadOnlyList<UserContentPart> content, JsonElement? providerMetadata = null)Creates a tool result whose output is a list of text and file parts, as upstream output: { type: 'content' }.
OutputType is json and OutputJson is the JSON text of the parts, so a provider that
does not read OutputContent sends the stringified parts, as upstream does by default.
Parameters
| Name | Type | Description |
|---|---|---|
toolCallId |
string | |
toolName |
string | |
content |
IReadOnlyList<UserContentPart> | |
providerMetadata |
JsonElement? |
ToolModelMessage(string, string, string, bool, JsonElement?)
Section titled “ToolModelMessage(string, string, string, bool, JsonElement?)”public ToolModelMessage(string toolCallId, string toolName, string outputJson, bool isError, JsonElement? providerMetadata = null)Creates a tool result message. The output type comes from <code class=“paramref”>isError</code> and from whether <code class=“paramref”>outputJson</code> is valid JSON.
Parameters
| Name | Type | Description |
|---|---|---|
toolCallId |
string | |
toolName |
string | |
outputJson |
string | |
isError |
bool | |
providerMetadata |
JsonElement? |
ToolModelMessage(string, string, string?, bool, string?, JsonElement?)
Section titled “ToolModelMessage(string, string, string?, bool, string?, JsonElement?)”public ToolModelMessage(string toolCallId, string toolName, string? outputJson, bool isError, string? outputType, JsonElement? providerMetadata = null)Creates a tool result message. <code class=“paramref”>outputType</code> is text, json, error-text, error-json,
or execution-denied. When it is null, the type comes from <code class=“paramref”>isError</code> and from whether
<code class=“paramref”>outputJson</code> is valid JSON. When it is set, it decides IsError and <code class=“paramref”>isError</code> is ignored.
For execution-denied, <code class=“paramref”>outputJson</code> is the reason, or null for none.
Parameters
| Name | Type | Description |
|---|---|---|
toolCallId |
string | |
toolName |
string | |
outputJson |
string | |
isError |
bool | |
outputType |
string | |
providerMetadata |
JsonElement? |
Properties
Section titled “Properties”IsError
Section titled “IsError”public bool IsError { get; }Whether the tool failed.
Value: bool
MessageProviderOptions
Section titled “MessageProviderOptions”public IReadOnlyDictionary<string, JsonElement>? MessageProviderOptions { get; init; }Provider options of the whole tool message, such as an Amazon Bedrock cachePoint added after all its results.
Value: IReadOnlyDictionary<string, JsonElement>
OutputContent
Section titled “OutputContent”public IReadOnlyList<UserContentPart>? OutputContent { get; }Text and file parts of a multi-part output, or null for a single value. OutputJson holds the same parts as JSON text.
Value: IReadOnlyList<UserContentPart>
OutputJson
Section titled “OutputJson”public string OutputJson { get; }JSON result. For text and error-text it is the text itself. For execution-denied it is the reason, or empty for none.
Value: string
OutputProviderOptions
Section titled “OutputProviderOptions”public JsonElement? OutputProviderOptions { get; init; }Provider options set on the tool output itself rather than on the tool result, such as an OpenAI promptCacheBreakpoint.
Value: JsonElement?
OutputType
Section titled “OutputType”public string OutputType { get; }Output type: text, json, error-text, error-json, or execution-denied.
Value: string
ProviderMetadata
Section titled “ProviderMetadata”public JsonElement? ProviderMetadata { get; }Provider metadata carried on this tool result, such as a thought signature.
Value: JsonElement?
ProviderOptions
Section titled “ProviderOptions”public IReadOnlyDictionary<string, JsonElement>? ProviderOptions { get; init; }Provider options set on this tool result, such as an Amazon Bedrock cachePoint.
Value: IReadOnlyDictionary<string, JsonElement>
Results
Section titled “Results”public IReadOnlyList<ToolModelMessage> Results { get; }The tool results this message carries, one per executed call. A single-result message lists itself.
Value: IReadOnlyList<ToolModelMessage>
ToolCallId
Section titled “ToolCallId”public string ToolCallId { get; }Matching tool call id.
Value: string
ToolName
Section titled “ToolName”public string ToolName { get; }Tool name.
Value: string
Methods
Section titled “Methods”Flatten(IReadOnlyList<ModelMessage>)
Section titled “Flatten(IReadOnlyList<ModelMessage>)”public static IReadOnlyList<ModelMessage> Flatten(IReadOnlyList<ModelMessage> messages)Splits grouped tool messages into one message per result, in order. Other messages pass through.
Parameters
| Name | Type | Description |
|---|---|---|
messages |
IReadOnlyList<ModelMessage> |
Returns: IReadOnlyList<ModelMessage>
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product