Skip to content
Automation
Agent

prompt-caching

`Agent.promptCaching()` generates provider-specific `providerOptions` for Anthropic, Claude on OpenRouter and Vertex, and OpenAI. Callers do not have to write the AI SDK's raw `cacheControl` / `promptCacheKey` shapes. It uses the existing `providerOptions` escape hatch — nothing

From plugin
n8n
209k10 skills10 agents2 commands

Claude Code

$ npx -y skills add n8n-io/n8n --agent claude-code

Agent definition

prompt-caching.md

Prompt caching

`Agent.promptCaching()` generates provider-specific `providerOptions` for Anthropic, Claude on OpenRouter and Vertex, and OpenAI. Callers do not have to write the AI SDK's raw `cacheControl` / `promptCacheKey` shapes. It uses the existing `providerOptions` escape hatch — nothing here is required, and anything set explicitly (via `.instructions(text, { providerOptions })`, call-level `providerOptions`, or `Tool.providerOptions(...)`) always wins on conflicts.

// Defaults tuned for agent workloads: Anthropic gets a 1h instruction
// breakpoint, OpenAI gets 24h retention plus an auto-generated cache key.
new Agent('assistant').model('anthropic/claude-sonnet-4-5').promptCaching().instructions(LONG_SYSTEM_PROMPT);

// Override a field, or disable a provider entirely.
new Agent('assistant')
  .model('anthropic/claude-sonnet-4-5')
  .promptCaching({ anthropic: { ttl: '5m' } })
  .instructions(LONG_SYSTEM_PROMPT);

new Agent('assistant')
  .model('openai/gpt-5.1')
  .promptCaching({ openai: { promptCacheKey: 'assistant-v1' } })
  .instructions(LONG_SYSTEM_PROMPT);

The n8n Agent JSON config is a mandatory, simplified surface

The richer SDK shape above (OpenAI key/retention overrides) is for direct SDK callers. The n8n Agent product (JSON config / builder UI) exposes `config.promptCaching: { enabled: boolean; anthropic?: { ttl?: '5m' | '1h' } }` and passes explicit settings to `agent.promptCaching(config.promptCaching)`.

  • **Mandatory in the builder.** For OpenAI, Anthropic, and Claude on OpenRouter

or Vertex, the config is always force-written with `{ enabled: true, ... }` by the builder agent's write-path normalizer and the model picker — regardless of what the LLM or a prior config said; there is no user-facing way to disable it. Other models do not get the field.

  • **Existing routed Claude agents get the default on their next run.** When a

saved `openrouter/anthropic/claude-*` or `google-vertex/claude-*` agent has no cache config, the JSON loader supplies `{ enabled: true }`. This does not change the saved config. Explicit settings, including `enabled: false`, pass through unchanged. Standalone SDK use stays opt-in.

  • **Claude cache duration defaults to `1h`.** The Advanced panel renders

a Cache duration dropdown (`5m` / `1h`) for Anthropic and routed Claude agents. OpenAI has no sub-config or UI (its caching is fully automatic server-side). The TTL is preserved when switching between the supported Claude routes.

Native tool deferral

`Agent.nativeToolDeferral({ eagerToolNames })` uses native tool search for eligible model versions on direct OpenAI and Anthropic endpoints. n8n enables this policy during agent reconstruction. It has no Agent Builder setting.

new Agent('assistant')
  .model('openai/gpt-5.4')
  .nativeToolDeferral({ eagerToolNames: ['workspace_read_file', 'load_skill'] })
  .promptCaching();

The runtime sends the complete authorized catalog on each request. Native tool search controls which local definitions enter the model context. Discovery does not change the catalog, tool order, instructions, or execution handlers. Provider-native tools stay eager. Local tools with explicit cache markers or `deferLoading: false` also stay eager.

Providers register deferral through the runtime model registry. Each implementation supplies `supports` and `prepareTools`. The [OpenAI](../src/runtime/model/native-tool-deferral/openai.ts) and [Anthropic](../src/runtime/model/native-tool-deferral/anthropic.ts) implementations define model support, allowed endpoints, and search setup. The [shared code](../src/runtime/model/native-tool-deferral.ts) resolves and checks endpoints, finds configured provider tools, selects eager tools, applies the fallback, and adapts provider schemas.

The runtime uses numeric version rules instead of a model allowlist:

  • OpenAI Responses uses hosted `tool_search` for GPT-5.4 and later versions.

