Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

Bug: long running agent tasks in Ollama leads to unexpected stop tokens before tool calls

Aberta
#672 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 2 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
74/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
clojure, ollama
Domínio
ai, backend

Direção de pesquisa

Start in src/eca/llm_providers/ollama.clj and read normalize-messages, comparing its message handling with the Anthropic adapter’s merge-adjacent-assistants. Check how request JSON keys are encoded and how assistant history items become Ollama chat messages. Done means prior tool calls are sent with the expected key and consecutive assistant content and tool calls are grouped as described; the issue names no test file, so locate the relevant provider tests.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

bug

To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.

Describe the bug

When using the Ollama API and long running agent tasks, the models (tested on qwen 3.5/3.8) emit unexpected stop tokens where a tool call is expected.

To Reproduce

Steps to reproduce the behavior:

  1. Use a model hosted by Ollama with the Ollama Api
  2. Start a long running task
  3. At some point the model outputs: Now I edit file X <stop_token>

Expected behavior

The model emits a tool call request instead of the stop token.

Cause and fix

The reason for the behavior is twofold. Both problems are in normalize-messages in src/eca/llm_providers/ollama.clj.

  1. Previous tool calls are silently dropped. The assistant tool-call messages are built with the key :tool-calls, and the body is encoded with a plain (json/generate-string body) (no key-fn), so the wire key is "tool-calls". Ollama's /api/chat expects tool_calls (API docs) and silently ignores unknown fields, so the request succeeds but the model never sees its earlier tool calls. (The response side already reads :tool_calls correctly.)

  2. One model response is sent as several assistant turns. Each history item becomes its own message: the reasoning (as plain content), the visible text, and the tool call. Ollama renders every assistant message as its own finished turn. The model's history therefore contains many turns of the form "I'll do X now", followed by an end-of-turn marker. That never happened during generation, where the call followed in the same turn. The model imitates the pattern and ends its turn right after announcing the action, so the stop token becomes likely. Each failure also adds another such example, which is why it gets worse in long sessions.

Fix

  • Use :tool_calls instead of :tool-calls.
  • Merge consecutive assistant messages into one (reasoning first, then text, joined by a blank line, with all tool calls concatenated). A tool message between two responses keeps them separate. The Anthropic adapter already does this with merge-adjacent-assistants.

Workaround until released

Pointing the provider at Ollama with "api": "anthropic" avoids the problem, because that adapter already merges messages and sends tool_use blocks (Ollama converts them to tool_calls).

Linguagem predominante
Clojure
Estrelas
1k
Forks
82
Merge médio
2d 2h
PRs com merge (30d)
21

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de editor-code-assistant/eca

Todas as issues de editor-code-assistant/eca

Issues semelhantes

Mais issues de Clojure

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.