Skip to content

Tools

Think provides built-in workspace file tools on every turn, plus integration points for custom tools, web fetches, code execution, and dynamic extensions.

Tool merge order

On every turn, Think merges tools from multiple sources. Later sources override earlier ones if names collide:

  1. Workspace tools — read, ls, find, grep, write, edit, delete, plus exec and publish when configured (built-in)
  2. getTools() — your custom server-side tools
  3. Extension tools — tools from loaded extensions (prefixed by extension name)
  4. Context tools — set_context, search_context (from configureContext() and configureSession(), refer to Context)
  5. Skill tools — activate_skill, read_skill_resource, run_skill_script (from getSkills(), refer to Agent Skills)
  6. MCP tools — from connected MCP servers when includeMcpTools is true
  7. Client tools — from the browser (refer to Client tools)

Tools belong to the agent running the turn. For parent-child orchestration, use Agents as tools instead of passing one-off tools through chat().

Connect a workspace

Every Think agent is connected to a workspace. this.workspace is a Workspace from Cloudflare Computer (@cloudflare/computer), stored in the Durable Object's SQLite database. The default workspace is a filesystem with no execution backend. Override workspace to add a backend for exec, git, or read-only mounts.

What Think does with the workspace:

  • It gives the model the built-in workspace tools on every turn.
  • It stores media that has aged out of the conversation under /workspace/attachments/evicted/, and large responses from the fetch tool under /workspace/fetched/.

Built-in workspace tools

Think adds Computer's AI SDK tools for this.workspace to every turn with no configuration.

Tool Description
read Read text with line and byte paging; pass images and PDFs to multimodal models
ls List files and directories in a path, with pagination
find Find files matching a glob pattern
grep Search file contents by regex or fixed string
write Write content to a file (creates parent directories)
edit Apply exact text replacements to a file, falling back to whitespace-tolerant search
delete Delete a file or directory
exec Run a command or module on one of the Workspace's execution backends
publish Share a workspace file through a presigned URL, when the Workspace has assets

Paths are absolute. Computer's tools and backends treat /workspace as the working root, and Think writes its own files there too.

@cloudflare/computer is a peer dependency of Think:

npm install @cloudflare/computer

Run code with exec

The default Workspace has no execution backends, so there is no exec tool until you add one. Configure the backends, and the modules they offer, on the Workspace:

import { Think } from "@cloudflare/think";
import { Workspace } from "@cloudflare/computer";
import { CodemodeBackend } from "@cloudflare/computer/backends/codemode";
import { createGitClient } from "@cloudflare/computer/git";
import { createGitModule } from "@cloudflare/computer/modules/git";
import { createAI } from "agents/models/ai-sdk";

export class MyAgent extends Think {
	workspace = new Workspace({
		storage: this.ctx.storage,
		git: createGitClient(),
		backends: [
			new CodemodeBackend({
				loader: this.env.LOADER,
				access: "read-write",
				modules: { "codemode:git": createGitModule() },
			}),
		],
	});

	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}
}
import { Think } from "@cloudflare/think";
import { Workspace } from "@cloudflare/computer";
import { CodemodeBackend } from "@cloudflare/computer/backends/codemode";
import { createGitClient } from "@cloudflare/computer/git";
import { createGitModule } from "@cloudflare/computer/modules/git";
import { createAI } from "agents/models/ai-sdk";

export class MyAgent extends Think<Env> {
	override workspace = new Workspace({
		storage: this.ctx.storage,
		git: createGitClient(),
		backends: [
			new CodemodeBackend({
				loader: this.env.LOADER,
				access: "read-write",
				modules: { "codemode:git": createGitModule() },
			}),
		],
	});

	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}
}

The codemode backend runs JavaScript in a Dynamic Worker, so it needs a Worker Loader binding:

{
  "$schema": "./node_modules/wrangler/config-schema.json",
  "worker_loaders": [
    {
      "binding": "LOADER"
    }
  ]
}
[[worker_loaders]]
binding = "LOADER"

Computer also ships two experimental backends: a just-bash shell backend that runs in Dynamic Workers, and a container backend with a full Linux userland. Refer to the Computer README ↗︎ for each backend's bindings.

Call the agent's tools from code

Give a codemode backend a codemode:tools module, and code the model runs with exec can import the agent's tools. Code reads files through node:fs/promises, so serve getTools() rather than the workspace tools:

import { createToolBindings } from "@cloudflare/computer/modules/tools";
import { forAISDKTools } from "@cloudflare/computer/tools/ai-sdk";

new CodemodeBackend({
	loader: this.env.LOADER,
	modules: {
		"codemode:tools": createToolBindings(forAISDKTools(() => this.getTools())),
	},
});
import { createToolBindings } from "@cloudflare/computer/modules/tools";
import { forAISDKTools } from "@cloudflare/computer/tools/ai-sdk";

new CodemodeBackend({
	loader: this.env.LOADER,
	modules: {
		"codemode:tools": createToolBindings(forAISDKTools(() => this.getTools())),
	},
});

Code the model runs with exec:

import { readFile } from "node:fs/promises";
import { getWeather } from "codemode:tools";

export default async function () {
	const cities = JSON.parse(await readFile("/workspace/cities.json", "utf8"));
	const reports = [];
	for (const city of cities) reports.push((await getWeather({ city })).text);
	return reports;
}

codemode:tools does not export tools that need approval or tools that run in the browser, because nothing can approve or run them from code. Calls from code do not go through beforeToolCall. Refer to codemode:tools ↗︎ for how calls and results work.

Change the tools

exec offers every backend the Workspace has, and each backend describes itself to the model. To change a built-in tool, return a tool with the same name from getTools(). It replaces the built-in. To hide tools for a turn, return activeTools from beforeTurn.

Upgrade to Computer 0.10

Think 0.24 and later need @cloudflare/computer 0.10. Upgrade both together. In Computer 0.10, the JavaScript backend is CodemodeBackend from @cloudflare/computer/backends/codemode, replacing WorkerJavaScriptBackend from @cloudflare/computer/backends/worker-javascript, and host modules use the codemode: prefix instead of ws:, such as codemode:tools and codemode:git.

Upgrade from @cloudflare/shell

Earlier versions of Think used a Workspace from @cloudflare/shell, which is now deprecated. Computer stores files in different tables, and Think does not move your data. To keep an existing workspace, copy its files with the script in Migrating from @cloudflare/shell to @cloudflare/computer ↗︎.

The upgrade also changes the tools:

  • list is now ls.
  • The in-process bash tool is gone. Add a backend to the Workspace to get exec.
  • workspaceBash, createWorkspaceTools, and @cloudflare/think/tools/workspace are removed, with no replacement. To change a built-in tool, return a tool with the same name from getTools(). To hide tools for a turn, return activeTools from beforeTurn.

Refer to Upgrading to a Computer workspace ↗︎ for the full list.

Custom tools

Override getTools() to add your own tools. These are standard AI SDK tool() definitions with schemas from a library like Zod or Valibot:

import { Think } from "@cloudflare/think";
import { tool } from "ai";

import { z } from "zod";
import { createAI } from "agents/models/ai-sdk";

export class MyAgent extends Think {
	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}

	getTools() {
		return {
			getWeather: tool({
				description: "Get the current weather for a city",
				inputSchema: z.object({
					city: z.string().describe("City name"),
				}),
				execute: async ({ city }) => {
					const res = await fetch(
						`https://api.weather.com/v1/current?q=${city}&key=${this.env.WEATHER_KEY}`,
					);
					return res.json();
				},
			}),
		};
	}
}
import { Think } from "@cloudflare/think";
import { tool } from "ai";
import type { ToolSet } from "ai";
import { z } from "zod";
import { createAI } from "agents/models/ai-sdk";

export class MyAgent extends Think<Env> {
	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}

	getTools(): ToolSet {
		return {
			getWeather: tool({
				description: "Get the current weather for a city",
				inputSchema: z.object({
					city: z.string().describe("City name"),
				}),
				execute: async ({ city }) => {
					const res = await fetch(
						`https://api.weather.com/v1/current?q=${city}&key=${this.env.WEATHER_KEY}`,
					);
					return res.json();
				},
			}),
		};
	}
}

Custom tools are merged with workspace tools automatically. If a custom tool has the same name as a workspace tool, the custom tool wins.

Tool approval

Tools can require user approval before execution using the needsApproval option:

getTools(): ToolSet {
	return {
		deleteFile: tool({
			description: "Delete a file from the system",
			inputSchema: z.object({ path: z.string() }),
			needsApproval: async ({ path }) => path.startsWith("/important/"),
			execute: async ({ path }) => {
				await this.workspace.fs.rm(path);
				return { deleted: path };
			},
		}),
	};
}

When needsApproval returns true, the tool call is sent to the client for approval. The conversation pauses until the client responds with CF_AGENT_TOOL_APPROVAL.

Per-turn tool overrides

The beforeTurn hook can restrict or add tools for a specific turn:

beforeTurn(ctx: TurnContext) {
	return {
		activeTools: ["read", "write", "getWeather"],
		tools: { emergencyTool: this.createEmergencyTool() },
	};
}

activeTools limits which tools the model can call. tools adds extra tools for this turn only (merged on top of existing tools).

MCP tools

Think inherits MCP client support from the Agent base class. By default, Think converts tools from connected MCP servers to AI SDK tools and adds them to every turn.

Set waitForMcpConnections to ensure MCP servers are connected before inference runs:

export class MyAgent extends Think {
	waitForMcpConnections = true; // default 10s timeout
	// or: waitForMcpConnections = { timeout: 5000 };

	getModel() {
		/* ... */
	}
}
export class MyAgent extends Think<Env> {
	waitForMcpConnections = true; // default 10s timeout
	// or: waitForMcpConnections = { timeout: 5000 };

	getModel() {
		/* ... */
	}
}

If you expose MCP tools through Code Mode or another mechanism outside Think's automatic tool set, turn off direct AI SDK tool exposure:

export class MyAgent extends Think {
	includeMcpTools = false;
	waitForMcpConnections = true;

	getModel() {
		/* ... */
	}
}
export class MyAgent extends Think<Env> {
	includeMcpTools = false;
	waitForMcpConnections = true;

	getModel() {
		/* ... */
	}
}

includeMcpTools controls only the automatic model tool merge. MCP connections still register, restore, discover, and wait. Raw catalog access, direct calls, Code Mode connectors, and explicit this.mcp.getAITools() calls continue to work.

Use this property instead of removing MCP tool names through activeTools in beforeTurn. Think converts MCP schemas before it calls beforeTurn, so activeTools cannot avoid that conversion. To configure a connector runtime, refer to Use MCP tools with Code Mode.

Add MCP servers programmatically or via @callable methods:

import { callable } from "agents";
import { createAI } from "agents/models/ai-sdk";

export class MyAgent extends Think {
	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}

	@callable()
	async addServer(name, url) {
		return await this.addMcpServer(name, url);
	}

	@callable()
	async removeServer(serverId) {
		await this.removeMcpServer(serverId);
	}
}
import { callable } from "agents";
import { createAI } from "agents/models/ai-sdk";

export class MyAgent extends Think<Env> {
	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}

	@callable()
	async addServer(name: string, url: string) {
		return await this.addMcpServer(name, url);
	}

	@callable()
	async removeServer(serverId: string) {
		await this.removeMcpServer(serverId);
	}
}

Code execution tool

Let the LLM write and run JavaScript in a sandboxed Worker, recorded on a durable Code Mode runtime (abort-and-replay, human approvals, audit trail, reusable snippets). Requires @cloudflare/codemode and a worker_loaders binding.

npm install @cloudflare/codemode

The one-liner infers the executor from env.LOADER and a live browser (cdp.*) from env.BROWSER if bound. Pass tools for tools.*, including the workspace tools if the sandbox should reach the workspace:

import { Think } from "@cloudflare/think";
import { createAITools } from "@cloudflare/computer/tools/ai-sdk";
import { createExecuteTool } from "@cloudflare/think/tools/execute";
import { createAI } from "agents/models/ai-sdk";

export class MyAgent extends Think {
	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}

	getTools() {
		return {
			execute: createExecuteTool(this, {
				tools: createAITools({ workspace: this.workspace }),
			}),
		};
	}
}
import { Think } from "@cloudflare/think";
import { createAITools } from "@cloudflare/computer/tools/ai-sdk";
import { createExecuteTool } from "@cloudflare/think/tools/execute";
import { createAI } from "agents/models/ai-sdk";

