aifree.dev

Làm sao nó gọi được một hàm mà nó không tự chạy được?

Tool calling (gọi hàm, function calling) · Thực hành · 5 phút · agents, format · học sau Structured output (giải mã có ràng buộc)

Tool calling cho phép model nhờ code của bạn chạy một hàm. Bạn gửi tên, mô tả và JSON schema của từng tool; model trả lời bằng một tên hàm và tham số JSON, code của bạn chạy hàm đó rồi gửi kết quả lại.

Trước khi bắt đầu: bạn giải thích được chuyện này cho bạn bè không?

1 = hoàn toàn không · 5 = dễ dàng

  1. 1 Đoán trước

    Bạn hỏi một ứng dụng xây trên Claude: “What’s the weather in San Francisco?” Nó trả lời bằng thời tiết hôm nay. Model đã gửi lại cái gì đầu tiên?
  2. 2 Xem

    One tool call, four messages

    1 / 4
    1. your app sends · request 1: question + tools

      user: “What’s the weather in San Francisco?”

      tools: [{
        "name": "get_weather",
        "description": "Get the current weather for a given location.",
        "input_schema": {
          "type": "object",
          "properties": {
            "location": {
              "type": "string",
              "description": "City and state, e.g. San Francisco, CA"
            }
          },
          "required": ["location"]
        }
      }]

    Sent on every request, called or not. Claude Haiku 5.5 also adds a hidden 286-token tool prompt.

    requests and replies quoted from Anthropic’s tool-use docs (claude-opus-5-5 example) · checked 2026-10-23

    Your app sends the question and a menu of tools: a name, a description and a JSON schema each.

    Model chỉ viết: trước tiên là một lệnh gọi để code của bạn chạy, rồi, khi kết quả được dán lại, mới đến câu trả lời.

  3. Model vẫn chỉ viết chữ. Khi request liệt kê các tool (hàm được mô tả bằng tên, mô tả và JSON schema), nó có thể viết một lệnh gọi theo khuôn cố định thay cho câu trả lời. API trả lệnh đó về thành một khối riêng và dừng, với stop_reason "tool_use". Có chạy hay không là do code của bạn.

  4. 4 Bạn là model

    Bạn là model, có một tool: get_weather. Trong năm lượt, hãy chọn viết gì: một câu trả lời, một câu hỏi lại, hay một lệnh gọi tool.

    you are the model · your one tool: get_weather (location: string, required) · what do you write next?

    turn 1 of 5 · the user writes

    “What’s the weather in San Francisco?”

    requests and replies quoted from Anthropic’s tool-use docs (claude-opus-5-5 example) · checked 2026-10-23

    You are the model. Answer, ask, or write a tool call?
  5. 5 Kiểm tra

    Thời tiết đến được model bằng cách nào?
  6. Chỗ hay hỏng. Tham số sai: thiếu thành phố, sai kiểu. Kiểm tra trước khi chạy, hoặc đặt strict: true (Anthropic, OpenAI) hay chế độ validated của Gemini; gửi lỗi lại với is_error, và Claude thử lại 2–3 lần. Gọi thừa: mô tả mơ hồ, quá nhiều tool; Gemini khuyên tối đa 10–20. Nhiều lệnh gọi nối thành vòng lặp tạo ra một agent.

  7. 7 Nói lại bằng lời bạn

  8. 8 Nhiệm vụ · 5 phút

    Với một API key Gemini miễn phí, làm theo tài liệu function calling của Gemini: khai báo get_weather (location: string, bắt buộc) và hỏi gemini-3.8-flash “What’s the weather in Hanoi?”. Bạn nhận về một functionCall có name và args, không phải câu trả lời. Gửi lại một functionResponse bạn tự bịa, {"temp_c": 31}, rồi đọc câu trả lời. Sau đó hỏi “What is a cold front?”: nó có gọi tool không?

Ba câu nhanh

Rút ngẫu nhiên từ bộ câu hỏi của bài; lần sau sẽ khác.

Xong chưa?

Còn bây giờ: bạn giải thích được cho bạn bè chưa?

1 = hoàn toàn không · 5 = dễ dàng

Trả lời ba câu nhanh trước đã.

Nhận email khi có bài mới

Bài mới nằm trong bản tin hằng tuần, chỉ gửi vào tuần có bài. Bạn xác nhận qua email trước; hủy đăng ký chỉ với một lần bấm.

Nguồn

  • https://platform.claude.com/docs/en/agents-and-tools/tool-use/overview (checked 2026-10-23; no update date): the get_weather round trip on claude-opus-5-5 (tool with input_schema, location required; output “Claude called get_weather with {"location": "San Francisco, CA"}”; result “15 degrees Celsius, partly cloudy”; answer “The current weather in San Francisco is 15 degrees Celsius with partly cloudy skies.”); client tools stop with stop_reason "tool_use"; with tool_choice auto Claude “responds directly for stable knowledge”; with no location, Claude Opus “is much more likely to recognize that a parameter is missing and ask for it”, Claude Sonnet might guess {"location": "New York, NY", "unit": "fahrenheit"}; strict: true guarantees schema conformance; tool use system prompt tokens: Claude Haiku 5.5 286 (auto, none), 406 (any, tool); the tools parameter counts as input tokens
  • https://platform.claude.com/docs/en/agents-and-tools/tool-use/handle-tool-calls (checked 2026-10-23): example id toolu_01A09q90qw90lq917835lq9; tool_result with tool_use_id and is_error; tool_result blocks must immediately follow the tool_use; error “ConnectionError: the weather service API is not available (HTTP 500)” and Claude’s reply “I’m sorry, I was unable to retrieve the current weather because the weather service API is not available. Please try again later.”; “Claude will retry 2–3 times with corrections before apologizing”; server tools such as web_search run on Anthropic’s infrastructure
  • https://ai.google.dev/gemini-api/docs/function-calling (updated 2026-09-23, checked 2026-10-23): “The model doesn’t execute the function itself”; modes auto, any, none, validated (“Model ensures function schema adherence”); “Keep active set to 10-20 tools maximum”; examples on gemini-3.8-flash
  • https://developers.openai.com/api/docs/guides/function-calling (checked 2026-10-23): five steps from a request with tools to a final response “(or more tool calls)”; “Setting strict to true will ensure function calls reliably adhere to the function schema”
  • https://ai.google.dev/gemini-api/docs/pricing (updated 2026-10-22, checked 2026-10-23): Gemini 3.8 Flash free tier, input and output “Free of charge”; aifree.dev catalog google-gemini-developer-api-free-tier (verified 2026-10-12)

Đăng Oct 23, 2026 · cập nhật Oct 23, 2026

Never miss new offers and news

New tools, credits, and AI news are added regularly. Pick how you want to hear about them.

Telegram channel
Join @aifree_dev and get new free AI offers and news right in your Telegram feed.
Browser notifications
Turn on push notifications and get an alert on this device whenever something new is posted. No account needed.
Email newsletter
A weekly digest of new, changed and expiring free AI offers. Double opt-in, one-click unsubscribe. See the latest issue.

Unsubscribe anytime. Privacy

Frequently asked questions

What is aifree.dev?

aifree.dev helps everyone access AI through a curated directory of free AI tools, API credits, free tiers, and startup programs for coding, image, voice, video, and students - verified regularly.

How are offers presented?

Each offer includes its access details, free models when available, and expiration information when provided. Limited-time deals stay visible so they are easy to compare.

Do education and startup programs need verification?

Yes. Providers usually ask students to verify their status with a school email, student ID, or a program like the GitHub Student Pack, and ask startups to verify company details such as age, funding, or website. Check each offer’s claim page for the exact requirements.

What kinds of free AI offers are listed?

Free tiers and free trials from AI providers, free API credits, startup and student programs, and free tools for coding, image generation, voice, and video.

How can I suggest a tool or report a broken link?

Use the submit form: paste the offer page URL and a short note. A person checks every submission before anything is listed. Broken links and changed terms go through the same form.

+

Know a good one?

Tell us about an AI tool worth knowing. Found a broken link? We want to hear that too.

Submit an offer