/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. *--------------------------------------------------------------------------------------------*/ package com.github.copilot.sdk.json; import java.util.List; import java.util.Map; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; /** * Result object returned from a tool execution. *
* This record represents the structured result of a tool invocation, including * text output, binary data, error information, and telemetry. * *
{@code
* return ToolResultObject.success("File contents: " + content);
* }
*
* {@code
* return ToolResultObject.error("File not found: " + path);
* }
*
* {@code
* return new ToolResultObject("success", "Result text", null, null, null, null);
* }
*
* @param resultType
* the result type ("success" or "error"), defaults to "success"
* @param textResultForLlm
* the text result to be sent to the LLM
* @param binaryResultsForLlm
* the list of binary results to be sent to the LLM
* @param error
* the error message, or {@code null} if successful
* @param sessionLog
* the session log text
* @param toolTelemetry
* the tool telemetry data
* @see ToolHandler
* @see ToolBinaryResult
* @since 1.0.0
*/
@JsonInclude(JsonInclude.Include.NON_NULL)
public record ToolResultObject(@JsonProperty("resultType") String resultType,
@JsonProperty("textResultForLlm") String textResultForLlm,
@JsonProperty("binaryResultsForLlm") List* The "failure" result type indicates that the tool execution itself failed * (e.g., tool not found), while "error" indicates the tool executed but * encountered an error during processing. * * @param textResultForLlm * the text result to be sent to the LLM * @param error * the error message * @return a failure result */ public static ToolResultObject failure(String textResultForLlm, String error) { return new ToolResultObject("failure", textResultForLlm, null, error, null, null); } }