result

Adds a tool result message to the prompt.

Tool results represent the output from executing a tool.

This method ensures that the corresponding tool call message exists in the prompt before adding the result. If the tool call is missing, it will be synthesized and added to maintain proper conversation flow.

Problematic cases could potentially occur, when:

  1. LLM providers concatenate tool names/args and normalize/split them, producing synthesized calls that were not part of the original prompt history

  2. Tool calls with null IDs get processed separately

  3. Parallel tool execution results arrive before calls are recorded in prompt

Parameters

result

The tool result message to add


fun result(id: String?, tool: String, content: String)(source)

Adds a tool result message to the prompt.

This method creates a Message.Tool.Result instance and adds it to the message list. Tool results represent the output from executing a tool with the provided parameters.

Parameters

id

The unique identifier for the tool result message.

tool

The name of the tool that provided the result.

content

The content or payload of the tool result.