[GH-ISSUE #7488] Avoid clearing response content when parsing tools is unnecessary #66818

Closed
opened 2026-05-04 08:16:43 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @ouariachi on GitHub (Nov 4, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/7488

I just found this code:

resp.Message.Content = sb.String()

if len(req.Tools) > 0 {
	if toolCalls, ok := m.parseToolCalls(sb.String()); ok {
		resp.Message.ToolCalls = toolCalls
		resp.Message.Content = ""
	}
}

I don't understand why the content of the response is forced to be empty if there are tools. Wouldn't it be better if the tools are only parsed when needed?

What I need is for the AI to interpret the intent of the message and parse a tool(s) if it thinks it is necessary. For example, if I tell the AI “Hello”, don't parse the tool and return a normal message. But if I tell it “What events do I have today?”, it returns the parsed “get_calendar” tool and the empty message content.

Request example

{
    "model": "llama3.2",
    "messages": [ { "role": "user", "content": "Hi!" } ],
    "stream": false,
    "tools": [
        {
            "type": "function",
            "function": {
                "name": "get_calendar",
                "description": "Get the user's calendar with all his events."
            }
        }
    ]
}

Actual response

"message": {
    "role": "assistant",
    "content": "",
    "tool_calls": [
        {
            "function": {
                "name": "get_calendar",
                "arguments": {}
            }
        }
    ]
}

Response I want

"message": {
    "role": "assistant",
    "content": "How can I assist you today?"
}
Originally created by @ouariachi on GitHub (Nov 4, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/7488 I just found [this code](https://github.com/ollama/ollama/blob/18237be9b2a4f8b060b9888996a8cc8b02796290/server/routes.go#L1511): ```go resp.Message.Content = sb.String() if len(req.Tools) > 0 { if toolCalls, ok := m.parseToolCalls(sb.String()); ok { resp.Message.ToolCalls = toolCalls resp.Message.Content = "" } } ``` I don't understand why the content of the response is forced to be empty if there are tools. Wouldn't it be better if the tools are only parsed when needed? What I need is for the AI to interpret the intent of the message and parse a tool(s) if it thinks it is necessary. For example, if I tell the AI “Hello”, don't parse the tool and return a normal message. But if I tell it “What events do I have today?”, it returns the parsed “get_calendar” tool and the empty message content. ### Request example ```json { "model": "llama3.2", "messages": [ { "role": "user", "content": "Hi!" } ], "stream": false, "tools": [ { "type": "function", "function": { "name": "get_calendar", "description": "Get the user's calendar with all his events." } } ] } ``` ### Actual response ```json "message": { "role": "assistant", "content": "", "tool_calls": [ { "function": { "name": "get_calendar", "arguments": {} } } ] } ``` ### Response I want ```json "message": { "role": "assistant", "content": "How can I assist you today?" } ```
GiteaMirror added the feature request label 2026-05-04 08:16:43 -05:00
Author
Owner

@rick-github commented on GitHub (Nov 4, 2024):

https://github.com/ollama/ollama/issues/6127

<!-- gh-comment-id:2454214839 --> @rick-github commented on GitHub (Nov 4, 2024): https://github.com/ollama/ollama/issues/6127
Author
Owner

@rick-github commented on GitHub (Dec 2, 2024):

dupe #6127

<!-- gh-comment-id:2511752289 --> @rick-github commented on GitHub (Dec 2, 2024): dupe #6127
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#66818