AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

User-scoped long-term memory option for AstrBot channels

Open vivekgupta-memcode opened this issue 2 months ago • 3 comments

cc @Soulter for your thoughts on this integration.

Hi AstrBot team. I’m Vivek Gupta, Founder & CEO of MemCode (memcode.in).

AstrBot spans messaging channels, MCP, skills and a knowledge base. A user may want a small preference they approved in one session to be available in a later conversation without adding that person’s entire chat history to the knowledge base. I can contribute a plugin or MCP walkthrough for explicit save and recall, with the channel user mapped to the correct MemCode identity.

If you want long-term memory to be a standard AstrBot capability, I’d also be interested in a core provider behind your existing abstractions. The main acceptance test would be isolation across users and channels; saving should always be visible and deliberate.

Which route and extension point would your maintainers recommend? https://memcode.in/docs?product=mcp

vivekgupta-memcode avatar Sep 29 '26 06:09 vivekgupta-memcode

I reviewed the current extension points on master@b53999e. Based on the code that exists today, a plugin wrapper is the safer first integration. There is not yet a generic long-term-memory provider contract: provider_ltm_settings in astrbot/core/config/default.py currently controls group history/ICL/active-reply features, not a pluggable per-user memory backend.

Code basis and identity boundary

  • Plugin tools registered through astrbot/core/star/register/star_handler.py::register_llm_tool() receive a trusted AstrMessageEvent as their first argument.
  • AstrMessageEvent.get_platform_id() returns the unique adapter instance ID, while get_sender_id() returns the sender ID from the platform event (astrbot/core/platform/astr_message_event.py).
  • unified_msg_origin is platform_id:message_type:session_id via MessageSession (astrbot/core/platform/message_session.py). In a group/channel, that session identifies the conversation, not necessarily the individual sender, so it must not be the sole user-memory key.
  • A generic MCP tool does not receive the event automatically. astrbot/core/agent/mcp_client.py::MCPTool.call() forwards the LLM-produced kwargs directly to the MCP server. Exposing user_id as an MCP tool argument would therefore let the model choose or spoof the memory subject.
  • Plugins already have persistent namespaced storage through astrbot/core/utils/plugin_kv_store.py::PluginKVStoreMixin, which is suitable for storing opaque identity mappings and consent state.

Suggested integration

Implement two narrow plugin tools such as save_memory and recall_memory. Derive the subject inside the plugin from trusted event data; do not expose it in the tool schema:

local_identity = (event.get_platform_id(), event.get_sender_id())
subject = await get_or_create_opaque_subject(local_identity)
# call the remote API/MCP internally with subject + bounded content/query

Including platform_id prevents the same numeric/user ID on two configured adapters from colliding. Add event.get_group_id() or the session ID only for an explicit channel-scoped mode. Cross-channel identity cannot be inferred safely because platforms use unrelated IDs; it needs an explicit account-link flow (for example, short-lived one-time codes confirmed at both endpoints) and revocable mapping.

For deliberate saving, require an explicit user action or confirmation and make the saved text visible before commit. Recall should be bounded (top-k/size/timeout), return data as untrusted content, and fail open so a memory outage does not block the normal reply. The plugin should also expose list/delete/export controls, retention policy, and redact or reject secrets by default. If it calls an MCP server internally, the wrapper—not the model—must add the opaque subject and ignore any model-supplied identity field.

A core provider abstraction would make sense only after the plugin establishes stable semantics for subject resolution, consent, deletion, failure handling, and result shape. Otherwise the core interface would prematurely encode vendor-specific behavior.

Observable effect and verification

This route provides explicit save/recall without adding whole transcripts to the KB, while preserving AstrBot’s current channel isolation and keeping identity authorization outside the model. I would require these tests before considering it safe:

  1. Two users in the same group cannot recall each other’s memories.
  2. Equal sender IDs on different platform_id values remain isolated.
  3. Prompt/tool-argument injection cannot override the derived subject.
  4. Channel-scoped memories are unavailable outside that channel unless explicitly linked.
  5. Cross-channel linking requires confirmation at both endpoints and can be revoked.
  6. Save confirmation, list/delete/export, restart persistence, concurrent saves, remote timeout, and remote failure all have deterministic behavior.
  7. Recalled text is treated as untrusted data and cannot become system/tool instructions.

This does not pre-empt the maintainers’ product decision, but it is the smallest current extension point that can satisfy the stated isolation and deliberate-save acceptance criteria without changing core lifecycle or provider APIs.

LIghtJUNction avatar Sep 29 '26 07:09 LIghtJUNction

Thanks for reaching out, and for putting together such a concrete proposal. I'm commenting as a contributor, not on behalf of the maintainers, but here's my read on route and extension point.

Recommended route: plugin first, core later

I'd suggest starting with a plugin (or an MCP-based integration) rather than a core provider. AstrBot is widely self-hosted, and most users will want an external memory service to be an explicit opt-in. A plugin keeps that dependency optional, lets the integration iterate independently without committing core to a specific vendor, and gives us a real usage signal. If it turns out to be broadly useful and generalizable, that's the evidence needed to discuss a first-class, provider-agnostic memory capability behind the existing abstractions — with MemCode as one implementation rather than the default.

On the MCP path

One compatibility question: does https://mcp.memcode.in/mcp require an interactive OAuth flow? A large share of AstrBot deployments run headless, where a browser-based approval step is awkward or impossible. If that's the case, a plugin talking to your HTTP API with a server-side key may be more reliable than remote MCP for this audience.

On the acceptance test (isolation)

I fully agree that per-user and per-channel isolation is the hard requirement. From your docs, personal integrations derive identity from the configured credential, while organization integrations require context_space_id plus optional actor_id/scope. For AstrBot, the natural boundary is (platform, session/channel, user_id). It would help to be explicit about who owns that mapping — I assume the plugin — and to guarantee that two AstrBot users can never share one memory scope by accident.

Explicit, visible saves

Also strongly agree. The plugin should only write memory on a deliberate user action or an explicit, user-visible "remember this" tool call. Silent writes on every message would be a privacy and cost problem, and hard to reason about.

Things worth covering in the proposal

  • Data residency / privacy: self-hosted users need to know exactly what leaves their machine and where it goes.
  • Latency and cost: the docs mention Free-tier writes are batched for up to ~60s, which conflicts with interactive chat. What's a realistic write-to-searchable latency on a priority key?
  • Async failure modes: writes are asynchronous, so what should the agent do if a recall query runs before ingest completes? A clear "not ready yet" path matters more than pretending it succeeded.
  • Secret handling: server-side keys only, never in the WebUI or client.

Suggested next step

Package the integration as an AstrBot plugin and publish it through the official plugin marketplace at cloud.astrbot.app, together with a short design note covering identity mapping, the explicit-save UX, and the privacy/retention story. Distributing it as a marketplace plugin rather than landing it in core keeps it optional for users and lets it iterate on its own schedule — and it's the fastest way to get real feedback and usage data. I'd be happy to take a look at the design note.

mantoujun12 avatar Oct 02 '26 03:10 mantoujun12