Skip to content

Tool Calls Section End Token (<|tool_calls_section_end|>) Parsing Failures #1021

@mcotdev

Description

@mcotdev

OpenCode.ai's parsing system appears to rely on the <|tool_calls_section_end|> token to properly delimit tool calling sections, but this token is frequently missing, malformed, or incorrectly handled by various AI models, leading to parsing failures and broken tool execution.

Environment

  • Provider: OpenRouter
  • Model: moonshotai/kimi-k2
  • OS: Linux

Issue Description

The <|tool_calls_section_end|> token appears to be critical for OpenCode.ai's response parsing, but many models fail to generate it consistently, causing:

  • Incomplete tool execution
  • Parsing errors
  • System hanging/time out issues
  • Malformed responses

Steps to Reproduce

  1. Configure OpenCode with Kimi K2 through OpenRouter:
    {
      "model": "moonshotai/kimi-k2",
      "provider": "openrouter"
    }
  2. Request a task that requires tool calls (e.g., "Create a file named test.py")
  3. Observe the raw response output (if possible)
  4. Note missing or malformed <|tool_calls_section_end|> token

Expected Behaviour

  • All models should consistently generate the required section end token
  • Parser should handle missing tokens gracefully
  • Tool execution should work regardless of minor token variations

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions