[6.x]: AI tool-calling check fails with a 400 on Anthropic, so Ask AI can't use Claude models

Đã đóng Phù hợp với người mới
#20,266 1 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

@riasvdv đang làm issue này rồi.

Từ ngày 3/11/2026.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
78/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ệ
php
Lĩnh vực
backend

Hướng nghiên cứu

Kiểm tra đang lỗi là công cụ ẩn danh trong src/Ai/Agents/ToolCallingProbe.php, khoảng dòng 34, không có phương thức name(), nên laravel/ai quay về dùng class_basename mà Anthropic từ chối. Hãy bắt đầu bằng việc đọc tệp đó và so sánh với các công cụ trợ lý Craft khác có định nghĩa name(). Công việc hoàn thành khi probe khai báo một name() như get_verification_code và kiểm tra gọi công cụ đạt với claude-sonnet-5-5.

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

Mô tả

bug repo:cms
What happened?
Steps to reproduce
  1. Add an Anthropic provider to config/ai.php (the stock laravel/ai config has one) and set ANTHROPIC_API_KEY.
  2. In Settings → Extend → Connections, set the default text provider to anthropic and the model to claude-sonnet-5-5.
  3. Save.
Expected behavior

Craft confirms the model supports tool calling, and the AI assistant task becomes available.

Actual behavior

The check fails, and the AI assistant task is reported as unavailable:

Craft couldn’t check whether the claude-sonnet-5-5 model on the anthropic provider supports tool calling, which AI assistant needs: HTTP request returned status code 400: {"type":"error","error":{"type":"invalid_request_error","message":"tools.0.custom.name: String should match pattern '^[a (truncated...)

Cause

The test tool in src/Ai/Agents/ToolCallingProbe.php:34 is an anonymous class without a name() method. laravel/ai's ToolNameResolver falls back to class_basename(), which for an anonymous class gives a name like ToolCallingProbe.php:34$398. Anthropic rejects the ., : and $. Craft's other assistant tools all define name(), so only this check is affected.

Suggested fix
  • Add a name() method to the anonymous tool, e.g. returning get_verification_code.
Notes

With that method added locally, the tool name resolves to get_verification_code and the check passes with claude-sonnet-5-5. config/ai.php is the stock laravel/ai config, so the config isn't involved.

Craft CMS version

6.x-dev (395aae2)

PHP version

No response

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions
Ngôn ngữ chính
PHP
Star
3.6k
Fork
712
Merge trung bình
12 giờ 44 phút
Pull request đã merge (30 ngày)
381

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

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 craftcms/cms

Tất cả issue của craftcms/cms

Issue tương tự

Thêm issue về PHP

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.