Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đã đóng Phù hợp với người mới
#324 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Một pull request liên quan đã được merge.

  • #325 của @gtokman — đã merge

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
82/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
swift
Lĩnh vực
api

Hướng nghiên cứu

Lỗi nằm ở nhánh .toolCalls của chuyển đổi transcript trong Sources/AnyLanguageModel/Models/OpenAILanguageModel.swift, nơi JSONEncoder().encode(call.arguments) ghi dạng Codable của GeneratedContent. Hãy kiểm tra biến thể .responses, vốn đọc cùng một message, và so sánh với OpenResponsesLanguageModel, nơi dùng call.arguments.jsonString. Hoàn thành khi các arguments của tool_calls được phát lại là JSON thuần như {"query":...} trong messages của yêu cầu thứ hai.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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).

Ngôn ngữ chính
Swift
Star
959
Fork
99
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
57

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của huggingface/AnyLanguageModel

Tất cả issue của huggingface/AnyLanguageModel

Issue tương tự

Thêm issue về Swift

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.