Skip to content

feat(adapters): add cohere-chat adapter for Cohere Chat API v2 - #6

Merged
felmonon merged 1 commit into
mainfrom
feat/cohere-chat-adapter
Jul 14, 2026
Merged

feat(adapters): add cohere-chat adapter for Cohere Chat API v2#6
felmonon merged 1 commit into
mainfrom
feat/cohere-chat-adapter

Conversation

@felmonon

Copy link
Copy Markdown
Owner

What

Adds a third provider adapter: cohere-chat, importing Cohere Chat API v2 conversation transcripts into the canonical trace format, with auto-detection.

Design notes

  • Detection ordering matters: Cohere v2 deliberately shares the tool_calls / role: "tool" wire shape with OpenAI. Detection therefore scans the full message list for Cohere-only markers first — tool_plan on assistant messages, assistant message-level citations, and document typed tool-result blocks — before falling through to the per-message OpenAI/Anthropic rules. Covered by dedicated tests, including an ambiguous transcript that carries tool_calls but no tool_plan.
  • tool_plan is agent behavior: it maps to a model_response step (marked metadata.source_field: "tool_plan") so plan text stays visible to safety scanning without being mistaken for the final answer.
  • Document-block flattening: tool results arrive as {type: document, document: {data}} block lists; valid data payloads are joined in order, and malformed blocks are recorded under metadata.adapter.notes (never silently dropped) while still recovering the valid payloads around them.
  • Cannot-carry fields stay honest: latency/cost/tokens/status are left unset so dependent checks go not applicable rather than silently passing — same contract as the existing adapters.

Testing

  • 11 new tests: detection (3 incl. the shared-wire-shape trap), full refund-transcript mapping, tool_plan marking, citation mapping, edge-case note recording, round-trip validation, and a cross-provider verdict-equivalence test (same conversation via OpenAI and Cohere transcripts yields identical rule verdicts under the same policy).
  • Full suite: 205 tests green on 3.11/3.13 locally; ruff and mypy --strict clean; benchmark suite thresholds all met.

Version

Bumps to 0.2.2 (new feature, backward compatible). Changelog updated.

…ripts

- Import Cohere v2 message lists: tool_plan/tool_calls assistant messages,
  document-block tool results, message-level citations
- Auto-detection scans Cohere-only markers (tool_plan, assistant-level
  citations, document blocks) before OpenAI rules, since Cohere shares the
  tool_calls wire shape with OpenAI
- tool_plan maps to a model_response step marked metadata.source_field so
  plan text stays visible to safety checks
- 11 new tests incl. cross-provider verdict-equivalence; docs + changelog
- Version 0.2.2
@felmonon
felmonon merged commit d38b7ca into main Jul 14, 2026
8 checks passed
@felmonon
felmonon deleted the feat/cohere-chat-adapter branch July 14, 2026 19:15
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.

1 participant