Skip to content

Bring Anthropic usechat backend to OpenAI-level tool-use parity and stream robustness#2971

Draft
Copilot wants to merge 6 commits intomainfrom
copilot/update-anthropic-backend
Draft

Bring Anthropic usechat backend to OpenAI-level tool-use parity and stream robustness#2971
Copilot wants to merge 6 commits intomainfrom
copilot/update-anthropic-backend

Conversation

Copy link
Contributor

Copilot AI commented Mar 3, 2026

This updates pkg/aiusechat/anthropic from partial implementation to full backend parity for core tool-use orchestration and stream behavior. The main gaps were unimplemented tool lifecycle methods, missing persisted tool-use UI state, and weaker disconnect/error handling versus the OpenAI backend.

  • Tool-use lifecycle parity (critical path)

    • Implemented Anthropic backend support for:
      • UpdateToolUseData
      • RemoveToolUseCall
      • GetFunctionCallInputByToolCallId
    • Wired pkg/aiusechat/usechat-backend.go to call Anthropic implementations instead of stubs.
    • Added Anthropic run-step nil-message guard so nil responses are not wrapped into []GenAIMessage{nil}.
  • Persisted tool-use state in Anthropic native messages

    • Added internal ToolUseData storage on Anthropic tool_use blocks.
    • Ensured internal-only fields are stripped before API requests via Clean().
  • UI conversion parity for reloaded history

    • Extended ConvertToUIMessage() to emit data-tooluse parts when tool-use metadata exists, in addition to tool-{name} parts.
  • Streaming UX parity for tool argument deltas

    • Added aiutil.SendToolProgress(...) calls during:
      • input_json_delta (incremental updates)
      • content_block_stop for tool_use (final update)
  • Disconnect/stream robustness

    • Added sse.Err() checks in event handling and decode-error path.
    • Added partial-text extraction on client disconnect and deterministic ordering of partial blocks.
    • Cleans up completed blocks from in-flight state to avoid duplicate partial extraction.
  • Correctness + hygiene alignment

    • Continuation model checks now use AreModelsCompatible(...) (instead of strict string equality).
    • Added hostname sanitization in Anthropic error paths (HTTP error parsing and httpClient.Do failures).
    • Replaced unconditional Anthropic debug log.Printf calls with logutil.DevPrintf.
  • Targeted coverage additions

    • Added Anthropic tests for:
      • function-call lookup by tool call id
      • tool-use data update + removal
      • data-tooluse UI conversion behavior
// usechat-backend.go
func (b *anthropicBackend) RunChatStep(...) (..., []uctypes.GenAIMessage, ...) {
    stopReason, msg, rateLimitInfo, err := anthropic.RunAnthropicChatStep(ctx, sseHandler, chatOpts, cont)
    if msg == nil {
        return stopReason, nil, rateLimitInfo, err
    }
    return stopReason, []uctypes.GenAIMessage{msg}, rateLimitInfo, err
}

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits March 3, 2026 23:51
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
Co-authored-by: sawka <2722291+sawka@users.noreply.github.com>
Copilot AI changed the title [WIP] Update pkg/aiusechat/anthropic provider for full functionality Bring Anthropic usechat backend to OpenAI-level tool-use parity and stream robustness Mar 3, 2026
Copilot finished work on behalf of sawka March 3, 2026 23:59
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Mar 4, 2026

Deploying waveterm with  Cloudflare Pages  Cloudflare Pages

Latest commit: d629e4a
Status: ✅  Deploy successful!
Preview URL: https://bc2a2902.waveterm.pages.dev
Branch Preview URL: https://copilot-update-anthropic-bac.waveterm.pages.dev

View logs

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.

2 participants