Skip to content

[wrangler] Add agent_memory binding support and namespace commands#13610

Draft
petebacondarwin wants to merge 14 commits intomainfrom
pbd/agent-memory
Draft

[wrangler] Add agent_memory binding support and namespace commands#13610
petebacondarwin wants to merge 14 commits intomainfrom
pbd/agent-memory

Conversation

@petebacondarwin
Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin commented Apr 20, 2026

Add support for Cloudflare's Agent Memory service in Wrangler and Miniflare.

This PR introduces:

  1. agent_memory binding (wrangler + miniflare, minor)

    • New config section in wrangler.json:
      {
        "agent_memory": [
          { "binding": "MY_MEMORY", "namespace": "my-namespace" }
        ]
      }
    • Remote-only binding — always proxied to the Cloudflare API during wrangler dev (no local simulation), wired through startDevWorker, a Miniflare plugin, and the deploy paths.
    • Automatic namespace provisioning during wrangler deploy if the namespace doesn't exist.
    • Type generation via wrangler types emits agent_memory_namespace typed bindings.
    • Config validation, print-bindings output, config-diffs, and worker-upload-form integration.
  2. wrangler agent-memory namespace commands (wrangler, minor)

    wrangler agent-memory namespace create <namespace>
    wrangler agent-memory namespace list [--json]
    wrangler agent-memory namespace get <namespace_name> [--json]
    wrangler agent-memory namespace delete <namespace_name> [--force]

  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation

A picture of a cute animal (not mandatory, but encouraged)

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 20, 2026

🦋 Changeset detected

Latest commit: 181d5f5

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Apr 20, 2026
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 20, 2026

UnknownError: ProviderInitError

github run

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Apr 20, 2026

@petebacondarwin Bonk workflow failed. Check the logs for details.

View workflow run · To retry, trigger Bonk again.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 20, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@13610

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@13610

miniflare

npm i https://pkg.pr.new/miniflare@13610

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@13610

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@13610

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@13610

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@13610

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@13610

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@13610

wrangler

npm i https://pkg.pr.new/wrangler@13610

commit: 181d5f5

@petebacondarwin petebacondarwin marked this pull request as ready for review April 20, 2026 17:07
@workers-devprod workers-devprod requested review from a team and ascorbic and removed request for a team April 20, 2026 17:08
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Apr 20, 2026

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • packages/miniflare/src/plugins/agent-memory/index.ts: [@cloudflare/wrangler]
  • packages/miniflare/src/plugins/index.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/config/config.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/config/environment.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/config/validation.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/map-worker-metadata-bindings.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/types.ts: [@cloudflare/wrangler]
  • packages/workers-utils/src/worker.ts: [@cloudflare/wrangler]
  • packages/workers-utils/tests/config/validation/normalize-and-validate-config.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/e2e/agent-memory.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/e2e/remote-binding/miniflare-remote-resources.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/e2e/remote-binding/workers/agent-memory.js: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/agent-memory.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/create-worker-upload-form/bindings.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/deploy/bindings.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/index.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/print-bindings.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/provision.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/type-generation.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/tests/whoami.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/agent-memory/client.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/agent-memory/create.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/agent-memory/delete.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/agent-memory/get.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/agent-memory/index.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/agent-memory/list.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/agent-memory/provisioning.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/api/startDevWorker/utils.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/core/teams.d.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/deploy/check-remote-secrets-override.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/deploy/config-diffs.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/deployment-bundle/bindings.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/deployment-bundle/create-worker-upload-form.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/dev/miniflare/index.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/index.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/type-generation/index.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/user/user.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/utils/print-bindings.ts: [@cloudflare/wrangler]
  • tools/e2e/common.ts: [@cloudflare/wrangler]
  • tools/e2e/e2eCleanup.ts: [@cloudflare/wrangler]

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

Copy link
Copy Markdown
Contributor

@penalosa penalosa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial pass. My main concern at this stage is the agentmemory/agent_memory/agent_memory_namespace naming confusion

Comment thread packages/workers-utils/src/config/environment.ts
"ai",
"ai_search_namespace",
"ai_search",
"agent_memory_namespace",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the _namespace suffix?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@oliy - is this because the previous unsafe binding was named agent_memory_namespace, even though the new public binding is just agent_memory?

