Commit 5f2f7ca
committed
fix(agents): stop DatabricksAdapter duplicating answer text across tool calls (#421)
Claude on Databricks Model Serving emits a full draft answer ALONGSIDE its tool
calls in the same turn, because the OpenAI-compatible layer lacks Claude's
native tool-use prompt. DatabricksAdapter yielded every `delta.content` as a
`message_delta` the instant it arrived, so in a ReAct loop the draft surfaced on
every tool-calling step — the same answer appearing 3-4x, and (because
consumeAdapterStream appends message_delta content) duplicated in the aggregated
output too.
Surface assistant text only on the terminal turn:
- streamCompletion streams text live only when no tools are offered (such a turn
is always terminal). When tools are present it buffers the text into fullText
instead of yielding it.
- run() emits the buffered text as a single message_delta on the terminal turn
(no structured or text-encoded tool calls). Tool-calling turns keep their text
in message history for model context but never surface it to the user.
Tradeoff: with tools enabled, the final answer arrives as one delta rather than
streaming token-by-token — there's no way to know a turn is terminal until its
stream ends without tool calls. Pure-chat (no tools) still streams live.
Tests: 2 new cases (text+tool-call in one turn; no duplication across multiple
steps). Full appkit suite (2141) passes.
Signed-off-by: MarioCadenas <MarioCadenas@users.noreply.github.com>1 parent 494edcc commit 5f2f7ca
2 files changed
Lines changed: 128 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
416 | 425 | | |
417 | 426 | | |
418 | 427 | | |
| |||
486 | 495 | | |
487 | 496 | | |
488 | 497 | | |
| 498 | + | |
489 | 499 | | |
490 | 500 | | |
491 | 501 | | |
492 | 502 | | |
493 | 503 | | |
494 | 504 | | |
495 | | - | |
| 505 | + | |
496 | 506 | | |
497 | 507 | | |
498 | 508 | | |
| |||
573 | 583 | | |
574 | 584 | | |
575 | 585 | | |
576 | | - | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
577 | 598 | | |
578 | 599 | | |
579 | 600 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
252 | 252 | | |
253 | 253 | | |
254 | 254 | | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
255 | 360 | | |
256 | 361 | | |
257 | 362 | | |
| |||
0 commit comments