GPT-5.4 Nano stays eager, including its dated snapshots. See the [tool search guide](https://developers.openai.com/api/docs/guides/tools-tool-search) and the [Nano model page](https://developers.openai.com/api/docs/models/gpt-5.4-nano).

  • Anthropic Messages uses native BM25 tool search for Claude 4.5 and later

versions. The rule accepts model families that use the `claude-<family>-<major>[-<minor>]` format, including dated snapshots. See the [model compatibility table](https://platform.claude.com/docs/en/agents-and-tools/tool-use/tool-search-tool#model-compatibility).

Later versions in these formats qualify without a catalog update. For Claude, this is a forward compatibility policy based on the current table. The provider does not guarantee support for every future model.

The runtime checks the model version, API route, and effective endpoint before the request. Older versions, excluded variants, unknown model ID formats, other providers, Chat Completions, and custom endpoints use the complete eager catalog. Gateway credits also stays eager. When native search is not available, or the agent sets `.toolDeferral({ mode: 'tool-catalog' })`, deferred tools go behind the tool catalog: the prompt lists their names, and the model uses `find_tools` and `call_tool`.

Discovered definitions stay at their original history positions. OpenAI appends search results to the conversation. Anthropic expands tool references in the conversation. The runtime does not move discovered tools into the eager prefix. Call and result provider options are stored separately. This preserves the separate OpenAI search-result item ID through memory and approval checkpoints. The catalog carries the registered search tool name into prompt preparation. When the catalog changes, the runtime uses that name to remove unavailable Anthropic tool references from search results in the outgoing prompt. It also omits failed Anthropic search calls and their results from that prompt. Stored messages keep the original searc

Read more
@n8n-io
Ships withn8n

Fair-code platform to build and deploy AI agents and workflows. Combine a visual canvas with custom code, run it self-hosted or in the cloud, and connect to 1500+ integrations. AI automation you can trust with real work, from prototype to production.

209k12 skills10 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
209.2k
Star history of n8n-io/n8n on GitHub, a chart by star-history.com

Other agents on n8n.

developer

developer

Agent

Use this agent for any n8n development task - frontend (Vue 3), backend (Node.js/TypeScript), workflow engine, node creation, or…

@n8n-io@n8n-ioInstall Agent
linear-issue-triager

linear-issue-triager

Agent

Use this agent proactively when a Linear issue is created, updated, or needs comprehensive analysis. This agent performs thorough…

@n8n-io@n8n-ioInstall Agent
episodic-memory-capture

episodic-memory-captur…

Agent

Capture-capable memory backends must implement `EpisodicMemoryCaptureMethods`. This includes `getEntriesByContentHashes(scope,…

@n8n-io@n8n-ioInstall Agent
observation-log-storage

observation-log-storag…

Agent

Observational memory requires a `BuiltObservationLogStore` backend. The backend must implement `commitObservationLogBatch`. The…

@n8n-io@n8n-ioInstall Agent
BUILT_IN_TOOLS

BUILT_IN_TOOLS

Agent

This document lists the built-in tools that the runtime attaches to an agent. It explains what each tool does and when the…

@n8n-io@n8n-ioInstall Agent
PLAN_TASK_STATUS

PLAN_TASK_STATUS

Agent

Each task has one source of status. A parent-run task stores its status and timestamps in the plan. A delegated task stores one…

@n8n-io@n8n-ioInstall Agent

More agents from other plugins.

aris-fanout-leaf

aris-fanout-leaf

Agent

Read-only leaf worker for one bounded ARIS fan-out shard. Never delegates, writes files, or renders verdicts.

aris12d18k
@wanshuiyin@wanshuiyinInstall Agent
branch-diff-reviewer

branch-diff-reviewer

Agent

Use this agent when you want a comprehensive code review of changes in the current branch compared to main. This includes…

windmill11d18k
@windmill-labs@windmill-labsInstall Agent
GLOBAL

GLOBAL

Agent

本文件包含所有 Agent 必须遵守的通用规则。各 Agent 的 SOUL.md 可覆盖此处设定。

edict6w17k
@cft0808@cft0808Install Agent
code-reviewer
Auto-invoked

code-reviewer

Agent

Expert code review specialist. Proactively reviews code for quality, security, and maintainability. Use immediately after writing…

@galaxy-dawn@galaxy-dawnInstall Agent

Questions about prompt-caching.

Which coding agents can use prompt-caching?
prompt-caching installs in Claude Code and Cursor: each loads subagents from .claude/agents, so copy the file there. Flowy's auto-invocation runs in Claude Code only.