export class MyAgent extends Think<Env> {
	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}

	getTools() {
		return {
			execute: createExecuteTool(this, {
				tools: createAITools({ workspace: this.workspace }),
			}),
		};
	}
}

Setup checklist:

{
  "$schema": "./node_modules/wrangler/config-schema.json",
  "worker_loaders": [
    {
      "binding": "LOADER"
    }
  ],
  "browser": {
    "binding": "BROWSER"
  }
}
[[worker_loaders]]
binding = "LOADER"

[browser]
binding = "BROWSER" # optional — enables cdp.*
// worker entry — the runtime lives in a Durable Object facet, so the class
// must be exported (the @cloudflare/codemode/vite plugin does this
// automatically; the Think framework's generated entry already includes it)
export { CodemodeRuntime } from "@cloudflare/codemode";
// worker entry — the runtime lives in a Durable Object facet, so the class
// must be exported (the @cloudflare/codemode/vite plugin does this
// automatically; the Think framework's generated entry already includes it)
export { CodemodeRuntime } from "@cloudflare/codemode";

Each missing piece fails with an error naming the step.

Inside the sandbox the model sees typed namespaces plus the platform SDK:

  • tools.* — your AI SDK tools (object args, validated against their schemas). Only tools with an execute function are exposed — client-side tools cannot run in the sandbox.
  • cdp.* — the browser, when a Browser Run binding is configured. The execute tool defaults to session: { mode: "dynamic" }: sessions are per-execution unless the model promotes one with cdp.startSession().
  • codemode.search / codemode.describe / codemode.step / codemode.run — discovery, side-effect boundaries, and saved snippets.

Or pass fully explicit options (no agent inference):

createExecuteTool({
	ctx: this.ctx,
	tools: myDomainTools,
	browser: this.env.BROWSER,
	loader: this.env.LOADER,
});
createExecuteTool({
	ctx: this.ctx,
	tools: myDomainTools,
	browser: this.env.BROWSER,
	loader: this.env.LOADER,
});

Approvals (human-in-the-loop)

An AI SDK tool with needsApproval does not run immediately inside the sandbox — calling it pauses the run durably. The pause comes back as a normal tool output ({ status: "paused", executionId, pending }), the model tells the user what it needs, and the turn ends. This differs from the client-side approval flow for plain getTools() tools: inside the sandbox a function-valued needsApproval cannot be evaluated against the call's arguments ahead of time, so it conservatively always requires approval. Think ships built-in callables to resolve it:

  • approveExecution(executionId) — resumes the run where it stopped. Already-done work is replayed, not re-executed. The outcome replaces the paused output in the transcript and the chat auto-continues.
  • rejectExecution(executionId, reason?) — ends the run with { status: "rejected", reason } so the model can adapt.
  • pendingExecutions() — pending actions (with full args) for rendering approval UI.

For a working approval card, refer to the assistant example ↗︎.

The runtime handle

createExecuteRuntime returns the moving parts when the host needs more than the tool — and the handle is also assigned to this.codemode when created from an agent:

import { createExecuteRuntime } from "@cloudflare/think/tools/execute";

const { runtime, connectors, tool } = createExecuteRuntime(this);
await runtime.executions(); // audit trail
await runtime.expirePaused(); // reclaim stale never-approved pauses (call from a scheduled task)
await runtime.saveSnippet("name", { executionId }); // promote a script for reuse
import { createExecuteRuntime } from "@cloudflare/think/tools/execute";

const { runtime, connectors, tool } = createExecuteRuntime(this);
await runtime.executions(); // audit trail
await runtime.expirePaused(); // reclaim stale never-approved pauses (call from a scheduled task)
await runtime.saveSnippet("name", { executionId }); // promote a script for reuse

Fetch tool

The fetch tool gives the model a read-only way to read web pages and internal APIs. It is off by default. Set the fetchTools property to turn it on:

import { Think } from "@cloudflare/think";
import { createAI } from "agents/models/ai-sdk";

export class DocsAgent extends Think {
	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}

	fetchTools = {
		allowlist: ["https://developers.cloudflare.com/**"],
		bindings: {
			docsApi: {
				binding: this.env.DOCS_API,
				description: "Internal docs search API.",
				allowlist: ["/v1/docs/**"],
				headers: { "x-agent": "think" },
			},
		},
	};
}
import { Think } from "@cloudflare/think";
import { createAI } from "agents/models/ai-sdk";