Or is this just an oversight that needs fixing here?

},
];
break;
case "agent_memory_namespace": {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be called agent_memory in some places, and agent_memory_namespace in others

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we probably should be using agent_memory rather than agent_memory_namespace...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this really need an E2E test?

// Pretend all Agent Memory namespaces exist for the same reason.
msw.use(
http.get(
"*/accounts/:accountId/agentmemory/namespaces/:namespaceName",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agentmemory/agent_memory/agent_memory_namespace

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the API is fairly locked down now, or could it be updated to agent-memory to make it more consisten with the product name @oliy ?

wrangler whoami 🕵️ Retrieve your user information

COMPUTE & AI
wrangler agent-memory 🧠 Manage Agent Memory namespaces [open beta]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit wordy as a command name—wrangler agents memory?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Agent Memory" is the product name

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Can you use the Cloudflare SDK instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this has been generated yet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Cloudflare TypeScript SDK doesn't yet expose the /agentmemory endpoints — I checked against the version pinned in this monorepo. Same situation as src/ai-search/client.ts, which also uses fetchResult directly. Added a TODO in 79346fe to migrate once the SDK covers these endpoints.

Comment thread packages/wrangler/src/agent-memory/create.ts
Comment on lines +22 to +24
logger.log(`✅ Created Agent Memory namespace`);
logger.log(` ID: ${result.id}`);
logger.log(` Name: ${result.name}`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This output looks a bit odd, and there's no --json support

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need JSON support here? What is odd about the output?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 79346fe — added --json support and switched the text output to use logger.table, matching the list/get commands. New output looks like:

> ✅ Created Agent Memory namespace "my-namespace"
┌──────────────────────────────┬──────────────┬────────────────┬──────────────────────┐
│         namespace_id         │     name     │   account_id   │     created_at       │
├──────────────────────────────┼──────────────┼────────────────┼──────────────────────┤
│ 01HNXYZ1234567890ABCDEFGH    │ my-namespace │ some-account-id│ 2024-01-01T00:00:00Z │
└──────────────────────────────┴──────────────┴────────────────┴──────────────────────┘

--json returns the raw namespace object. Let me know if the new format still reads off.

Comment thread packages/wrangler/src/agent-memory/provisioning.ts
@oliy
Copy link
Copy Markdown
Contributor

oliy commented Apr 21, 2026

Looks this doesn't include the new OAuth permissions.

@oliy
Copy link
Copy Markdown
Contributor

oliy commented Apr 21, 2026

Not completely sure how "remote" bindings are implemented, but they don't seem to work.

@oliy
Copy link
Copy Markdown
Contributor

oliy commented Apr 21, 2026

As for naming, you make good points on the consistency. Since we are not constrained by agent week deadlines, we are going to make changes to center on using "agent-memory" in the naming. (and "agent_memory", as necessary).
Unfortunately, this means numerous changes in other systems (EWC, API Gateway, etc.)

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 22, 2026

✅ All changesets look good

Reviewed changesets:

  • .changeset/agent-memory-binding-support.md
  • .changeset/agent-memory-namespace-commands.md

Validation results:

  • ✅ Version Type: Both correctly use minor for new features
  • ✅ Changelog Quality: Both have meaningful descriptions with usage examples
  • ✅ Markdown Headers: No h1/h2/h3 headers found
  • ✅ Analytics: N/A (user-visible feature additions)
  • ✅ Dependabot: N/A (not dependency updates)

@petebacondarwin
Copy link
Copy Markdown
Contributor Author

Marking as draft while @oliy works through some backend updates (e.g. around the agentmemory/agent-memory/agent_memory naming etc)

@petebacondarwin petebacondarwin marked this pull request as draft April 24, 2026 13:37
petebacondarwin and others added 7 commits April 25, 2026 07:28
…te commands

The Agent Memory API now uses namespace names in URL paths instead of IDs.
Update get and delete commands to accept <namespace_name> instead of
<namespace_id>, and fix create description to reflect the actual validation
constraints (max 32 chars, alphanumeric with embedded hyphens).
…_memory binding

Add agent_memory to wrangler types generation so running `wrangler types`
produces typed AgentMemory bindings. Fix config-diffs to strip the remote
field when comparing local vs remote configs. Fix print-bindings to
correctly display inherited agent_memory bindings.

Add comprehensive tests: config validation (7 tests), provisioning
(3 tests), deploy binding payload (1 test), and update type generation
snapshots.
- Reformat changeset example JSONC (tabs + trailing commas, per oxfmt).
- Mark Plugin and RemoteProxyConnectionString as type-only imports in
  the miniflare agent-memory plugin to satisfy consistent-type-imports.
- Update provision tests to use agent_memory_namespace (the actual
  metadata binding type) instead of agent_memory.
The upload form emits type "agent_memory_namespace" for agent memory
bindings, but the deploy/bindings test was asserting on
"agent_memory", causing the toEqual(arrayContaining(...)) check to
fail.
- Rename emitted ambient type AgentMemory to AgentMemoryNamespace to
  match the type declared in workerd (cloudflare/workerd#6628) and
  follow the AiSearchNamespace precedent.
- Consolidate the AgentMemoryNamespace interface by importing it from
  agent-memory/client.ts in agent-memory/provisioning.ts instead of
  redeclaring a narrower shape there.
- Split agent-memory/client.ts into two layers: low-level helpers that
  take (complianceConfig, accountId, ...) and high-level wrappers that
  resolve auth via requireAuth. agent-memory/provisioning.ts now
  delegates to the low-level helpers, removing the duplicated fetch
  calls.
- Reorder the agent_memory block in deploy/config-diffs.ts so it sits
  alongside the related ai_search blocks.
Matches the dominant pattern in the wrangler codebase
(ai-search.ts, pipelines/client.ts, vectorize/client.ts, etc.);
fetchResult<null> was just a style nit. No behavior change.
- wrangler agent-memory namespace create: add --json flag and switch
  the text output to logger.table, matching the list/get commands.
- Add TODO on agent-memory/client.ts pointing at the migration to the
  Cloudflare TypeScript SDK once it exposes /agentmemory endpoints
  (same situation as ai-search).
Catch the predictable client-side API errors from the agent-memory
namespace commands and rethrow them as UserError with friendly
messages so they do not get reported to Sentry:

- get/delete on an unknown namespace (404) now explains the namespace
  was not found and suggests running `namespace list`.
- create with an invalid or duplicate name (400/409/422) now surfaces
  the server's validation message wrapped in a UserError.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: In Review

Development

Successfully merging this pull request may close these issues.

4 participants