Embedded function calling arrives on Workers AI
Cloudflare has released embedded function calling for Workers AI, a new approach that runs LLM inference and function execution in the same Workers runtime. Alongside it, the company is shipping an open-source @cloudflare/ai-utils package designed to cut the boilerplate out of building function-calling applications.
The announcement follows Cloudflare's initial function-calling support from mid-June. In the traditional model, an LLM receives a prompt plus a list of function names and argument schemas; it responds with the function and arguments to call, and the developer then makes the actual API request in a separate step. That means multiple round-trips across the network between the origin server, the inference provider, and external APIs, with the developer orchestrating every request and response. For complex agents with multi-tool or recursive calls, that orchestration burden grows quickly.
A different runtime model
Workers AI takes a different path because its inference runtime is the Workers platform itself—a global compute network of distributed functions (RPCs). Since the platform also provides compute, storage, and bindings, workers can pass not just function names and schemas to the model, but the actual function code to execute. The LLM inference and the function run in the same execution environment, eliminating many of the network requests that traditional function calling requires.
This embedded model also lets developers use open-source models with a developer experience comparable to what closed-source providers offer. Most other open-source inference providers focus on serving and infrastructure; Cloudflare's bet is that combining inference with a developer toolkit on one platform gives it an edge over using external libraries like AI SDK, which still depend on upstream inference providers.
The ai-utils package
The new @cloudflare/ai-utils package exposes two primary helpers for embedded function calling. It is available on npm and the source is on GitHub.
runWithTools
runWithTools is the core method for embedded function calling. You pass in your AI binding (env.AI), the model, your prompt messages, and a tools array. Each tool entry includes a function description and, unlike traditional function calling, the actual function code to run. The method makes the inference call and executes the function code in one step, with built-in handling for multiple function calls, recursive tool calls, response validation, and streaming the final response.
The package also includes an autoTrimTools helper, which uses an initial LLM inference call to select only the relevant tools and shrink the tools array before the real function-calling inference runs. Cloudflare reports this can reduce total token usage significantly when many tools are present, since fewer input tokens are consumed when generating the argument list. You opt in by passing autoTrimTools as a parameter to runWithTools.
createToolsFromOpenAPISpec
For applications that need to hit external APIs, createToolsFromOpenAPISpec takes an OpenAPI spec and dynamically generates the tool schemas and API endpoints you would otherwise have to write by hand. You call it inside runWithTools, and it populates everything for you.
Putting it together
The result is that the only thing you need to supply is the prompt. The model selects the correct tool based on the conversation, the runtime executes it, and the final response comes back without the user having to wire up the intermediate steps manually. The documentation for getting started is available on Cloudflare's developer docs.



