Compaction fails with Bedrock: toolConfig not included when conversation has tool history #7360

Closed
opened 2026-02-16 18:06:57 -05:00 by yindo · 2 comments
Owner

Originally created by @mladencucakSYN on GitHub (Jan 23, 2026).

Originally assigned to: @thdxr on GitHub.

Description

When using OpenCode with AWS Bedrock (via custom provider or Portkey gateway), compaction fails with:

bedrock error: The toolConfig field must be defined when using toolUse and toolResult content blocks.

Root Cause

When OpenCode performs compaction, it sends the conversation history (which contains tool_calls and tool role messages) but does not include the tools array in the request.

AWS Bedrock's Converse API requires toolConfig to be present whenever the message history contains toolUse or toolResult content blocks.

Reproduction

  1. Configure OpenCode with a Bedrock-backed provider (direct or via Portkey/proxy)
  2. Have a conversation that uses tools (file edits, bash commands, etc.)
  3. Trigger compaction (manual or auto when context fills)
  4. Error occurs

Verified via direct API testing

Works (tools array included):

curl -X POST https://api-gateway/v1/chat/completions \
  -d '{
    "model": "us.anthropic.claude-*",
    "tools": [...],  # <-- Present
    "messages": [
      {"role": "assistant", "tool_calls": [...]},
      {"role": "tool", "content": "..."},
      ...
    ]
  }'

Fails (no tools array, but tool history in messages):

curl -X POST https://api-gateway/v1/chat/completions \
  -d '{
    "model": "us.anthropic.claude-*",
    # No "tools" array
    "messages": [
      {"role": "assistant", "tool_calls": [...]},
      {"role": "tool", "content": "..."},
      ...
    ]
  }'
# Error: toolConfig field must be defined

Suggested Fix

Either:

  1. Include tools in compaction requests when conversation history contains tool calls
  2. Strip tool call history from messages before compaction (convert to plain text summaries)
  3. Add empty tools array "tools": [] to satisfy Bedrock's requirement

Environment

  • OpenCode version: latest
  • Provider: Custom Bedrock via Portkey (@ai-sdk/openai-compatible)
  • Model: us.anthropic.claude-opus-4-5-20251101-v1:0
  • Config:
{
  "provider": {
    "portkey": {
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://portkey-gateway/v1"
      },
      "models": {
        "us.anthropic.claude-opus-4-5-20251101-v1:0": {
          "modalities": {"input": ["text", "image"], "output": ["text"]},
          "tool_call": true
        }
      }
    }
  }
}

Workaround

Disable auto-compaction and manually start new sessions:

{
  "compaction": {
    "auto": false,
    "prune": true
  }
}
Originally created by @mladencucakSYN on GitHub (Jan 23, 2026). Originally assigned to: @thdxr on GitHub. ## Description When using OpenCode with AWS Bedrock (via custom provider or Portkey gateway), compaction fails with: ``` bedrock error: The toolConfig field must be defined when using toolUse and toolResult content blocks. ``` ## Root Cause When OpenCode performs compaction, it sends the conversation history (which contains `tool_calls` and `tool` role messages) but **does not include the `tools` array** in the request. AWS Bedrock's Converse API requires `toolConfig` to be present whenever the message history contains `toolUse` or `toolResult` content blocks. ## Reproduction 1. Configure OpenCode with a Bedrock-backed provider (direct or via Portkey/proxy) 2. Have a conversation that uses tools (file edits, bash commands, etc.) 3. Trigger compaction (manual or auto when context fills) 4. Error occurs ## Verified via direct API testing **Works** (tools array included): ```bash curl -X POST https://api-gateway/v1/chat/completions \ -d '{ "model": "us.anthropic.claude-*", "tools": [...], # <-- Present "messages": [ {"role": "assistant", "tool_calls": [...]}, {"role": "tool", "content": "..."}, ... ] }' ``` **Fails** (no tools array, but tool history in messages): ```bash curl -X POST https://api-gateway/v1/chat/completions \ -d '{ "model": "us.anthropic.claude-*", # No "tools" array "messages": [ {"role": "assistant", "tool_calls": [...]}, {"role": "tool", "content": "..."}, ... ] }' # Error: toolConfig field must be defined ``` ## Suggested Fix Either: 1. **Include `tools` in compaction requests** when conversation history contains tool calls 2. **Strip tool call history** from messages before compaction (convert to plain text summaries) 3. **Add empty tools array** `"tools": []` to satisfy Bedrock's requirement ## Environment - OpenCode version: latest - Provider: Custom Bedrock via Portkey (`@ai-sdk/openai-compatible`) - Model: `us.anthropic.claude-opus-4-5-20251101-v1:0` - Config: ```json { "provider": { "portkey": { "npm": "@ai-sdk/openai-compatible", "options": { "baseURL": "https://portkey-gateway/v1" }, "models": { "us.anthropic.claude-opus-4-5-20251101-v1:0": { "modalities": {"input": ["text", "image"], "output": ["text"]}, "tool_call": true } } } } } ``` ## Workaround Disable auto-compaction and manually start new sessions: ```json { "compaction": { "auto": false, "prune": true } } ```
yindo closed this issue 2026-02-16 18:06:57 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Jan 23, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #8246: Anthropic via LiteLLM/proxies rejects requests with tool history but no tools param (similar root cause: tools parameter missing when message history contains tool calls)
  • #10037: LiteLLM proxy error with Anthropic when tools parameter is missing (ongoing issue with same pattern)

Both issues address the core problem of including the tools array when message history contains tool calls, which is exactly what Bedrock's toolConfig requirement mandates. Feel free to ignore if your specific Bedrock case differs from these.

@github-actions[bot] commented on GitHub (Jan 23, 2026): This issue might be a duplicate of existing issues. Please check: - #8246: Anthropic via LiteLLM/proxies rejects requests with tool history but no tools param (similar root cause: tools parameter missing when message history contains tool calls) - #10037: LiteLLM proxy error with Anthropic when tools parameter is missing (ongoing issue with same pattern) Both issues address the core problem of including the tools array when message history contains tool calls, which is exactly what Bedrock's toolConfig requirement mandates. Feel free to ignore if your specific Bedrock case differs from these.
Author
Owner

@mladencucakSYN commented on GitHub (Jan 23, 2026):

Closing as duplicate of #8246. The fix is already available via the litellmProxy: true provider option added in PR #8658. This works for Bedrock via Portkey as well.

@mladencucakSYN commented on GitHub (Jan 23, 2026): Closing as duplicate of #8246. The fix is already available via the `litellmProxy: true` provider option added in PR #8658. This works for Bedrock via Portkey as well.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#7360