serverside_multiscope

command
v0.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 22, 2026 License: None detected not legal advice Imports: 0 Imported by: 0

Documentation

Overview

serverside_multiscope is a reference wiring example for server-side consumers that run the engine's Dream consolidation across many isolated scopes -- e.g. a WeChat customer-service backend where each chat group (or tenant, or account) gets its own private memory and its own Dream loop. It shows the seam the engine provides (ScopeRoot + SessionProvider + Dream().CheckAndRun) and, crucially, the part the consumer must build itself (a central scheduler with a global concurrency cap so that a few hundred groups do not fan out into a few hundred simultaneous LLM calls).

This file uses a zero-API-key mock provider and an in-memory mock session provider, so it compiles and runs the full structure without ever calling a real LLM. A real deployment swaps the two mocks for a real provider (anthropic.New / openai.New / ...) and a DB-backed SessionProvider.

What the engine gives you (neutral, per-scope primitives):

  • Config.ScopeRoot -- a single isolation anchor; memory lands under <ScopeRoot>/memory and Dream state under <ScopeRoot>/dream.{lock,state}.
  • engine.SessionProvider -- ListSince(t) returns the scope's session IDs touched since t; the engine has no idea where they come from.
  • engine.Dream().CheckAndRun(ctx) -- a per-scope hook that fires Dream consolidation asynchronously IF its internal gates are satisfied.

What the consumer must build (not in the engine, on purpose):

  • the DB query behind SessionProvider.ListSince,
  • the central scheduler: which scopes to poll, how often, and the global concurrency cap that prevents an LLM fork storm,
  • the scope_id data model, and GC of idle scopes.

Run:

cd core && go run ./examples/serverside_multiscope/

serverside_multiscope 是服务端消费者跨多个隔离 scope 跑引擎 Dream 巩固的 接线参考 -- 例如微信客服后端, 每个客服群 (或租户, 或账号) 有自己私有的 memory 和自己的 Dream loop. 它展示引擎给的 seam (ScopeRoot + SessionProvider + Dream().CheckAndRun), 以及消费者必须自建的部分 (一个带全局并发上限的 中央调度器, 防止几百个群同时 fan out 成几百个并发 LLM 调用).

本文件用零 API key 的 mock provider 加内存 mock session provider, 所以编译 和运行整个结构都不会真调 LLM. 真实部署把两个 mock 换成真 provider (anthropic.New / openai.New / ...) 加 DB-backed SessionProvider.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL