The Cloudflare OS agent is a fully general-purpose AI assistant. While it excels at building Gadgets, you can use it for any task — writing, analysis, research, automation — without creating an app at all. What makes it distinctive is how it performs those tasks: the Cloudflare OS agent is a Code Mode agent, meaning it acts by writing and immediately executing snippets of code rather than by calling a fixed set of predefined tools.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/cloudflare/cloudflare-os/llms.txt
Use this file to discover all available pages before exploring further.
Code Mode explained
In most agent frameworks, tools are defined upfront as a fixed list of functions. The agent picks from the list, fills in parameters, and calls the tool. This works, but it creates a rigid interface between the agent and the world. Cloudflare OS agents use Code Mode instead. When the agent wants to accomplish a step in a task, it writes a JavaScript snippet and executes it. The snippet can call any method on any resource that has been introduced to the session — Gatekeeper APIs, Gadget methods, spawner controls — all via natural code.- Low boilerplate for the agent. Cap’n Web RPC means the agent calls service methods as if they were local function calls, with no HTTP wrangling or JSON parsing.
- Any API is automatically a tool. The Gadget’s own server methods, Gatekeeper APIs, and spawner controls are all directly callable from
executeCode. There is no need to build a separate tool layer.
Context and the Context Library
Before the agent begins a task, it reads from the Context Library — an auto-provisioned Gatekeeper that provides named collections of context documents. These documents are surfaced to the agent as observations (read-only inputs) at the start of each chat session. Context collections come in two forms:| Type | Created by | Readable by |
|---|---|---|
| Public | Deployment admins | All users automatically |
| Private | Individual users | That user only |
getSession() and getAgentCatalog() on the context account; each read is recorded as an observation in the action log.
Because the Context Library is auto-provisioned, there is no OAuth flow and no introduction step. It is always available in the agent’s environment.
Capability-based tool access
A freshly opened agent session has access to nothing external. Even if you have configured a dozen Gatekeeper accounts, the agent cannot use any of them until you explicitly introduce a resource to the session. Introductions happen in three ways:- Paste a link to a resource (e.g., a GitHub repo URL or Google Doc URL). The Workshop creates a Gatekeeper for that resource and surfaces it as a named binding in the chat’s environment.
- Use the “Add resource” UI to select a resource from a connected account via the resource configurator.
- The agent requests a connection. The agent emits a
connectionRequestchat message naming the vendor, resource type, and reason. You accept or deny it inline; on acceptance the Gatekeeper is created and the agent is resumed.
executeCode environment as env.BINDING_NAME, where the binding name is a JavaScript identifier the agent chooses when making the request.
Gatekeeper bindings in executeCode
When the agent’s code snippet runs, it receives an env object populated with every resource introduced to the current chat. Two methods on the agent session are important for understanding what is available:
getSession()— returns the agent’s own session stub, including references to the chat’s bound Gatekeepers and ambient singletons (Context Library, Scheduler).getAgentCatalog()— returns a description of the Gatekeeper APIs available in the current session, formatted as text for the agent’s context window.
getAgentCatalog() at the start of each turn to understand what it can call, then writes executeCode snippets that call those methods directly.
Agent spawners
A Gadget can define agent spawner bindings — configuration that allows the Gadget’s server code to programmatically create new agent chat threads at runtime. This is how Gadgets implement automated workflows: a Gadget that processes incoming emails might spawn a separate agent for each message. Each spawner binding is created with anAgentSpawnerConfig:
env field defines exactly which resources the spawned agent can access — a snapshot taken at spawn time. The spawned agent sees only these bindings, never the workspace’s full default binding list. This is the right security primitive for preventing prompt injection between email threads or other isolated task contexts.
Spawner bindings are configured from the Connections panel and appear as a binding type in Blueprints so that Blueprint consumers can choose which model their spawner should use.
Model providers
Cloudflare OS works with all major AI model providers. Models are configured per-user from the Settings panel and identified by a stable string ID used throughout the API.| Provider | Example models |
|---|---|
| Anthropic | Claude Opus 5, Claude Sonnet 5, Claude Haiku 4.5 |
| OpenAI | GPT 5.6 Sol, GPT 5.6 Luna, GPT 5.6 Terra |
| Gemini 3.6 Flash | |
| Cloudflare Workers AI | Kimi K2.7 Code, GLM 5.2 |
| Ollama | Any self-hosted model |
apiUrl field.
Bring Your Own Key (BYOK): AI model usage is billed to the API token attached to the model configuration of the user who sent the message — not the Gadget owner. When a collaborator uses the agent inside a shared Gadget, their model configuration and API token are used for that turn. This means Gadget owners are not charged for their collaborators’ AI usage.
Compaction
Long agent conversations eventually approach the model’s context window limit. When this happens, the Workshop performs compaction: a background step that summarizes earlier portions of the conversation history and replaces them with a compact checkpoint. Compaction is transparent to the user — the full message history remains readable in the UI, but older messages are replaced by a summary in the model’s prompt for subsequent turns. TheAiChatMetadata.compactedTo field records the sequence number through which the current compaction checkpoint covers, so the client can page through history one checkpoint-delimited segment at a time.
The outputLimit field on each model configuration (used for Workers AI models with a fixed response budget) is how the Workshop sizes the prompt budget for compaction — reserving outputLimit tokens for the response and targeting the remainder as the maximum prompt size.