Skip to content

fix: use JSON skill serialization by default for non-Anthropic models#24852

Open
andrewgwoodruff wants to merge 2 commits intoanomalyco:devfrom
andrewgwoodruff:fix/skill-serialization-format-for-local-models
Open

fix: use JSON skill serialization by default for non-Anthropic models#24852
andrewgwoodruff wants to merge 2 commits intoanomalyco:devfrom
andrewgwoodruff:fix/skill-serialization-format-for-local-models

Conversation

@andrewgwoodruff
Copy link
Copy Markdown

@andrewgwoodruff andrewgwoodruff commented Apr 28, 2026

Issue for this PR

Closes #24824

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When a project has skills loaded, OpenCode serializes them into the system prompt as XML (<available_skills>, <skill>, etc.). This is fine for Claude, which is trained to parse XML-structured prompts, but non-Anthropic models — especially local models via Ollama — interpret the dense XML as a signal to respond in XML format. That breaks JSON tool calls.

I ran 50 tests each against devstral:24b with the same prompt and tools, varying only the skills serialization format:

Format Pass rate
XML (current) 68%
Markdown 74%
JSON 86%

JSON and XML are nearly the same size, so it's the format itself that matters. The fix defaults to JSON for non-Anthropic models and leaves XML in place for Anthropic/Claude. There's also a skills.format config option for anyone who wants to override it explicitly.

How did you verify your code works?

Validated the format hypothesis by running 50 direct Ollama API calls per format against devstral:24b using manually constructed system prompts matching what OpenCode produces. Results are in the table above.

Also ran the project test suite locally (bun test test/session/system.test.ts) — updated the existing system prompt test to pass the required model argument, and added a second test verifying JSON output for non-Anthropic models. Both pass. Full typecheck clean (pre-existing failures in config.test.ts unrelated to this change).

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

The skills system prompt block was always serialized as XML
(`<available_skills>`), a Claude-specific convention. Non-Anthropic
models (Ollama, etc.) interpret dense XML in the system prompt as a
signal to respond in XML format, breaking JSON tool calls.

Controlled testing across 50 runs each showed:
- XML:      68% tool-call success
- Markdown: 74% tool-call success
- JSON:     86% tool-call success

Changes:
- `skill/index.ts`: replace `verbose: boolean` with `format: "xml" | "json" | "markdown"` in `fmt()`; add JSON serialization path
- `session/system.ts`: pass model to `skills()`; default to JSON for non-Anthropic models, XML for Anthropic; read `skills.format` config override
- `config/skills.ts`: add optional `format` field so users can override per-project
- `tool/registry.ts`: update call site to use explicit `format: "markdown"` (tool description path, unchanged behavior)

Fixes anomalyco#24824
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Apr 28, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

- Fix Schema.Union call in config/skills.ts to use array syntax
- Update system.test.ts to pass model argument to skills() and add
  a second test covering JSON output for non-Anthropic models
Bojun-Vvibe added a commit to Bojun-Vvibe/oss-contributions that referenced this pull request Apr 29, 2026
- anomalyco/opencode#24877: session directory routing fix (merge-after-nits)
- anomalyco/opencode#24852: JSON skill serialization for non-Anthropic models (merge-after-nits)
- openai/codex#20113: heredoc file_redirect sandbox bypass fix (merge-after-nits)
- openai/codex#20096: remote installed plugin cache for skills/MCP (merge-after-nits)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Large XML-heavy system prompt breaks tool calling across multiple Ollama models (Qwen3, Qwen2.5, Devstral)

1 participant