ai-anthropic: truncated tool-call arguments are sent as a string tool_use.input, which breaks the conversation
I maintainer di solito rispondono entro 1 giorno
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
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
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di TanStack/ai
-
openai-base: a tool call cut off by finish_reason "length" is reported as "tool_calls" and re-sentForse già presa @tombeckenham l’ha presa oggi. Apertawaiting-on: maintainer
TanStack/ai#1853 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
ai-ollama: streamed chat() reports finishReason "stop" when done_reason is "length"Forse già presa @AlemTuzlak l’ha presa oggi. Apertawaiting-on: maintainer
TanStack/ai#1852 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
ai-vercel-gateway: surface provider_metadata.gateway cost on usage (usage.cost)Forse già presa @tombeckenham l’ha presa 1 giorno fa. Apertawaiting-on: maintainer
TanStack/ai#1845 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
withPersistence does not save activity rows when a run is stopped or failsForse già presa @tombeckenham l’ha presa 6 giorni fa. Apertawaiting-on: maintainer
TanStack/ai#1804 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Discriminate status-dependent record and option types (RunRecord, SessionIndexEntry, InputState, durable-only options)Forse già presa @jherr l’ha presa 6 giorni fa. Apertaenhancement waiting-on: maintainer
TanStack/ai#1799 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Issue simili
-
数据界面的横向滚动条缺失Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
zilliztech/attu#1037 ·
-
clawsweeper:fix-shape-clear clawsweeper:queueable-fix clawsweeper:source-repro impact:ux-friction issue-rating: 🦞 diamond lobster no-stale P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
openclaw/openclaw#181212 · 1 commento · 1 reazione ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
apify/apify-mcp-server#1684 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
Automattic/data-liberation-agent#953 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
siteboon/claudecodeui#1642 ·
I maintainer di solito rispondono entro 5 giorni