Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

ai-anthropic: truncated tool-call arguments are sent as a string tool_use.input, which breaks the conversation

Chiusa Adatta ai principianti
#1,582 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@tombeckenham ci sta già lavorando.

Dal 1/10/2026.

  • #1583 di @Tetnofa — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
api

Direzione di ricerca

Inizia in packages/ai-anthropic/src/adapters/text.ts, in AnthropicTextAdapter.formatMessages, e verifica come gli argomenti malformati delle chiamate agli strumenti diventano tool_use.input. Usa la riproduzione fornita per confrontare gli argomenti troncati, validi, vuoti e non-oggetto. Il lavoro è completato quando Anthropic riceve sempre un oggetto per tool_use.input e i test pertinenti dell’adapter coprono la regressione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

has-pr waiting-on: maintainer

Hi! We hit a case where one interrupted tool call permanently breaks a chat thread on the Anthropic adapter.

Versions: @tanstack/ai 0.58.0, @tanstack/ai-anthropic 0.18.11 (also present on main at packages/ai-anthropic/src/adapters/text.ts)

What happens

When a stream ends while a tool call's arguments are still streaming (the user stops generation, the connection drops, or the model hits max tokens), the stream processor marks that tool call input-complete and keeps the partial arguments string (stream/processor.js, completeToolCall). Because the state is input-complete, the tool call is included when the history is converted back into model messages (messages.js, isToolCallIncluded).

On the next request, AnthropicTextAdapter.formatMessages tries to JSON.parse those arguments, fails, and falls back to the raw string:

let parsedInput: unknown = {}
try {
  const parsed = toolCall.function.arguments
    ? JSON.parse(toolCall.function.arguments)
    : {}
  parsedInput = parsed && typeof parsed === 'object' ? parsed : {}
} catch {
  parsedInput = toolCall.function.arguments // string
}

Anthropic rejects the request with 400 messages.N.content.M.tool_use.input: Input should be an object. Since the bad message stays in history, every later turn in that conversation fails the same way.

Repro
import { AnthropicTextAdapter } from '@tanstack/ai-anthropic'

const adapter = new AnthropicTextAdapter({ apiKey: 'x' }, 'claude-sonnet-4-5')
const out = adapter.formatMessages([
  { role: 'user', content: 'hi' },
  {
    role: 'assistant',
    content: '',
    toolCalls: [{ id: 'toolu_1', type: 'function', function: { name: 'get_agent', arguments: '{"agentId": "abc' } }],
  },
  { role: 'tool', toolCallId: 'toolu_1', content: 'ok' },
])
// tool_use.input === '{"agentId": "abc'   (string)

For comparison, valid JSON, an empty string and a non-object JSON value ("hello") all produce an object.

Expected

tool_use.input should always be an object. The catch branch could fall back to {}, the same as the non-object branch just above it. Alternatively, tool calls whose arguments never finished parsing could be excluded from history, or marked error instead of input-complete, when a stream is finalized.

Related: #265 / #266 fixed the null input case in the same area.

Happy to open a PR for the {} fallback if that's the preferred fix.

Lingua principale
TypeScript
Stelle
3.2k
Fork
365
Merge medio
1g 9h
PR unite (30g)
263

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di TanStack/ai

Tutte le issue di TanStack/ai

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.