Skip to content

Add support for advanced AI.run configuration in runWithTools + Add support for OpenAI-like function call output format#19

Open
Hiutaky wants to merge 3 commits into
cloudflare:mainfrom
Hiutaky:main
Open

Add support for advanced AI.run configuration in runWithTools + Add support for OpenAI-like function call output format#19
Hiutaky wants to merge 3 commits into
cloudflare:mainfrom
Hiutaky:main

Conversation

@Hiutaky

@Hiutaky Hiutaky commented Apr 15, 2026

Copy link
Copy Markdown

Make runWithTools generic over the model to infer input/output types,
and accept a 4th parameter for advanced ChatCompletions options
(temperature, max_tokens, top_p, seed, response_format, etc.)
that are passed through to ai.run calls.

Previously only Mistral-like responses ({ tool_calls: [{ name, arguments }] })
were handled. This adds an extractToolCalls helper that normalizes tool calls
from both Mistral-like and OpenAI-like ({ choices: [{ message: { tool_calls:
[{ function: { name, arguments } }] } }] }) response formats.

Also updates @cloudflare/workers-types and exports BaseAiTextGenerationModels
from local types to fix compatibility with newer package versions.

Hiutaky added 3 commits April 15, 2026 15:46
Previously only Mistral-like responses ({ tool_calls: [{ name, arguments }] })
were handled. This adds an extractToolCalls helper that normalizes tool calls
from both Mistral-like and OpenAI-like ({ choices: [{ message: { tool_calls:
[{ function: { name, arguments } }] } }] }) response formats.

Also updates @cloudflare/workers-types and exports BaseAiTextGenerationModels
from local types to fix compatibility with newer package versions.
Make runWithTools generic over the model to infer input/output types,
and accept a 4th parameter for advanced ChatCompletions options
(temperature, max_tokens, top_p, seed, response_format, etc.)
that are passed through to ai.run calls.
@kerema14

kerema14 commented Jul 1, 2026

Copy link
Copy Markdown

maybe review? it's been 2.5 months. @Dhravya

@Hiutaky

Hiutaky commented Jul 1, 2026

Copy link
Copy Markdown
Author

maybe review? it's been 2.5 months. @Dhravya

I think that cloudflare moved to a different AI Library to call the AI Workers, this one is still solid but with bad type infer. Dunno if my implementation is working with the latest wrangler versions

@kerema14

kerema14 commented Jul 1, 2026

Copy link
Copy Markdown

maybe review? it's been 2.5 months. @Dhravya

I think that cloudflare moved to a different AI Library to call the AI Workers, this one is still solid but with bad type infer. Dunno if my implementation is working with the latest wrangler versions

do you know what library it is? I couldn't find anything else on running cloudflare ai with tools, other than this one.

@Hiutaky

Hiutaky commented Jul 1, 2026

Copy link
Copy Markdown
Author

maybe review? it's been 2.5 months. @Dhravya

I think that cloudflare moved to a different AI Library to call the AI Workers, this one is still solid but with bad type infer. Dunno if my implementation is working with the latest wrangler versions

do you know what library it is? I couldn't find anything else on running cloudflare ai with tools, other than this one.

Check here: Cloudflare Agents

There's this new generateText method that accepts tools. I'm still using the ai-utils for my app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants