forked from github/copilot-sdk-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToolResultObject.java
More file actions
111 lines (103 loc) · 3.74 KB
/
ToolResultObject.java
File metadata and controls
111 lines (103 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/*---------------------------------------------------------------------------------------------
* 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.
* <p>
* This record represents the structured result of a tool invocation, including
* text output, binary data, error information, and telemetry.
*
* <h2>Example: Success Result</h2>
*
* <pre>{@code
* return ToolResultObject.success("File contents: " + content);
* }</pre>
*
* <h2>Example: Error Result</h2>
*
* <pre>{@code
* return ToolResultObject.error("File not found: " + path);
* }</pre>
*
* <h2>Example: Custom Result</h2>
*
* <pre>{@code
* return new ToolResultObject("success", "Result text", null, null, null, null);
* }</pre>
*
* @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<ToolBinaryResult> binaryResultsForLlm,
@JsonProperty("error") String error, @JsonProperty("sessionLog") String sessionLog,
@JsonProperty("toolTelemetry") Map<String, Object> toolTelemetry) {
/**
* Creates a success result with the given text.
*
* @param textResultForLlm
* the text result to be sent to the LLM
* @return a success result
*/
public static ToolResultObject success(String textResultForLlm) {
return new ToolResultObject("success", textResultForLlm, null, null, null, null);
}
/**
* Creates an error result with the given error message.
*
* @param error
* the error message
* @return an error result
*/
public static ToolResultObject error(String error) {
return new ToolResultObject("error", null, null, error, null, null);
}
/**
* Creates an error result with both a text result and error message.
*
* @param textResultForLlm
* the text result to be sent to the LLM
* @param error
* the error message
* @return an error result
*/
public static ToolResultObject error(String textResultForLlm, String error) {
return new ToolResultObject("error", textResultForLlm, null, error, null, null);
}
/**
* Creates a failure result with the given text and error message.
* <p>
* 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);
}
}