Skip to content

ToolModelMessage

Namespace: Vercel.AI.Provider

public sealed class ToolModelMessage : ModelMessage

A tool result fed back to the model.

Inheritance: object → ModelMessage

View source

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>

View source

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?

View source

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?

View source

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?

View source

public bool IsError { get; }

Whether the tool failed.

Value: bool

View source

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>

View source

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>

View source

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

View source

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?

View source

public string OutputType { get; }

Output type: text, json, error-text, error-json, or execution-denied.

Value: string

View source

public JsonElement? ProviderMetadata { get; }

Provider metadata carried on this tool result, such as a thought signature.

Value: JsonElement?

View source

public IReadOnlyDictionary<string, JsonElement>? ProviderOptions { get; init; }

Provider options set on this tool result, such as an Amazon Bedrock cachePoint.

Value: IReadOnlyDictionary<string, JsonElement>

View source

public IReadOnlyList<ToolModelMessage> Results { get; }

The tool results this message carries, one per executed call. A single-result message lists itself.

Value: IReadOnlyList<ToolModelMessage>

View source

public string ToolCallId { get; }

Matching tool call id.

Value: string

View source

public string ToolName { get; }

Tool name.

Value: string

View source

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>

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product