[GH-ISSUE #6224] Passing result from tool calling to model #3889

Closed
opened 2026-04-12 14:43:35 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @tristanMatthias on GitHub (Aug 7, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/6224

Hi there. I am trying to follow the guidelines from Meta on how to pass a result from a tool call to Llama3.1

This is per their documentation

The ollama api.ToolCall struct does not have any way to pass the result back to the model.

Is there some way we could support passing responses back to ollama/llama in Meta's preferred way? Or am I missing something?

Thank you for the great work!

### Step - 3 Result from calling the tool is passed back to the model

<|begin_of_text|><|start_header_id|>system<|end_header_id|>


            Environment: ipython
            Tools: brave_search, wolfram_alpha

            Cutting Knowledge Date: December 2023
            Today Date: 23 Jul 2024

            # Tool Instructions
            - Always execute python code in messages that you share.
            - When looking for real time information use relevant functions if available else fallback to brave_search



            You have access to the following functions:

            Use the function 'spotify_trending_songs' to: Get top trending songs on Spotify
            {"name": "spotify_trending_songs", "description": "Get top trending songs on Spotify", "parameters": {"n": {"param_type": "int", "description": "Number of trending songs to get", "required": true}}}


            If a you choose to call a function ONLY reply in the following format:
            <{start_tag}={function_name}>{parameters}{end_tag}
            where

            start_tag => `<function`
            parameters => a JSON dict with the function argument name as key and function argument value as value.
            end_tag => `</function>`

            Here is an example,
            <function=example_function_name>{"example_name": "example_value"}</function>

            Reminder:
            - Function calls MUST follow the specified format
            - Required parameters MUST be specified
            - Only call one function at a time
            - Put the entire function call reply on one line
            - Always add your sources when using search results to answer the user query

            You are a helpful assistant.<|eot_id|><|start_header_id|>user<|end_header_id|>

            Can you check the top 5 trending songs on spotify?<|eot_id|><|start_header_id|>assistant<|end_header_id|>

            <function=spotify_trending_songs>{"n": "5"}</function><|eom_id|><|start_header_id|>ipython<|end_header_id|>

            ["1. BIRDS OF A FEATHER by Billie Eilish", "2. Espresso by Sabrina Carpenter", "3. Please Please Please by Sabrina Carpenter", "4. Not Like Us by Kendrick Lamar", "5. Gata Only by FloyyMenor, Cris Mj"]<|eot_id|><|start_header_id|>assistant<|end_header_id|>            
Originally created by @tristanMatthias on GitHub (Aug 7, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/6224 Hi there. I am trying to follow the guidelines from Meta on how to pass a result from a tool call to Llama3.1 This is per [their documentation](https://llama.meta.com/docs/model-cards-and-prompt-formats/llama3_1/) The ollama [`api.ToolCall`](https://github.com/ollama/ollama/blob/main/api/types.go#L144-L146) struct does not have any way to pass the result back to the model. Is there some way we could support passing responses back to ollama/llama in Meta's preferred way? Or am I missing something? Thank you for the great work! ``` ### Step - 3 Result from calling the tool is passed back to the model <|begin_of_text|><|start_header_id|>system<|end_header_id|> Environment: ipython Tools: brave_search, wolfram_alpha Cutting Knowledge Date: December 2023 Today Date: 23 Jul 2024 # Tool Instructions - Always execute python code in messages that you share. - When looking for real time information use relevant functions if available else fallback to brave_search You have access to the following functions: Use the function 'spotify_trending_songs' to: Get top trending songs on Spotify {"name": "spotify_trending_songs", "description": "Get top trending songs on Spotify", "parameters": {"n": {"param_type": "int", "description": "Number of trending songs to get", "required": true}}} If a you choose to call a function ONLY reply in the following format: <{start_tag}={function_name}>{parameters}{end_tag} where start_tag => `<function` parameters => a JSON dict with the function argument name as key and function argument value as value. end_tag => `</function>` Here is an example, <function=example_function_name>{"example_name": "example_value"}</function> Reminder: - Function calls MUST follow the specified format - Required parameters MUST be specified - Only call one function at a time - Put the entire function call reply on one line - Always add your sources when using search results to answer the user query You are a helpful assistant.<|eot_id|><|start_header_id|>user<|end_header_id|> Can you check the top 5 trending songs on spotify?<|eot_id|><|start_header_id|>assistant<|end_header_id|> <function=spotify_trending_songs>{"n": "5"}</function><|eom_id|><|start_header_id|>ipython<|end_header_id|> ["1. BIRDS OF A FEATHER by Billie Eilish", "2. Espresso by Sabrina Carpenter", "3. Please Please Please by Sabrina Carpenter", "4. Not Like Us by Kendrick Lamar", "5. Gata Only by FloyyMenor, Cris Mj"]<|eot_id|><|start_header_id|>assistant<|end_header_id|> ```
GiteaMirror added the feature requestneeds more info labels 2026-04-12 14:43:35 -05:00
Author
Owner

@mxyng commented on GitHub (Aug 7, 2024):

api.ToolCall is an assistant's response to a user message to indicate it wants to call a tool.

What you're looking for is a Message with role tool and content the tool result

Here's a full tool call exchange:

[
  {"role":"user","content":"What's the weather today in San Francisco?"},
  {"role":"assistant","tool_calls":[{"function":{"name":"arguments","arguments":"location":"San Francisco, CA"}}]},
  {"role":"tool","content":"70F"},
  {"role":"assistant","content":"The weather today in San Francisco is 70 Fahrenheit"}
]
<!-- gh-comment-id:2273816419 --> @mxyng commented on GitHub (Aug 7, 2024): `api.ToolCall` is an assistant's response to a user message to indicate it wants to call a tool. What you're looking for is a Message with role `tool` and content the tool result Here's a full tool call exchange: ```json [ {"role":"user","content":"What's the weather today in San Francisco?"}, {"role":"assistant","tool_calls":[{"function":{"name":"arguments","arguments":"location":"San Francisco, CA"}}]}, {"role":"tool","content":"70F"}, {"role":"assistant","content":"The weather today in San Francisco is 70 Fahrenheit"} ] ```
Author
Owner

@tristanMatthias commented on GitHub (Aug 7, 2024):

Thanks for your response. I tried that and was consistently getting an empty response back from the LLM. My "content" was a JSON object:

type ToolCallRun struct {
	Channel   chan<- *ToolCallRun                         `json:"-"`
	CallID    string                                      `json:"id"`
	Tool      string                                      `json:"tool"`
	Arguments api.ToolCallFunctionArguments               `json:"arguments"`
	Status    messages.MessageContentToolCallStatusStatus `json:"status"`
	Result    json.RawMessage                             `json:"result"`
	Error     error                                       `json:"error"`
	Final     bool                                        `json:"final"`
}

I tried playing around with different role's, but it seemed as if the LLM didn't even register them. It was often asking for extra input, or saying it couldn't find the relevant information.

<!-- gh-comment-id:2274084384 --> @tristanMatthias commented on GitHub (Aug 7, 2024): Thanks for your response. I tried that and was consistently getting an empty response back from the LLM. My "content" was a JSON object: ``` type ToolCallRun struct { Channel chan<- *ToolCallRun `json:"-"` CallID string `json:"id"` Tool string `json:"tool"` Arguments api.ToolCallFunctionArguments `json:"arguments"` Status messages.MessageContentToolCallStatusStatus `json:"status"` Result json.RawMessage `json:"result"` Error error `json:"error"` Final bool `json:"final"` } ``` I tried playing around with different `role`'s, but it seemed as if the LLM didn't even register them. It was often asking for extra input, or saying it couldn't find the relevant information.
Author
Owner

@mitar commented on GitHub (Aug 15, 2024):

That depends on the model. I had issues with some models returning anything after giving them the response from the tool (with "role":"tool"). See example here as well.

<!-- gh-comment-id:2291981698 --> @mitar commented on GitHub (Aug 15, 2024): That depends on the model. I had issues with some models returning anything after giving them the response from the tool (with `"role":"tool"`). See [example here as well](https://github.com/ollama/ollama-python/blob/main/examples/tools/main.py#L74-L79).
Author
Owner

@jmorganca commented on GitHub (Sep 2, 2024):

@tristanMatthias may I ask which model this is? And what code you're using to interact with Ollama? This will help us debug.

<!-- gh-comment-id:2325379109 --> @jmorganca commented on GitHub (Sep 2, 2024): @tristanMatthias may I ask which model this is? And what code you're using to interact with Ollama? This will help us debug.
Author
Owner

@maks commented on GitHub (Oct 2, 2025):

@jmorganca sorry to comment on a closed issue, let me know if this should be filed as a new issue but I am seeing this with ollama 0.12.3.

Using llama3.2:3b a80c4f17acd5 I get an expected response from the model after passing back the results of tool call from its prior response.
If I do the same with with gpt-oss:20b f2b8351c629c , which is listed as supporting tool calling, I don't get back any response after sending back the results of the tool call.

<!-- gh-comment-id:3359235225 --> @maks commented on GitHub (Oct 2, 2025): @jmorganca sorry to comment on a closed issue, let me know if this should be filed as a new issue but I am seeing this with ollama 0.12.3. Using `llama3.2:3b a80c4f17acd5 ` I get an expected response from the model after passing back the results of tool call from its prior response. If I do the same with with `gpt-oss:20b f2b8351c629c ` , which is listed as supporting tool calling, I don't get back any response after sending back the results of the tool call.
Author
Owner

@leo95batista commented on GitHub (Oct 9, 2025):

@maks well.. in my case, I'm getting the same wrong behavior with llama3.2:latest... Also, I have noticed that Ollama is executing the tools, even when the prompt does not ask for anything related to a defined tool, it is as if whenever tools are passed to the request, it executes them regardless of whether they are needed or not.

<!-- gh-comment-id:3387247990 --> @leo95batista commented on GitHub (Oct 9, 2025): @maks well.. in my case, I'm getting the same wrong behavior with llama3.2:latest... Also, I have noticed that Ollama is executing the tools, even when the prompt does not ask for anything related to a defined tool, it is as if whenever tools are passed to the request, it executes them regardless of whether they are needed or not.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#3889