export class DocsAgent extends Think<Env> {
	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}

	fetchTools = {
		allowlist: ["https://developers.cloudflare.com/**"],
		bindings: {
			docsApi: {
				binding: this.env.DOCS_API,
				description: "Internal docs search API.",
				allowlist: ["/v1/docs/**"],
				headers: { "x-agent": "think" },
			},
		},
	};
}

Think adds a fetch_url tool when you set a public allowlist, and one fetch_<name> tool for each entry in bindings, such as fetch_docsApi for a service binding. Each binding has its own path allowlist and fixed headers, which the model cannot see or change.

The tool is built to be safe to hand to a model:

  • Read-only. It only sends GET requests. For changes, use an action with approval.
  • Allowlisted. Every request must match the allowlist after the URL is normalized. fetch_url blocks private, loopback, link-local, and *.internal targets even if the allowlist allows them.
  • Bounded. maxBytes caps the download and maxModelChars truncates the text the model sees. With response: "workspace", or spillToWorkspace: true, large or binary bodies are written to a workspace file under /workspace/fetched/ instead of the transcript.
  • Header-safe. The model can only set headers in modelHeaderAllowlist (by default accept, accept-language, and range).
  • Redirect-safe. By default a redirect is followed only when the final URL is still allowlisted. Binding targets never follow cross-origin redirects.

In an allowlist, a bare origin such as https://example.com matches that origin and every path under it. ** matches any characters, including /, and * matches any character except /. Matching ignores the query string and fragment.

Results are values, not exceptions. A failed request returns { ok: false, code, message }, where code is one of disallowed_url, disallowed_redirect, timeout, aborted, non_2xx, unsupported_content_type, invalid_json, too_large, or request_failed.

For an allowlist that changes per tenant or per turn, call createFetchTools() from @cloudflare/think/tools/fetch in getTools() instead. It takes the same options, and runs on every turn:

import { Think } from "@cloudflare/think";
import { createFetchTools } from "@cloudflare/think/tools/fetch";

export class MyAgent extends Think {
	getTools() {
		const tenant = this.getConfig();
		return {
			...createFetchTools({
				allowlist: tenant ? [`${tenant.docsOrigin}/**`] : [],
				workspace: this.workspace,
			}),
		};
	}
}
import { Think } from "@cloudflare/think";
import { createFetchTools } from "@cloudflare/think/tools/fetch";

export class MyAgent extends Think<Env> {
	getTools() {
		const tenant = this.getConfig<{ docsOrigin: string }>();
		return {
			...createFetchTools({
				allowlist: tenant ? [`${tenant.docsOrigin}/**`] : [],
				workspace: this.workspace,
			}),
		};
	}
}

To block or replace a fetch for one call, use beforeToolCall. For a stateless fetch tool that works with any AI SDK agent, refer to Web fetch.

Browser tools

browserTool from agents/browser/ai-sdk gives the model a persistent browser that it drives with the Chrome DevTools Protocol (CDP). Tabs, cookies, and logins carry over from one turn to the next. Install a Browser on the agent's Lifecycle, and return the tool from getTools():

import { Think } from "@cloudflare/think";
import { Browser, browserRun } from "agents/browser";
import { browserTool } from "agents/browser/ai-sdk";
import { createAI } from "agents/models/ai-sdk";

export class MyAgent extends Think {
	browser = new Browser({ provider: browserRun(this.env.BROWSER) });

	constructor(ctx, env) {
		super(ctx, env);
		this.lifecycle.use(this.browser);
	}

	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}

	getTools() {
		return {
			browser: browserTool({ browser: this.browser, loader: this.env.LOADER }),
		};
	}
}
import { Think } from "@cloudflare/think";
import { Browser, browserRun } from "agents/browser";
import { browserTool } from "agents/browser/ai-sdk";
import { createAI } from "agents/models/ai-sdk";

export class MyAgent extends Think<Env> {
	readonly browser = new Browser({ provider: browserRun(this.env.BROWSER) });

