[goose-llm] update example to add toolResult status error (#2854)

This commit is contained in:
Salman Mohammed
2025-06-11 19:24:06 -04:00
committed by GitHub
parent 77c9ca2c28
commit 2bdfe5bac6
3 changed files with 407 additions and 14 deletions
+71 -5
View File
@@ -29,7 +29,7 @@ fun main() = runBlocking {
"value": {
"name": "calculator_extension__toolname",
"arguments": {
"operation": "multiply",
"operation": "doesnotexist",
"numbers": [7, 6]
},
"needsApproval": false
@@ -45,6 +45,51 @@ fun main() = runBlocking {
Message(
role = Role.USER,
created = now + 3,
content = listOf(
MessageContent.ToolResp(
ToolResponse(
id = "calc1",
toolResult = """
{
"status": "error",
"error": "Invalid value for operation: 'doesnotexist'. Valid values are: ['add', 'subtract', 'multiply', 'divide']"
}
""".trimIndent()
)
)
)
),
// 4) Assistant makes a tool request (ToolReq) to calculate 7×6
Message(
role = Role.ASSISTANT,
created = now + 4,
content = listOf(
MessageContent.ToolReq(
ToolRequest(
id = "calc1",
toolCall = """
{
"status": "success",
"value": {
"name": "calculator_extension__toolname",
"arguments": {
"operation": "multiply",
"numbers": [7, 6]
},
"needsApproval": false
}
}
""".trimIndent()
)
)
)
),
// 5) User (on behalf of the tool) responds with the tool result (ToolResp)
Message(
role = Role.USER,
created = now + 5,
content = listOf(
MessageContent.ToolResp(
ToolResponse(
@@ -124,8 +169,30 @@ fun main() = runBlocking {
val extensions = listOf(calculator_extension)
val systemPreamble = "You are a helpful assistant."
// Testing with tool calls with an error in tool name
val reqToolErr = createCompletionRequest(
providerName,
providerConfig,
modelConfig,
systemPreamble,
messages = listOf(
Message(
role = Role.USER,
created = now,
content = listOf(
MessageContent.Text(
TextContent("What is 7 x 6?")
)
)
)),
extensions = extensions
)
val req = createCompletionRequest(
val respToolErr = completion(reqToolErr)
println("\nCompletion Response (one msg):\n${respToolErr.message}")
println()
val reqAll = createCompletionRequest(
providerName,
providerConfig,
modelConfig,
@@ -134,14 +201,13 @@ fun main() = runBlocking {
extensions = extensions
)
val response = completion(req)
println("\nCompletion Response:\n${response.message}")
val respAll = completion(reqAll)
println("\nCompletion Response (all msgs):\n${respAll.message}")
println()
// ---- UI Extraction (custom schema) ----
runUiExtraction(providerName, providerConfig)
// --- Prompt Override ---
val prompt_req = createCompletionRequest(
providerName,