[PR #14970] Add command-r tool call parser for Cohere models #25486

Open
opened 2026-04-19 18:14:40 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ollama/ollama/pull/14970
Author: @kvncrw
Created: 3/20/2026
Status: 🔄 Open

Base: mainHead: fix/command-r-tool-call-parser


📝 Commits (1)

  • 04e1b08 Add command-r tool call parser for Cohere models

📊 Changes

4 files changed (+495 additions, -0 deletions)

View changed files

model/parsers/commandr.go (+266 -0)
model/parsers/commandr_test.go (+214 -0)
📝 model/parsers/parsers.go (+2 -0)
📝 server/routes.go (+13 -0)

📄 Description

Summary

  • Command-R models output tool calls in Cohere's format: Action: ```json [{"tool_name": "...", "parameters": {...}}]``` but the generic tool parser searches for literal function names in the output buffer. Since command-r wraps tool names in JSON ("tool_name": "bash"), the parser never finds a match and silently returns empty content.
  • This adds a dedicated CommandRParser that correctly handles Cohere's tool call format, and auto-assigns it to models with command-r model family.

Problem

When calling command-r via /v1/chat/completions with tools, the response comes back with "content": "" and no tool_calls field. The model generates ~31 tokens (the tool call output), but the generic parser in tools/tools.go:findTool() can't match tool names embedded in JSON strings. The output is silently discarded.

This affects all command-r variants accessed through the OpenAI-compatible API, breaking integration with tools like OpenCode, Continue, and other AI coding assistants.

Changes

  • model/parsers/commandr.go: New parser that handles Cohere's Action: + JSON code block format, parses {"tool_name", "parameters"} objects, filters directly-answer pseudo-tool, supports streaming
  • model/parsers/commandr_test.go: 10 tests covering single/multiple tool calls, streaming, partial tags, directly-answer filtering, plain text passthrough
  • model/parsers/parsers.go: Register "command-r" parser name
  • server/routes.go: Auto-detect command-r models by model family and assign parser (same pattern as shouldUseHarmony)

Test plan

  • All 10 new parser tests pass
  • All existing parser tests still pass
  • Server package compiles cleanly
  • Manual test: curl /v1/chat/completions with command-r and tools returns populated tool_calls
  • Manual test: command-r without tools still returns normal text content

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ollama/ollama/pull/14970 **Author:** [@kvncrw](https://github.com/kvncrw) **Created:** 3/20/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/command-r-tool-call-parser` --- ### 📝 Commits (1) - [`04e1b08`](https://github.com/ollama/ollama/commit/04e1b08d5b046f54d94f9a744017c5c39d008b30) Add command-r tool call parser for Cohere models ### 📊 Changes **4 files changed** (+495 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `model/parsers/commandr.go` (+266 -0) ➕ `model/parsers/commandr_test.go` (+214 -0) 📝 `model/parsers/parsers.go` (+2 -0) 📝 `server/routes.go` (+13 -0) </details> ### 📄 Description ## Summary - Command-R models output tool calls in Cohere's format: `Action: ```json [{"tool_name": "...", "parameters": {...}}]``` ` but the generic tool parser searches for literal function names in the output buffer. Since command-r wraps tool names in JSON (`"tool_name": "bash"`), the parser never finds a match and silently returns empty content. - This adds a dedicated `CommandRParser` that correctly handles Cohere's tool call format, and auto-assigns it to models with `command-r` model family. ## Problem When calling command-r via `/v1/chat/completions` with tools, the response comes back with `"content": ""` and no `tool_calls` field. The model generates ~31 tokens (the tool call output), but the generic parser in `tools/tools.go:findTool()` can't match tool names embedded in JSON strings. The output is silently discarded. This affects all command-r variants accessed through the OpenAI-compatible API, breaking integration with tools like OpenCode, Continue, and other AI coding assistants. ## Changes - **`model/parsers/commandr.go`**: New parser that handles Cohere's `Action:` + JSON code block format, parses `{"tool_name", "parameters"}` objects, filters `directly-answer` pseudo-tool, supports streaming - **`model/parsers/commandr_test.go`**: 10 tests covering single/multiple tool calls, streaming, partial tags, directly-answer filtering, plain text passthrough - **`model/parsers/parsers.go`**: Register `"command-r"` parser name - **`server/routes.go`**: Auto-detect command-r models by model family and assign parser (same pattern as `shouldUseHarmony`) ## Test plan - [x] All 10 new parser tests pass - [x] All existing parser tests still pass - [x] Server package compiles cleanly - [ ] Manual test: `curl /v1/chat/completions` with command-r and tools returns populated `tool_calls` - [ ] Manual test: command-r without tools still returns normal text content --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-19 18:14:40 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#25486