DatabricksAdapter yields text content during tool-calling rounds, causing response duplication

Offen
#421 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 3 Tagen

Dieses Issue hat noch niemand übernommen.

  • #436 von @MarioCadenas — ohne Merge geschlossen

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
55/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Ruhig
Tech-Stack
typescript
Bereich
ai, api, backend

Rechercherichtung

Beginne mit DatabricksAdapter's streamCompletion() und der run()-Methode um Zeile 196, und reproduziere dann das Problem mit maxSteps: 10 und mehreren Tools wie describeTable und executeSql. Verfolge message_delta- und Tool-Call-Ereignisse über einen Tool-Calling-Durchlauf hinweg. Fertig bedeutet, dass Zwischentext keine doppelten für den Benutzer sichtbaren Antworten erzeugt, während die endgültige Antwort weiterhin genau einmal erscheint.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

DatabricksAdapter yields text content during tool-calling rounds, causing response duplication

Problem

When using DatabricksAdapter with Claude models via Databricks Model Serving (OpenAI-compatible endpoint), the model produces substantial text content alongside tool calls in the same response turn. The adapter's streamCompletion() method yields all delta.content text as message_delta events regardless of whether the same response also contains tool calls.

In a multi-step ReAct loop, this causes the model's intermediate text (which often includes the full answer) to be emitted and displayed to the user on every tool-calling turn — resulting in the same answer appearing 3-4× in the final output.

Root Cause Analysis

Claude's native API uses a trained-in tool-use system prompt that shapes the model to produce brief commentary before tool_use blocks. The Databricks OpenAI-compatible translation layer does not include this trained-in prompt, so Claude produces more verbose text during tool-calling rounds.

The adapter loop (run() method, line ~196) correctly breaks when no tool calls are present, but during tool-calling rounds, streamCompletion() yields ALL delta.content as message_delta events — there's no mechanism to suppress or buffer text that arrives in a turn that also contains tool calls.

Expected Behavior

Text content from tool-calling rounds should either:

  1. Be suppressed (not yielded as message_delta) when the same response also contains tool_calls
  2. Be buffered until streamCompletion returns, and only yielded if no tool calls were detected
  3. Be marked with metadata so consumers can distinguish intermediate text from final-answer text
Current Workaround

We added:

  • A system prompt instruction telling the model to only write brief status notes during tool-calling turns
  • Client-side text buffering in the SSE transport layer that discards accumulated text when a function_call event arrives in the same round
Environment
  • AppKit version: 0.38.1
  • Model: databricks-claude-opus-4-6 via Model Serving
  • Adapter: DatabricksAdapter.fromServingEndpoint()
Reproduction
  1. Create an agent with maxSteps: 10 and multiple tools (e.g., describeTable, executeSql)
  2. Ask a question that triggers 3+ tool calls
  3. Observe that the assistant's text response contains the full answer repeated once per tool-calling round
Vorherrschende Sprache
TypeScript
Sterne
119
Forks
36
Ø Merge
4 T. 16 Std.
Gemergte PRs (30 T.)
37

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus databricks/appkit

Alle Issues in databricks/appkit

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.