	constructor(ctx: DurableObjectState, env: Env) {
		super(ctx, env);
		this.lifecycle.use(this.browser);
	}

	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}

	getTools() {
		return {
			browser: browserTool({ browser: this.browser, loader: this.env.LOADER }),
		};
	}
}

It needs a Browser Run binding, a Worker Loader binding, and @cloudflare/codemode installed:

{
  "$schema": "./node_modules/wrangler/config-schema.json",
  "browser": {
    "binding": "BROWSER"
  },
  "worker_loaders": [
    {
      "binding": "LOADER"
    }
  ]
}
[browser]
binding = "BROWSER"

[[worker_loaders]]
binding = "LOADER"

For how the browser behaves, internal hostnames, Live View, and recording, refer to Browse the web.

createBrowserTools() and createQuickActionTools() from @cloudflare/think/tools/browser are deprecated. They keep working, but will not change. To read a page without a browser, use the fetch tool.

Extensions

Extensions are dynamically loaded sandboxed Workers that add tools at runtime. The LLM can write extension source code, load it, and use the new tools on the next turn.

Extensions require a worker_loaders binding:

import { Think } from "@cloudflare/think";
import { createAI } from "agents/models/ai-sdk";

export class MyAgent extends Think {
	extensionLoader = this.env.LOADER;

	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}
}
import { Think } from "@cloudflare/think";
import { createAI } from "agents/models/ai-sdk";

export class MyAgent extends Think<Env> {
	extensionLoader = this.env.LOADER;

	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}
}

Static extensions

Define extensions that load at startup:

export class MyAgent extends Think {
	extensionLoader = this.env.LOADER;

	getModel() {
		/* ... */
	}

	getExtensions() {
		return [
			{
				manifest: {
					name: "math",
					version: "1.0.0",
					permissions: { network: false },
				},
				source: `({
					tools: {
						add: {
							description: "Add two numbers",
							parameters: { a: { type: "number" }, b: { type: "number" } },
							execute: async ({ a, b }) => ({ result: a + b })
						}
					}
				})`,
			},
		];
	}
}
export class MyAgent extends Think<Env> {
	extensionLoader = this.env.LOADER;

	getModel() {
		/* ... */
	}

	getExtensions() {
		return [
			{
				manifest: {
					name: "math",
					version: "1.0.0",
					permissions: { network: false },
				},
				source: `({
					tools: {
						add: {
							description: "Add two numbers",
							parameters: { a: { type: "number" }, b: { type: "number" } },
							execute: async ({ a, b }) => ({ result: a + b })
						}
					}
				})`,
			},
		];
	}
}

Extension tools are namespaced — a math extension with an add tool becomes math_add in the model's tool set.

LLM-driven extensions

Give the model createExtensionTools so it can load extensions dynamically:

import { createExtensionTools } from "@cloudflare/think/tools/extensions";
import { createAI } from "agents/models/ai-sdk";

export class MyAgent extends Think {
	extensionLoader = this.env.LOADER;

	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}

	getTools() {
		return {
			...createExtensionTools({ manager: this.extensionManager }),
			...this.extensionManager.getTools(),
		};
	}
}
import { createExtensionTools } from "@cloudflare/think/tools/extensions";
import { createAI } from "agents/models/ai-sdk";

export class MyAgent extends Think<Env> {
	extensionLoader = this.env.LOADER;

	getModel() {
		return createAI({ binding: this.env.AI })(
			"@cf/deepseek-ai/deepseek-v4.1-flash-1017",
		);
	}

	getTools() {
		return {
			...createExtensionTools({ manager: this.extensionManager! }),
			...this.extensionManager!.getTools(),
		};
	}
}

This gives the model two tools:

  • load_extension — load a new extension from JavaScript source
  • list_extensions — list currently loaded extensions

Extension context blocks

Extensions can declare context blocks in their manifest. These are automatically registered with the Session:

getExtensions() {
	return [{
		manifest: {
			name: "notes",
			version: "1.0.0",
			permissions: { network: false },
			context: [
				{ label: "scratchpad", description: "Extension scratch space", maxTokens: 500 },
			],
		},
		source: `({ tools: { /* ... */ } })`,
	}];
}

The context block is registered as notes_scratchpad (namespaced by extension name).

Was this helpful?