[wrangler] Add agent_memory binding support and namespace commands#13610
[wrangler] Add agent_memory binding support and namespace commands#13610petebacondarwin wants to merge 14 commits intomainfrom
Conversation
🦋 Changeset detectedLatest 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 |
|
UnknownError: ProviderInitError |
|
@petebacondarwin Bonk workflow failed. Check the logs for details. View workflow run · To retry, trigger Bonk again. |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
penalosa
left a comment
There was a problem hiding this comment.
Initial pass. My main concern at this stage is the agentmemory/agent_memory/agent_memory_namespace naming confusion
| "ai", | ||
| "ai_search_namespace", | ||
| "ai_search", | ||
| "agent_memory_namespace", |
There was a problem hiding this comment.
Why the _namespace suffix?
There was a problem hiding this comment.
@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": { |
There was a problem hiding this comment.
This seems to be called agent_memory in some places, and agent_memory_namespace in others
There was a problem hiding this comment.
I think we probably should be using agent_memory rather than agent_memory_namespace...
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
agentmemory/agent_memory/agent_memory_namespace
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
It's a bit wordy as a command name—wrangler agents memory?
There was a problem hiding this comment.
"Agent Memory" is the product name
There was a problem hiding this comment.
nit: Can you use the Cloudflare SDK instead?
There was a problem hiding this comment.
I don't think this has been generated yet.
There was a problem hiding this comment.
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.
| logger.log(`✅ Created Agent Memory namespace`); | ||
| logger.log(` ID: ${result.id}`); | ||
| logger.log(` Name: ${result.name}`); |
There was a problem hiding this comment.
This output looks a bit odd, and there's no --json support
There was a problem hiding this comment.
Do we need JSON support here? What is odd about the output?
There was a problem hiding this comment.
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.
|
Looks this doesn't include the new OAuth permissions. |
|
Not completely sure how "remote" bindings are implemented, but they don't seem to work. |
|
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). |
79346fe to
230fe18
Compare
|
✅ All changesets look good Reviewed changesets:
Validation results:
|
|
Marking as draft while @oliy works through some backend updates (e.g. around the agentmemory/agent-memory/agent_memory naming etc) |
…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.
6ffd5a4 to
181d5f5
Compare
Add support for Cloudflare's Agent Memory service in Wrangler and Miniflare.
This PR introduces:
agent_memorybinding (wrangler + miniflare, minor)wrangler.json:{ "agent_memory": [ { "binding": "MY_MEMORY", "namespace": "my-namespace" } ] }wrangler dev(no local simulation), wired throughstartDevWorker, a Miniflare plugin, and the deploy paths.wrangler deployif the namespace doesn't exist.wrangler typesemitsagent_memory_namespacetyped bindings.wrangler agent-memory namespacecommands (wrangler, minor)A picture of a cute animal (not mandatory, but encouraged)