bug: ollama fails to return results from multiple tools
I ran into an issue where Ollama calls multiple tools, and while the logs show all tools being invoked, only one result is returned. I suspect this is due to content.first() dropping the other tool responses.
Originally posted by @Benaiad in https://github.com/0xPlaygrounds/rig/pull/478#discussion_r2203265430
Logs (trimmed to relevant tool calls) - Ollama invoking two tools, only one returned
❯ calculate 20+50/5+100 and what date is 30 days from now
2025-07-13T08:23:47.754036Z DEBUG Ollama chat response:
{
"model": "llama3.2",
"created_at": "2025-07-13T08:23:47.753597Z",
"message": {
"role": "assistant",
"content": "",
"tool_calls": [
{
"function": {
"name": "calculator",
"arguments": {
"expression": "20+50/5+100"
}
}
},
{
"function": {
"index": 1,
"name": "datetime",
"arguments": {
"date": "now",
"days": "30",
"operation": "add"
}
}
}
]
},
"done_reason": "stop",
"done": true,
"total_duration": 1091956542,
"load_duration": 16995833,
"prompt_eval_count": 1324,
"prompt_eval_duration": 605331750,
"eval_count": 50,
"eval_duration": 468616875
}
2025-07-13T08:23:47.754174Z INFO Calculator tool called with args: CalculatorArgs { expression: "20+50/5+100" }
2025-07-13T08:23:47.754275Z INFO Calculator tool returning: CalculatorOutput { result: 130.0, expression: "20+50/5+100" }
2025-07-13T08:23:47.754322Z INFO DateTime tool called with args: DateTimeArgs { operation: "add", format: None, date: Some("now"), from: None, to: None, days: Some(30), hours: None, minutes: None, seconds: None, unit: None }
2025-07-13T08:23:47.754469Z INFO DateTime tool returning: DateTimeOutput { result: "2025-08-12T08:23:47.754345+00:00", details: Some(Object {"added": Object {"days": Number(30), "hours": Number(0), "minutes": Number(0), "seconds": Number(0)}, "original": String("2025-07-13T08:23:47.754345+00:00")}) }
2025-07-13T08:23:47.754675Z DEBUG Chat mode payload:
{
"messages": [
{
"content": "You are the ...",
"role": "system"
},
{
"content": "calculate 20+50/5+100 and what date is 30 days from now",
"role": "user"
},
{
"content": "",
"role": "assistant",
"tool_calls": [
{
"function": {
"arguments": {
"expression": "20+50/5+100"
},
"name": "calculator"
},
"type": "function"
},
{
"function": {
"arguments": {
"date": "now",
"days": "30",
"operation": "add"
},
"name": "datetime"
},
"type": "function"
}
]
},
{
"content": "{\"result\":130.0,\"expression\":\"20+50/5+100\"}",
"name": "calculator",
"role": "tool"
}
],
"model": "llama3.2",
"options": {
"temperature": null
},
"stream": false,
"tools": [
{
"function": {
"description": "Evaluate mathematical expressions. Supports basic arithmetic (+, -, *, /), exponents (^), parentheses, and common functions (sin, cos, tan, log, sqrt, etc.)",
"name": "calculator",
"parameters": {
"properties": {
"expression": {
"description": "The mathematical expression to evaluate, e.g., '2 + 2', 'sin(3.14)', 'sqrt(16) * 3'",
"type": "string"
}
},
"required": [
"expression"
],
"type": "object"
}
},
"type": "function"
},
{
"function": {
"description": "Get current date/time or perform date arithmetic operations. If no parameters are provided, returns current date/time.",
"name": "datetime",
"parameters": {
"properties": {
"date": {
"description": "Base date for operations (ISO format or 'now')",
"type": "string"
},
"days": {
"description": "Days to add/subtract",
"type": "integer"
},
"format": {
"description": "Format string for date output (e.g., '%Y-%m-%d %H:%M:%S')",
"type": "string"
},
"from": {
"description": "Start date for difference calculation",
"type": "string"
},
"hours": {
"description": "Hours to add/subtract",
"type": "integer"
},
"minutes": {
"description": "Minutes to add/subtract",
"type": "integer"
},
"operation": {
"description": "The operation to perform. Defaults to 'now' if not specified.",
"enum": [
"now",
"format",
"add",
"subtract",
"difference"
],
"type": "string"
},
"seconds": {
"description": "Seconds to add/subtract",
"type": "integer"
},
"to": {
"description": "End date for difference calculation",
"type": "string"
},
"unit": {
"description": "Unit for difference result (default: days)",
"enum": [
"days",
"hours",
"minutes",
"seconds"
],
"type": "string"
}
},
"type": "object"
}
},
"type": "function"
},
{
"function": {
"description": "Generate random numbers, strings, or make random choices. If no parameters provided, generates a random integer between 1 and 100.",
"name": "random",
"parameters": {
"properties": {
"allow_duplicates": {
"description": "Allow duplicate selections (default: false)",
"type": "boolean"
},
"charset": {
"description": "Character set for random string (default: alphanumeric)",
"enum": [
"alphanumeric",
"alphabetic",
"numeric",
"hex",
"base64"
],
"type": "string"
},
"count": {
"description": "Number of values to generate (default: 1)",
"type": "integer"
},
"length": {
"description": "Length of random string (default: 10)",
"type": "integer"
},
"max": {
"description": "Maximum value for integer/float (default: 100 for integer, 1 for float)",
"type": "number"
},
"min": {
"description": "Minimum value for integer/float (default: 1 for integer, 0 for float)",
"type": "number"
},
"options": {
"description": "Options to choose from (for 'choice' type)",
"items": {
"type": "string"
},
"type": "array"
},
"type": {
"description": "Type of random value to generate (default: integer)",
"enum": [
"integer",
"float",
"boolean",
"string",
"choice",
"uuid"
],
"type": "string"
}
},
"type": "object"
}
},
"type": "function"
},
{
"function": {
"description": "Store an important fact, preference, or observation about the user for future reference",
"name": "remember",
"parameters": {
"properties": {
"category": {
"description": "The type of memory to store",
"enum": [
"preference",
"fact",
"pattern",
"goal",
"context"
],
"type": "string"
},
"confidence": {
"description": "How confident you are about this information (0-1)",
"maximum": 1,
"minimum": 0,
"type": "number"
},
"content": {
"description": "The information to remember about the user",
"type": "string"
},
"importance": {
"description": "How important this information is (0-1)",
"maximum": 1,
"minimum": 0,
"type": "number"
},
"metadata": {
"description": "Additional metadata about this memory",
"type": "object"
}
},
"required": [
"category",
"content"
],
"type": "object"
}
},
"type": "function"
},
{
"function": {
"description": "Retrieve stored memories about the user",
"name": "recall",
"parameters": {
"properties": {
"category": {
"description": "Filter by memory category",
"enum": [
"preference",
"fact",
"pattern",
"goal",
"context"
],
"type": "string"
},
"limit": {
"description": "Maximum number of memories to retrieve",
"maximum": 20,
"minimum": 1,
"type": "integer"
},
"query": {
"description": "Search query to find specific memories",
"type": "string"
}
},
"type": "object"
}
},
"type": "function"
},
{
"function": {
"description": "Remove a specific memory about the user",
"name": "forget",
"parameters": {
"properties": {
"memory_id": {
"description": "The ID of the memory to forget (first 8 characters are sufficient)",
"type": "string"
}
},
"required": [
"memory_id"
],
"type": "object"
}
},
"type": "function"
}
]
}
Logs (trimmed to relevant tool calls) - Ollama invoking two tools, only one returned ❯ calculate 20+50/5+100 and what date is 30 days from now
2025-07-13T08:23:47.754036Z DEBUG Ollama chat response: { "model": "llama3.2", "created_at": "2025-07-13T08:23:47.753597Z", "message": { "role": "assistant", "content": "", "tool_calls": [ { "function": { "name": "calculator", "arguments": { "expression": "20+50/5+100" } } }, { "function": { "index": 1, "name": "datetime", "arguments": { "date": "now", "days": "30", "operation": "add" } } } ] }, "done_reason": "stop", "done": true, "total_duration": 1091956542, "load_duration": 16995833, "prompt_eval_count": 1324, "prompt_eval_duration": 605331750, "eval_count": 50, "eval_duration": 468616875 }2025-07-13T08:23:47.754174Z INFO Calculator tool called with args: CalculatorArgs { expression: "20+50/5+100" } 2025-07-13T08:23:47.754275Z INFO Calculator tool returning: CalculatorOutput { result: 130.0, expression: "20+50/5+100" }2025-07-13T08:23:47.754322Z INFO DateTime tool called with args: DateTimeArgs { operation: "add", format: None, date: Some("now"), from: None, to: None, days: Some(30), hours: None, minutes: None, seconds: None, unit: None } 2025-07-13T08:23:47.754469Z INFO DateTime tool returning: DateTimeOutput { result: "2025-08-12T08:23:47.754345+00:00", details: Some(Object {"added": Object {"days": Number(30), "hours": Number(0), "minutes": Number(0), "seconds": Number(0)}, "original": String("2025-07-13T08:23:47.754345+00:00")}) }2025-07-13T08:23:47.754675Z DEBUG Chat mode payload: { "messages": [ { "content": "You are the ...", "role": "system" }, { "content": "calculate 20+50/5+100 and what date is 30 days from now", "role": "user" }, { "content": "", "role": "assistant", "tool_calls": [ { "function": { "arguments": { "expression": "20+50/5+100" }, "name": "calculator" }, "type": "function" }, { "function": { "arguments": { "date": "now", "days": "30", "operation": "add" }, "name": "datetime" }, "type": "function" } ] }, { "content": "{\"result\":130.0,\"expression\":\"20+50/5+100\"}", "name": "calculator", "role": "tool" } ], "model": "llama3.2", "options": { "temperature": null }, "stream": false, "tools": [ { "function": { "description": "Evaluate mathematical expressions. Supports basic arithmetic (+, -, *, /), exponents (^), parentheses, and common functions (sin, cos, tan, log, sqrt, etc.)", "name": "calculator", "parameters": { "properties": { "expression": { "description": "The mathematical expression to evaluate, e.g., '2 + 2', 'sin(3.14)', 'sqrt(16) * 3'", "type": "string" } }, "required": [ "expression" ], "type": "object" } }, "type": "function" }, { "function": { "description": "Get current date/time or perform date arithmetic operations. If no parameters are provided, returns current date/time.", "name": "datetime", "parameters": { "properties": { "date": { "description": "Base date for operations (ISO format or 'now')", "type": "string" }, "days": { "description": "Days to add/subtract", "type": "integer" }, "format": { "description": "Format string for date output (e.g., '%Y-%m-%d %H:%M:%S')", "type": "string" }, "from": { "description": "Start date for difference calculation", "type": "string" }, "hours": { "description": "Hours to add/subtract", "type": "integer" }, "minutes": { "description": "Minutes to add/subtract", "type": "integer" }, "operation": { "description": "The operation to perform. Defaults to 'now' if not specified.", "enum": [ "now", "format", "add", "subtract", "difference" ], "type": "string" }, "seconds": { "description": "Seconds to add/subtract", "type": "integer" }, "to": { "description": "End date for difference calculation", "type": "string" }, "unit": { "description": "Unit for difference result (default: days)", "enum": [ "days", "hours", "minutes", "seconds" ], "type": "string" } }, "type": "object" } }, "type": "function" }, { "function": { "description": "Generate random numbers, strings, or make random choices. If no parameters provided, generates a random integer between 1 and 100.", "name": "random", "parameters": { "properties": { "allow_duplicates": { "description": "Allow duplicate selections (default: false)", "type": "boolean" }, "charset": { "description": "Character set for random string (default: alphanumeric)", "enum": [ "alphanumeric", "alphabetic", "numeric", "hex", "base64" ], "type": "string" }, "count": { "description": "Number of values to generate (default: 1)", "type": "integer" }, "length": { "description": "Length of random string (default: 10)", "type": "integer" }, "max": { "description": "Maximum value for integer/float (default: 100 for integer, 1 for float)", "type": "number" }, "min": { "description": "Minimum value for integer/float (default: 1 for integer, 0 for float)", "type": "number" }, "options": { "description": "Options to choose from (for 'choice' type)", "items": { "type": "string" }, "type": "array" }, "type": { "description": "Type of random value to generate (default: integer)", "enum": [ "integer", "float", "boolean", "string", "choice", "uuid" ], "type": "string" } }, "type": "object" } }, "type": "function" }, { "function": { "description": "Store an important fact, preference, or observation about the user for future reference", "name": "remember", "parameters": { "properties": { "category": { "description": "The type of memory to store", "enum": [ "preference", "fact", "pattern", "goal", "context" ], "type": "string" }, "confidence": { "description": "How confident you are about this information (0-1)", "maximum": 1, "minimum": 0, "type": "number" }, "content": { "description": "The information to remember about the user", "type": "string" }, "importance": { "description": "How important this information is (0-1)", "maximum": 1, "minimum": 0, "type": "number" }, "metadata": { "description": "Additional metadata about this memory", "type": "object" } }, "required": [ "category", "content" ], "type": "object" } }, "type": "function" }, { "function": { "description": "Retrieve stored memories about the user", "name": "recall", "parameters": { "properties": { "category": { "description": "Filter by memory category", "enum": [ "preference", "fact", "pattern", "goal", "context" ], "type": "string" }, "limit": { "description": "Maximum number of memories to retrieve", "maximum": 20, "minimum": 1, "type": "integer" }, "query": { "description": "Search query to find specific memories", "type": "string" } }, "type": "object" } }, "type": "function" }, { "function": { "description": "Remove a specific memory about the user", "name": "forget", "parameters": { "properties": { "memory_id": { "description": "The ID of the memory to forget (first 8 characters are sufficient)", "type": "string" } }, "required": [ "memory_id" ], "type": "object" } }, "type": "function" } ] }
Thank you for being so prompt with follow-up information! I'll get to work and ensure a PR gets opened soon.