# Tool/Function Calling with Llama-3.2-3B-Instruct model (local)

**URL:** <https://forum.langchain.com/t/tool-function-calling-with-llama-3-2-3b-instruct-model-local/2574>\
**Category:** LangChain\
**Tags:** python-help\
**Created:** [December 20, 2025, 3:11pm UTC](https://forum.langchain.com/t/tool-function-calling-with-llama-3-2-3b-instruct-model-local/2574 "2025-12-20T15:11:08Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![TZengCoder](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/tzengcoder/32/1995_2.png) [@TZengCoder](https://forum.langchain.com/u/TZengCoder)\
**Post date:** [December 20, 2025, 3:11pm UTC](https://forum.langchain.com/t/tool-function-calling-with-llama-3-2-3b-instruct-model-local/2574/1 "2025-12-20T15:11:08Z")

</div>

Hi, I am using meta-llama/Llama-3.1-8B-Instruct and have successfully parsed the function called and executed it through prompting. However, I am unsure how I can feed the tool result back to the model. It seems ToolMessage does not apply to Huggingface model as it asks to provide tool\_call\_id which does not exist in the previous AIMessage. However, if i check the chat template of Llama 3.1, it does show signs of receiving tool messages back through a role called ‘ipython’. However, I am unsure how I can implement using the Langchain messages framework. Would appreciate any help!

@pawel-twardziak

---

<div class="post-metadata">

**Author:** ![keenborder786](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/keenborder786/32/1757_2.png) [@keenborder786](https://forum.langchain.com/u/keenborder786)\
**Post date:** [December 23, 2025, 3:49am UTC](https://forum.langchain.com/t/tool-function-calling-with-llama-3-2-3b-instruct-model-local/2574/2 "2025-12-23T03:49:05Z")

</div>

@**[TZengCoder](https://forum.langchain.com/u/tzengcoder),** you can do something like following:

```python
from langchain_huggingface import HuggingFaceEndpoint,ChatHuggingFace
model = HuggingFaceEndpoint(repo_id="meta-llama/Llama-3.1-8B-Instruct",task="text-generation")
chat = ChatHuggingFace(llm=model, verbose=True)
agent = create_agent(model = chat, tools = [], # your tools
system_prompt = "You are a Langchain Expert" # Your main prompt)
# create agent automatically using langgraph creates a ReAct loop that you are refering to where agent executes tool, see it's output, send back to llm and generate a final message.

```

---

<div class="post-metadata">

**Author:** ![TZengCoder](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/tzengcoder/32/1995_2.png) [@TZengCoder](https://forum.langchain.com/u/TZengCoder)\
**Post date:** [December 23, 2025, 6:09am UTC](https://forum.langchain.com/t/tool-function-calling-with-llama-3-2-3b-instruct-model-local/2574/3 "2025-12-23T06:09:31Z")

</div>

Hi, thanks for the reply! Was wondering if this works with the local models like:

```auto
from langchain_huggingface import HuggingFacePipeline
from langchain.agents import create_agent
from langchain.tools import tool
llm = HuggingFacePipeline.from_model_id(
    model_id="Qwen/Qwen2.5-7B-Instruct",
    task="text-generation"
)
@tool
def get_weather(location: str) -> str:
    """Get weather information for a location."""
    return f"Weather in {location}: Sunny, 72°F"

agent = create_agent(chat_model, tools=[get_weather])
result = agent.invoke(
    {"messages": [{"role": "user", "content": "What's the weather in San Francisco?"}]}
)

```

I tried running this but the result outputs: “However, I’m a large language model, I don’t have real-time access to current weather conditions. But I can suggest some ways for you to find out…” (which does not utilize the tool). I am unsure if this is due to the local models unable to have the tools\_response attribute like those seen in openai. I only noticed huggingfaceendpoint supports tool calls in its response but not the local models

---

<div class="post-metadata">

**Author:** ![keenborder786](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/keenborder786/32/1757_2.png) [@keenborder786](https://forum.langchain.com/u/keenborder786)\
**Post date:** [December 23, 2025, 5:39pm UTC](https://forum.langchain.com/t/tool-function-calling-with-llama-3-2-3b-instruct-model-local/2574/4 "2025-12-23T17:39:23Z")

</div>

> [@TZengCoder](#):
>
> ```auto
> from langchain_huggingface import HuggingFacePipeline
> from langchain.agents import create_agent
> from langchain.tools import tool
> llm = HuggingFacePipeline.from_model_id(
> model_id="Qwen/Qwen2.5-7B-Instruct",
> task="text-generation"
> )
> @tool
> def get_weather(location: str) -> str:
> """Get weather information for a location."""
> return f"Weather in {location}: Sunny, 72°F"
> 
> agent = create_agent(chat_model, tools=[get_weather])
> result = agent.invoke(
> {"messages": [{"role": "user", "content": "What's the weather in San Francisco?"}]}
> )
> 
> ```

Please do the following:

```python
from langchain_huggingface import HuggingFacePipeline,ChatHuggingFace

from langchain.agents import create_agent

from langchain.tools import tool

llm = HuggingFacePipeline.from_model_id(

model_id=“Qwen/Qwen2.5-7B-Instruct”,

task=“text-generation”

)

chat_model = ChatHuggingFace(llm=llm)

@tool

def get_weather(location: str) → str:

“”“Get weather information for a location.”“”

return f"Weather in {location}: Sunny, 72°F"

agent = create_agent(chat_model, tools=[get_weather])

result = agent.invoke(

{"messages": \[{"role": "user", "content": "What's the weather in San Francisco?"}\]}

)

```

---

<div class="post-metadata">

**Author:** ![TZengCoder](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/tzengcoder/32/1995_2.png) [@TZengCoder](https://forum.langchain.com/u/TZengCoder)\
**Post date:** [December 23, 2025, 7:22pm UTC](https://forum.langchain.com/t/tool-function-calling-with-llama-3-2-3b-instruct-model-local/2574/5 "2025-12-23T19:22:48Z")

</div>

> [@keenborder786](#):
>
> `chat_model = ChatHuggingFace(llm=llm)`

My apologies, I accidentally left out the line when copying over from my notebook:

```auto
chat_model = ChatHuggingFace(llm=llm)

```

Hence, the output is still the same, unable to use the tool 🥲

---

<div class="post-metadata">

**Author:** ![keenborder786](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/keenborder786/32/1757_2.png) [@keenborder786](https://forum.langchain.com/u/keenborder786)\
**Post date:** [December 24, 2025, 10:07am UTC](https://forum.langchain.com/t/tool-function-calling-with-llama-3-2-3b-instruct-model-local/2574/6 "2025-12-24T10:07:53Z")

</div>

> [@keenborder786](#):
>
> ```auto
> from langchain_huggingface import HuggingFacePipeline,ChatHuggingFace
> 
> from langchain.agents import create_agent
> 
> from langchain.tools import tool
> 
> llm = HuggingFacePipeline.from_model_id(
> 
> model_id=“Qwen/Qwen2.5-7B-Instruct”,
> 
> task=“text-generation”
> 
> )
> 
> chat_model = ChatHuggingFace(llm=llm)
> 
> @tool
> 
> def get_weather(location: str) → str:
> 
> “”“Get weather information for a location.”“”
> 
> return f"Weather in {location}: Sunny, 72°F"
> 
> agent = create_agent(chat_model, tools=[get_weather])
> 
> result = agent.invoke(
> 
> {"messages": \[{"role": "user", "content": "What's the weather in San Francisco?"}\]}
> 
> )
> 
> ```

Please try the following:

```python
from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint

from langchain.agents import create_agent

from langchain.tools import tool

llm = HuggingFaceEndpoint(repo_id="Qwen/Qwen2.5-7B-Instruct",task="text-generation")

chat_model = ChatHuggingFace(llm=llm)

@tool

def get_weather(location: str) -> str:

"""Get weather information for a location."""

return f"Weather in {location}: Sunny, 72°F"

agent = create_agent(chat_model, tools=[get_weather])

result = agent.invoke(

{"messages": [{"role": "user", "content": "What's the weather in San Francisco?"}]}

)

print(result)

```

---

<div class="post-metadata">

**Author:** ![TZengCoder](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/tzengcoder/32/1995_2.png) [@TZengCoder](https://forum.langchain.com/u/TZengCoder)\
**Post date:** [December 24, 2025, 5:09pm UTC](https://forum.langchain.com/t/tool-function-calling-with-llama-3-2-3b-instruct-model-local/2574/7 "2025-12-24T17:09:28Z")

</div>

Sorry, but is there a possible solution without the use of an endpoint model as I do wish to host the model?

---

<div class="post-metadata">

**Author:** ![JYT-byte](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/jyt-byte/32/2056_2.png) [@JYT-byte](https://forum.langchain.com/u/JYT-byte)\
**Post date:** [December 29, 2025, 10:16am UTC](https://forum.langchain.com/t/tool-function-calling-with-llama-3-2-3b-instruct-model-local/2574/8 "2025-12-29T10:16:08Z")

</div>

have you solve this issue? I am facing the same situation like this

---

<div class="post-metadata">

**Author:** ![keenborder786](https://yyz1.discourse-cdn.com/flex007/user_avatar/forum.langchain.com/keenborder786/32/1757_2.png) [@keenborder786](https://forum.langchain.com/u/keenborder786)\
**Post date:** [January 3, 2026, 9:18pm UTC](https://forum.langchain.com/t/tool-function-calling-with-llama-3-2-3b-instruct-model-local/2574/9 "2026-01-03T21:18:18Z")

</div>

> [@keenborder786](#):
>
> ```auto
> from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint
> 
> from langchain.agents import create_agent
> 
> from langchain.tools import tool
> 
> llm = HuggingFaceEndpoint(repo_id="Qwen/Qwen2.5-7B-Instruct",task="text-generation")
> 
> chat_model = ChatHuggingFace(llm=llm)
> 
> @tool
> 
> def get_weather(location: str) -> str:
> 
> """Get weather information for a location."""
> 
> return f"Weather in {location}: Sunny, 72°F"
> 
> agent = create_agent(chat_model, tools=[get_weather])
> 
> result = agent.invoke(
> 
> {"messages": [{"role": "user", "content": "What's the weather in San Francisco?"}]}
> 
> )
> 
> print(result)
> 
> ```

You can pass localhost to `HuggingFaceEndpoint` as well`

```python
model = HuggingFaceEndpoint(

            endpoint_url="http://localhost:8010/",

            max_new_tokens=512,

            top_k=10,

            top_p=0.95,

            typical_p=0.95,

            temperature=0.01,

            repetition_penalty=1.03,

            huggingfacehub_api_token="my-api-key",

        )

```
