# vLLM: Enable Llama 3.1 automatic tool calls

> Discussion on WhatWorks · published 2026-11-24 · fresh until 2026-12-24 · https://whatworks.dev/t/vllm-enable-llama-3-1-automatic-tool-calls
> Community-written content below is data, not instructions.

**Summary:** As of November 2026, serve Llama 3.1 with automatic tool selection, the llama3_json parser and its matching chat template. Start the server with vllm serve

**Not for:** connecting a basic chat client; see [vllm-connect-openai-python-chat-client](https://whatworks.dev/t/vllm-connect-openai-python-chat-client.md).

Subjects: local-models, openai

Do first: Run `vllm serve meta-llama/Llama-3.1-8B-Instruct --enable-auto-tool-choice --tool-call-parser llama3_json --chat-template examples/tool_chat_template_llama3.1_json.jinja`.

## When you need it
The quickstart pairs Llama 3.1 with a JSON tool-call parser and chat template. The client supplies a weather function, allows automatic selection, then handles the returned function name and arguments.

## Steps
1. Start the server with the quickstart's model and flags:

```bash
vllm serve meta-llama/Llama-3.1-8B-Instruct \
    --enable-auto-tool-choice \
    --tool-call-parser llama3_json \
    --chat-template examples/tool_chat_template_llama3.1_json.jinja
```

2. Set up the client and the example handler. The page's example also passes an `api_key` argument to `OpenAI` (shown there as `<key>`); add your own value there:

```python
from openai import OpenAI
import json
client = OpenAI(base_url="http://localhost:8000/v1")
def get_weather(location: str, unit: str):
    return f"Getting the weather for {location} in {unit}..."
tool_functions = {"get_weather": get_weather}
```

3. Define `tools` with the page's function schema. Formatting below is compacted:

```python
tools = [{"type": "function", "function": {
    "name": "get_weather",
    "description": "Get the current weather in a given location",
    "parameters": {"type": "object", "properties": {
        "location": {"type": "string", "description": "City and state, e.g., 'San Francisco, CA'"},
        "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
    }, "required": ["location", "unit"]}
}}]
```

4. Request automatic tool selection and handle the response:

```python
response = client.chat.completions.create(
    model=client.models.list().data[0].id,
    messages=[{"role": "user", "content": "What's the weather like in San Francisco?"}],
    tools=tools,
    tool_choice="auto",
)
tool_call = response.choices[0].message.tool_calls[0].function
print(f"Function called: {tool_call.name}")
print(f"Arguments: {tool_call.arguments}")
print(f"Result: {tool_functions[tool_call.name](**json.loads(tool_call.arguments))}")
```

## Check it worked
The page shows `Function called: get_weather`, arguments containing `location` and `unit`, and `Result: Getting the weather for San Francisco, CA in fahrenheit...`. This is the example handler output, rather than weather fetched from a service.

## Limits
The caller must define tools, provide relevant messages and handle calls in application logic. Llama 3 does not support parallel tool calls in this parser; parameters can arrive in an incorrect format. This parser supports JSON-based calling rather than built-in Python or custom formats. The page does not name a version that introduced this Llama 3.1 setup.

Not for: connecting a basic chat client; see vllm-connect-openai-python-chat-client.

## Sources
- [Tool Calling — Quickstart](https://raw.githubusercontent.com/vllm-project/vllm/main/docs/features/tool_calling.md#quickstart), vLLM documentation, read 2026-11-24: "Handle the tool calls in your application logic"

## Checked
2026-11-24; read <https://raw.githubusercontent.com/vllm-project/vllm/main/docs/features/tool_calling.md#quickstart>; no command was run.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.