qwen-code/integrations/external-context/examples
易良 9f75842786
feat(external-context): Support configurable Mem0 providers (#9952)
* feat(external-context): Support open-source Mem0 providers

Add a mem0 provider type to the external-context integration that speaks
the open-source Mem0 REST API (POST /v2/memories/search for on-demand
recall, POST /v1/memories with infer:false for exact direct-import
writes), so self-hosted mem0 servers and managed OSS-protocol services
such as Aliyun PolarDB Mem0 can serve as the external context corpus.

The tenant identity (user_id, optional app_id) is fixed in the
administrator-managed configuration and is never supplied by the model.
A new allowInsecureHttp opt-in permits plain-HTTP endpoints such as
PolarDB Mem0 while credentials-in-URL remain rejected.

Refs #9951

* test(external-context): Cover the open-source Mem0 example config

Assert the exact example structure and that it loads through loadConfig
once the endpoint and user placeholders are substituted, so the shipped
sample cannot drift from the provider schema.

* refactor(external-context): Address review on the mem0 provider

Enforce the OSS baseUrl policy only in the adapter constructor, matching
the sibling providers, and have the rejection message point at the
allowInsecureHttp opt-in. Extract the shared write-rejection classifier
used by both Mem0 adapters, pin localhost and IPv6 loopback acceptance,
cover non-HTTP write failures mapping to unknown, clean up the example
test's temp directory, and correct the README rollout guarantees and the
OSS write-enablement guidance.

* fix(external-context): Ship the mem0 example with HTTPS defaults

The example pre-enabled allowInsecureHttp, inverting the README guidance
it is cited by. Default to an HTTPS baseUrl without the flag; the hinted
validation error and the README paragraph lead plain-HTTP whitelist
deployments to the explicit opt-in.

* test(external-context): prove shipped mem0 example constructs a provider

* refactor(external-context): address mem0 review round — merge duplicate arms, gate HTTP hint, fix README wording

* fix(external-context): Scope OSS mem0 by agent_id instead of app_id

The open-source mem0 v1.0.1 REST protocol (implemented by Aliyun PolarDB
Mem0) scopes memories by user_id / agent_id / run_id; app_id is a
hosted-platform-only field these endpoints do not accept. Rename the
optional mem0 provider field to agentId, send it as agent_id, and place it
top-level in the v2 search request (filters carry user_id) to match the
protocol.

Verified live against a PolarDB Mem0 instance: add and search accept
agent_id, infer:false is honored for direct import, and the MCP chain works
end to end.

* fix(external-context): Scope Mem0 provider to PolarDB

* feat(external-context): add versioned Mem0 presets

Replace the protocol-specific draft provider with a generic Mem0 provider backed by reviewed, immutable presets for Mem0 Platform, stock Mem0 REST, and PolarDB.

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* fix(external-context): survive an unverified Mem0 deployment build

The endpoint is operator-supplied and its build is not guaranteed - these
services are self-hosted or vendor-packaged, and the stock Mem0 REST server
carries no API version in its paths at all. A preset is therefore a claim
about what is deployed, and it can be wrong. Nothing here probes or falls
back; instead a mismatch is kept from passing silently.

Send session identity at both the request root and under `filters` for the
Mem0 server preset. `_build_filters_and_metadata` seeds the effective filters
from `filters` and then overwrites each identity key with the root value, so
one request resolves to a byte-equal scope on builds that read either
position. A filters-only search is rejected outright by builds predating that
move, which surfaced as a 500 rather than as an unscoped search.

Claim `stored` for a direct import only when the echoed `memory` matches the
submitted text and the event is not a delete. `infer: false` is what makes the
stored memory the exact text approved at the confirmation Hook, but a build
whose request model predates the field drops it silently, runs fact
extraction, and returns a rewritten memory with a valid identifier - reported
until now as `stored`.

Write provider failures to stderr with the HTTP status, which separates a
contract mismatch from an outage. The model-facing error stays opaque, and no
provider response body is ever written.

Rename the preset to `mem0-server-rest-2026-08`: "OSS" names an object storage
service in some of the clouds these deployments run in, and the preset list it
sits in already names one of those clouds.

Report which scope key and which basePath rule a configuration broke, narrow
the preset unions to the members a shipped preset uses, and cover the write
result classes, basePath rules, both scope rules in isolation, the identifier
bound, the direct-import basePath join, the Platform V3 preset write request,
and the mem0 arm of auto-recall credential scrubbing.

* feat(external-context): add a read-only Mem0 preset probe

Every other field of a `mem0` block is a fact the administrator already holds.
`preset` is not: it is a claim about which wire contract the deployment
implements, and these services are self-hosted or vendor-packaged, so the
answer is not visible from the configuration side. The configuration made that
claim mandatory without offering any way to check it.

The probe runs a candidate preset through the real adapter against the real
endpoint, so a preset that reaches the service but whose items the parser
discards is reported as the mismatch it is. It also reads the declared search
schema when one is served, and compares scope placements so a preset can be
moved to `body-and-filters` on evidence rather than on assumption.

An empty corpus is reported as inconclusive rather than as a pass: three
equally empty result sets look like agreement and are not.

Read-only. It issues search requests and one `GET /openapi.json`, never
writes, and never renders the credential.

* refactor(external-context): drop the vendor prefix from the PolarDB preset

PolarDB Mem0 is offered by more than one cloud, so an identifier scoped to one
of them reads as inapplicable to an operator running the same contract
elsewhere - the preset names a wire contract, not a vendor. The mapping's
verification evidence came from an Aliyun deployment, which the design doc now
says explicitly rather than encoding in the identifier.

Record who controls the build behind each preset, and probe placements only
where that is the operator. A vendor-operated service has one published
contract and no version skew to hedge against, so reporting that a different
request shape also works would invite a deviation with a cost and no benefit.

A skipped comparison no longer stands in for a working preset: when the
baseline search fails, the verdict is the mismatch, not "see the baseline".

* fix(external-context): restore bounded Mem0 contracts

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

* docs(external-context): ship a PolarDB example that loads as it is shipped

The console hands out a plain-HTTP address and port, while the shipped example
carries an `https://` origin with no port - the shape the endpoint should have,
not the shape it arrives in. Pasting the console address into that example
fails the URL policy, and nothing tells the operator which of the legitimate
resolutions their deployment wants.

Add a loopback example instead of loosening the policy. An `ssh -L` relay
carries the credential and the memories, loopback HTTP loads with no opt-in, and
only the user id has to be substituted, so the path from a new instance to a
working search is one relay command and one copied file. The HTTPS example is
unchanged: pre-enabling the opt-in in a shipped file would invert the posture
the surrounding section asks operators to keep.

The loopback example omits `agentId`, which the preset sends at the request
root - a placement no PolarDB document confirms, and an optional field is not
worth staking a first connection on.

* docs(external-context): clarify PolarDB setup

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>

---------

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
2026-09-17 09:22:34 +00:00
..
provider-extension-local feat(external-context): Add provider extension profile (#9068) 2026-08-16 15:50:45 +00:00
provider-extension-remote feat(external-context): Add provider extension profile (#9068) 2026-08-16 15:50:45 +00:00
auto-recall-generic-http.json feat(external-context): Add submitted-prompt auto recall (#7877) 2026-07-29 05:21:29 +00:00
auto-recall-mem0.json feat(external-context): Add submitted-prompt auto recall (#7877) 2026-07-29 05:21:29 +00:00
generic-http.json feat(integrations): add retrieval-only external context search (#7586) 2026-07-25 08:18:27 +00:00
managed-auto-recall-system-settings.json feat(external-context): Add submitted-prompt auto recall (#7877) 2026-07-29 05:21:29 +00:00
managed-auto-recall-user-settings-posix.json fix(core)!: read command hook timeout in seconds (#11615) 2026-09-12 10:44:06 +00:00
managed-auto-recall-user-settings-windows.json fix(core)!: read command hook timeout in seconds (#11615) 2026-09-12 10:44:06 +00:00
managed-mcp.json feat(integrations): add retrieval-only external context search (#7586) 2026-07-25 08:18:27 +00:00
managed-mem0-write-mcp.json feat(external-context): Add optional Mem0 memory writes (#8507) 2026-08-07 16:52:33 +00:00
managed-mem0-write-system-settings.json feat(external-context): Add optional Mem0 memory writes (#8507) 2026-08-07 16:52:33 +00:00
managed-mem0-write-user-settings-posix.json fix(core)!: read command hook timeout in seconds (#11615) 2026-09-12 10:44:06 +00:00
managed-mem0-write-user-settings-windows.json fix(core)!: read command hook timeout in seconds (#11615) 2026-09-12 10:44:06 +00:00
managed-settings.json feat(integrations): add retrieval-only external context search (#7586) 2026-07-25 08:18:27 +00:00
mem0-oss.json feat(external-context): Support configurable Mem0 providers (#9952) 2026-09-17 09:22:34 +00:00
mem0-write.json feat(external-context): Add optional Mem0 memory writes (#8507) 2026-08-07 16:52:33 +00:00
mem0.json feat(integrations): add retrieval-only external context search (#7586) 2026-07-25 08:18:27 +00:00
polardb-mem0-loopback.json feat(external-context): Support configurable Mem0 providers (#9952) 2026-09-17 09:22:34 +00:00
polardb-mem0.json feat(external-context): Support configurable Mem0 providers (#9952) 2026-09-17 09:22:34 +00:00