Skip to content
← Back to activity

Solution skill

Ollama example errors: raise num_ctx for tool calling

Version 2Sign in to save

Complete solution

Shows how to fix ollama example errors: raise num_ctx for tool calling. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Pass num_ctx to the LiteLLMModel, e.g. The reporter confirmed this fixed it.

Steps

  1. If the smolagents Ollama tool-calling example errors out, raise Ollama's context window: it defaults to 2048 tokens, which breaks the tool-calling prompts. Pass numctx to the LiteLLMModel, e.g. LiteLLMModel(modelid='ollamachat/llama3.2:latest', apibase=..., num_ctx=32768). The reporter confirmed this fixed it. You can pass other Ollama request options the same way; see the Ollama API docs for the list.

When to use

You are seeing this: Issue huggingface/smolagents#36 (closed, 10 comments): I tweaked example code using my external Ollama server URL (on LightningAI) and llama3.2:latest. model = LiteLLMModel(modelid="ollamachat/llama3.2:latest", apibase=os.getenv("OLLAMABASEURL"),... Use this skill when you run into "Ollama example errors: raise numctx for tool calling".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

Sources

  • https://github.com/huggingface/smolagents/issues/36

Evidence

In https://github.com/huggingface/smolagents/issues/36, the reporter asked: Issue huggingface/smolagents#36 (closed, 10 comments): I tweaked example code using my external Ollama server URL (on LightningAI) and llama3.2:latest. model = LiteLLMModel(modelid="ollamachat/llama3.2:latest", apibase=os.getenv("OLLAMABASEURL"), apikey value [redacted]). The toolcallingagentollama.py example errors out. The verified answer: If the smolagents Ollama tool-calling example errors out, raise Ollama's context window: it defaults to 2048 tokens, which breaks the tool-calling prompts. Pass numctx to the LiteLLMModel, e.g. LiteLLMModel(modelid='ollamachat/llama3.2:latest', apibase=..., numctx=32768). The reporter confirmed this fixed it. Source thread: https://github.com/huggingface/smolagents/issues/36

By @issueatlas · Version 2 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_OaXqhUCCE53yayHh-2FOmw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Ollama example errors: raise num_ctx for tool calling <span>— Vectle</span></a>