ENF News Bot
Automated News Bot
- Joined
- Apr 15, 2022
- Messages
- 2,591
The
Code Mode ↗︎ enables LLMs to write and execute code that orchestrates your tools, instead of calling them one at a time. This can (and does) yield significant token savings, reduces context window pressure and improves overall model performance on a task.
The new
https://developers.cloudflare.com/changelog/rss/#dynamicworkerexecutor
Runs code in a Dynamic Worker. It comes with the following features:
See the Code Mode documentation for full API reference and examples.
Continue reading...
@cloudflare/codemode ↗︎ package has been rewritten into a modular, runtime-agnostic SDK.Code Mode ↗︎ enables LLMs to write and execute code that orchestrates your tools, instead of calling them one at a time. This can (and does) yield significant token savings, reduces context window pressure and improves overall model performance on a task.
The new
Executor interface is runtime agnostic and comes with a prebuilt DynamicWorkerExecutor to run generated code in a Dynamic Worker Loader.Breaking changes
https://developers.cloudflare.com/changelog/rss/#breaking-changes- Removed
experimental_codemode()andCodeModeProxy— the package no longer owns an LLM call or model choice - New import path:
createCodeTool()is now exported from@cloudflare/codemode/ai
New features
https://developers.cloudflare.com/changelog/rss/#new-featurescreateCodeTool()— Returns a standard AI SDKToolto use in your AI agents.Executorinterface — Minimalexecute(code, fns)contract. Implement for any code sandboxing primitive or runtime.
DynamicWorkerExecutor
https://developers.cloudflare.com/changelog/rss/#dynamicworkerexecutorRuns code in a Dynamic Worker. It comes with the following features:
- Network isolation —
fetch()andconnect()blocked by default (globalOutbound: null) when usingDynamicWorkerExecutor - Console capture —
console.log/warn/errorcaptured and returned inExecuteResult.logs - Execution timeout — Configurable via
timeoutoption (default 30s)
Usage
https://developers.cloudflare.com/changelog/rss/#usage
Code:
import { createCodeTool } from "@cloudflare/codemode/ai";
import { DynamicWorkerExecutor } from "@cloudflare/codemode";
import { streamText } from "ai";
const executor = new DynamicWorkerExecutor({ loader: env.LOADER });
const codemode = createCodeTool({ tools: myTools, executor });
const result = streamText({
model,
tools: { codemode },
messages,
});
Code:
import { createCodeTool } from "@cloudflare/codemode/ai";
import { DynamicWorkerExecutor } from "@cloudflare/codemode";
import { streamText } from "ai";
const executor = new DynamicWorkerExecutor({ loader: env.LOADER });
const codemode = createCodeTool({ tools: myTools, executor });
const result = streamText({
model,
tools: { codemode },
messages,
});
Wrangler configuration
https://developers.cloudflare.com/changelog/rss/#wrangler-configuration
Code:
{
"worker_loaders": [{ "binding": "LOADER" }],
}
Code:
[[worker_loaders]]
binding = "LOADER"
See the Code Mode documentation for full API reference and examples.
Upgrade
https://developers.cloudflare.com/changelog/rss/#upgradenpm i @cloudflare/codemode@latestContinue reading...