Traditional

Last updated Apr 21, 2026 This page shows how you can do traditional function calling, as defined by industry standards. Workers AI also offers embedded function calling, which is drastically easier than traditional function calling.

With traditional function calling, you define an array of tools with the name, description, and tool arguments. The example below shows how you would pass a tool called getWeather in an inference request to a model.

Traditional function calling examplejs

const response = await env.AI.run("@hf/nousresearch/hermes-2-pro-mistral-7b", {
    messages: [
        {
            role: "user",
            content: "what is the weather in london?",
        },
    ],
    tools: [
        {
            name: "getWeather",
            description: "Return the weather for a latitude and longitude",
            parameters: {
                type: "object",
                properties: {
                    latitude: {
                        type: "string",
                        description: "The latitude for the given location",
                    },
                    longitude: {
                        type: "string",
                        description: "The longitude for the given location",
                    },
                },
                required: ["latitude", "longitude"],
            },
        },
    ],
});

return new Response(JSON.stringify(response.tool_calls));

The LLM will then return a JSON object with the required arguments and the name of the tool that was called. You can then pass this JSON object to make an API call.

[
    {
        "arguments": { "latitude": "51.5074", "longitude": "-0.1278" },
        "name": "getWeather"
    }
]

For a working example on how to do function calling, take a look at our demo app ↗︎.

Was this helpful?

YesNo

On this page

Traditional - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/workers-ai/features/function-calling/traditional/#page","headline":"Traditional","description":"Define tools and schemas for industry-standard function calling with Workers AI models.","url":"https://developers.cloudflare.com/workers-ai/features/function-calling/traditional/","inLanguage":"en","image":"https://developers.cloudflare.com/workers-ai/features/function-calling/traditional/og.png?v=a7f9d52f0e6e4365","dateModified":"2026-04-21","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"}}


description: Force Workers AI text generation models to return valid JSON output using response_format or JSON schemas. title: JSON Mode image: https://developers.cloudflare.com/workers-ai/features/json-mode/og.png?v=7526f0fdc7cd915d


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/workers-ai/llms.txt
Use this file to discover all available pages before exploring further.