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

OpenAILanguageModel replays tool-call arguments as GeneratedContent's Codable form, not JSON

Aperta Adatta ai principianti
#324 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@gtokman ci sta già lavorando.

Dal 13/10/2026.

  • #325 di @gtokman — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
swift
Ambito
api

Direzione di ricerca

Il bug si trova nel caso .toolCalls della conversione del transcript in Sources/AnyLanguageModel/Models/OpenAILanguageModel.swift, dove JSONEncoder().encode(call.arguments) scrive la forma Codable di GeneratedContent. Controlla la variante .responses, che legge lo stesso messaggio, e confronta con OpenResponsesLanguageModel, che usa call.arguments.jsonString. È completato quando gli argomenti di tool_calls riprodotti sono JSON semplice come {"query":...} nei messages della seconda richiesta.

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

Descrizione

Summary

OpenAILanguageModel replays earlier tool calls with their arguments encoded by GeneratedContent's Codable conformance instead of as plain JSON. On the next turn the model sees arguments like:

{"kind":{"type":"structure","properties":{"query":{"kind":{"type":"string","value":"Apple stock 2026"}}},"orderedKeys":["query"]}}

instead of {"query":"Apple stock 2026"}. Models then copy that shape in their own new tool calls, the arguments don't match the tool's schema, and decoding them throws LanguageModelSession.ToolCallError, which ends the response.

Where

Sources/AnyLanguageModel/Models/OpenAILanguageModel.swift, in the .toolCalls case of the transcript conversion (line 1369 at 0.16.0, line 1374 on main / 1.0.0):

if let data = try? JSONEncoder().encode(call.arguments),
    let jsonString = String(data: data, encoding: .utf8)

GeneratedContent.encode(to:) writes id and kind, so this isn't the arguments' JSON. The .responses variant converts from the same message, so it's affected too. OpenResponsesLanguageModel already does it correctly with call.arguments.jsonString.

Suggested fix

let argumentsJSON = call.arguments.jsonString

Reproduce

  1. LanguageModelSession with OpenAILanguageModel (Chat Completions) and any tool.
  2. Ask something that makes the model call the tool, then ask a follow-up in the same session.
  3. Inspect the second request's messages: the assistant tool_calls[].function.arguments hold the {"kind":…} encoding.

Impact we measured

Benchmarking 4 models over 11 multi-turn conversations through the Vercel AI Gateway (Chat Completions): Gemini 4 Argon and Claude Haiku 5.5 each produced follow-up tool calls in the {"kind":…} shape (decoded as empty arguments, or failing to decode), which ended the reply. Claude Sonnet 5.5 happened to ignore it.

Seen on 0.16.0; the line is unchanged on main (1.0.0).

Lingua principale
Swift
Stelle
944
Fork
95
Merge medio
18h 38m
PR unite (30g)
56

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 huggingface/AnyLanguageModel

Tutte le issue di huggingface/AnyLanguageModel

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.