The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
Merge upstream/main into legacy-import-skip-composio
Steven Enamakel21350ac72d10
diff --cc crates/openhuman-core/src/memory/README.mdindex f82aa4d89c,2b3a18b0ea..99e411e5bf--- a/crates/openhuman-core/src/memory/README.md+++ b/crates/openhuman-core/src/memory/README.md@@@ -1,63 -1,328 +1,328 @@@# memory- The host side of TinyMemory's agent memory lifecycle. The spec is- [`docs/specs/memory-v2.md`](../../../../docs/specs/memory-v2.md); the engine- contract, the lifecycle and the engines live in `vendor/tinymemory`- (`tinymemory-api`, `tinymemory-tools`, `tinymemory-integrations`). This- directory binds an engine, decides who is acting, calls the lifecycle around- every turn, queues the slow work, and adapts it all to OpenHuman's- controllers, tool, cron and event bus under OpenHuman policy (credentials,- consent, scrubbing, scheduling).-- Chat thread persistence is not memory: see [`threads/store`](../threads/store/README.md).-- ## Responsibilities-- - Bind the configured engine (`tinyhumans` over the host backend credential- and attribution headers, or `cortexdb` with the key stored as- `memory-cortexdb`); memory is **off** when neither is usable: the tool is- not registered, the hooks do nothing and RPCs answer `MEMORY_OFF`.- - Scrub every write (`guard`).- - Resolve the acting identity to a layout root and memory agent id (`scope`).- - Before each turn, log the user turn and recall its pack; after the commit,- log the reply; on compaction, recall what was folded away (`lifecycle`).- - Queue and run belief builds and deferred ingests (`lifecycle::jobs`).- - File synced sources into the brain (`sources`, `brain`).- - Store past chats and import a v1 store, each after explicit consent.- - Delete for good (`deletion`). This covers a deleted thread's conversations,- a disconnected connector's items, a forgotten channel's threads and a removed- source's items.- - A connector's own `source:<toolkit>` scope is erased outright when it- holds only that connection's items.- - Everything else is forgotten by `memory_ids` with an explicit- `redact_events` cascade (the engine's default keeps the events).- - Anything that cannot run now, because memory is off or the call failed,- is queued and drained on the next sign-in (`CredentialChanged`) and on- every background tick.-- ## Key files-- | File | Role |+ This is the host side of agent memory. TinyMemory (`vendor/tinymemory`) owns+ the engine contract, the turn lifecycle and the engines themselves; this+ folder binds one engine to OpenHuman, works out who is acting, calls the+ lifecycle around every agent turn, queues the slow work, and exposes it all+ through the `openhuman.memory_*` controllers, the `memory` agent tool, cron+ jobs and the event bus. OpenHuman policy (credentials, consent, scrubbing,+ scheduling, deletion) is applied here. The design spec is+ [`docs/specs/memory-v2.md`](../../../../docs/specs/memory-v2.md).++ Chat thread persistence is not memory. It lives in+ [`threads/store`](../threads/store/README.md).++ ## How it works++ ### Binding an engine++ Every memory operation starts with `engine::resolve(config)`, which turns+ the `[memory]` config into either `Binding::On(BoundEngine)` or+ `Binding::Off` with a reason. Two engines are supported:++ | Engine | Endpoint | Credential | Off when |+ | --- | --- | --- | --- |+ | `tinyhumans` | `[memory.engines.tinyhumans] endpoint`, else `backend::base_url` | the host's backend credential, resolved per request | signed out, or no backend transport installed |+ | `cortexdb` | `[memory.engines.cortexdb] endpoint`, else CortexDB's managed API | the API key stored in the keyring as `memory-cortexdb` | no key stored |++ The core never keeps a TinyHumans credential of its own. The bearer is+ fetched from the host's credential seam (`resolve_backend_credential`) on+ every request, so a refreshed session takes effect at once and signing out+ turns memory off. The hosted engine does not go through the core's+ `BackendTransport`: [`engine.rs`](./engine.rs) hands TinyMemory's CortexDB client an+ `EngineSettings` with the endpoint, the attribution headers from+ `backend::attribution_headers` and an `EngineCredential::Dynamic(HostBearer)`,+ and TinyMemory's own HTTP client calls the backend's `/memory/*` routes. The+ `cortexdb` engine calls CortexDB directly with the stored key+ (`EngineCredential::Static`). Built engines are cached per config fingerprint (engine+ id, endpoint, credential identity, layout), so a config change, a sign-in or+ a new key rebuilds the engine on the next call without any event plumbing.++ An embedding host can install its own engine with `install_host_engine`.+ It wins over the configured one for every config in the process, so a host+ with its own store (or a test binary with an in-memory engine) runs the+ whole lifecycle without a TinyHumans session or a CortexDB key.++ Whatever engine is bound, it is wrapped in `guard::ScrubbingEngine`. Every+ text a `StoreItem` carries is scrubbed of secrets and PII under+ `security::scrub::host_policy` before the engine sees it. Wrapping the+ engine, instead of scrubbing at call sites, also covers the writes+ TinyMemory makes through its own types (`AgentMemory::pre_turn`,+ `Brain::ingest`, background ingests). The same wrapper logs one+ `[memory:timing]` debug line per engine call with the op, engine, elapsed+ time and outcome, never user content.++ When memory is off, the `memory` tool is not registered, the turn hooks do+ nothing, and the RPCs answer with the `MEMORY_OFF` error code.++ ### Who is acting++ Memory follows TinyMemory's standard layout (`tinymemory_tools::MemoryLayout`):++ ```text+ <root> shared learnings; holistic recall reads it all+ +-- source:<kind> the brain: synced documents, no agent id+ +-- agent:<memory agent> one agent's conversations, one turn per item+ ```++ A `MemoryIdentity` (in [`scope.rs`](./scope.rs)) is the acting agent definition and, for a+ team member, its team. The host scopes one around every agent turn with+ `scope::within_agent` or `scope::within`, which set a task-local.+ `MemoryIdentity::resolve` turns it into a `ResolvedIdentity` (layout root plus+ memory agent id), first match wins:++ | Rule | Memory agent id | Layout root |+ | --- | --- | --- |+ | 1. host binding | `[memory] agent_id` | `[memory] root` |+ | 2. definition pin | `[memory.agents.<definition>] agent_id` | `[memory.agents.<definition>] root` |+ | 3. team member | the definition id | `team:<team>` |+ | 4. default | the definition id, else `assistant` | the default root |++ The host binding is how a coordinating host (an embedder through+ `openhuman_embed::AgentSpec::memory`) gives each agent it runs a memory of+ its own: it derives a per-agent config with those two keys set. The+ identity is never taken from model arguments.++ Under `[memory] layout = "v3"` everything sits below the signed-in person's+ own scope root (`org:<id>`, `scope::user_root`), and every agent's chats+ share one chat node (`ws:main`, `scope::chat_node`), with the agent id kept+ on each turn. The person's actor is `user:<id>` (`scope::actor_of_root`),+ which is also the retired root still read during the move while+ `[memory] legacy_user_segment_read` is on. A signed-out session gets its+ root from a random install id minted once and recorded in+ `<workspace>/memory/local_root.json` as `user:local-<id>` ([`local_root.rs`](./local_root.rs)),+ used as `org:local-<id>`. If that file cannot be written or read, the+ session has no root and memory stays off.++ ### Around every turn++ TinyMemory's `AgentMemory` runs the lifecycle. [`lifecycle/mod.rs`](./lifecycle/mod.rs) builds one+ for an identity under the `[memory.recall]` policy, and [`lifecycle/hooks.rs`](./lifecycle/hooks.rs)+ has the three hooks the agent calls:++ ```text+ user message+ |+ v+ session host prelude ----> hooks::pre_turn+ (agent/session_host/ logs the user turn (index 2n)+ runtime_session/ recalls a TurnPack within+ memory_ingest.rs) [memory.recall] pre_turn_timeout_ms+ | optional date hint runs beside it+ v+ MemoryPackMiddleware ----> adds the pack to each model request of the+ (agent/tinyagents/ turn as an ephemeral instruction; it is+ middleware/memory_pack.rs) never written to the transcript+ |+ v+ model + tools run, turn is committed+ |+ v+ session host ------------> hooks::post_turn+ logs the reply with a tool-call summary+ (index 2n + 1); queues belief builds+ |+ v (later, when the transcript is compacted)+ memory_summarizer -------> hooks::compaction+ (agent/tinyagents/ recalls what the folded-away turns carried+ memory_summarizer.rs)+ ```++ Turn indices follow the committed transcript: the user message of the turn+ after `n` committed turns is `2n` and its reply `2n + 1`. They are stable+ across retries and restarts, which is what lets TinyMemory treat a retried+ turn as a replay. Every hook is bounded by a timeout and never fails a+ turn: an engine outage degrades memory, it does not block the agent. If the+ engine refuses the whole account (for example `INSUFFICIENT_CREDITS`), the+ pack becomes a notice saying so, so the model does not read an empty pack+ as "nothing is stored".++ A few details hang off the turn. For a message that arrived on a channel,+ `lifecycle::sender::channel_actor` records the sender as the observed actor+ (`user:+1555...` for phone-addressed channels, `user:<email>`, otherwise+ `<channel>:<sender>`). The session host records the channel/thread pairing+ in [`channels.rs`](./channels.rs) so a channel's memory can be forgotten later. With+ `[memory.recall] date_hint` on, `lifecycle::date_hint::extract` makes one+ small model call to work out which days the user means; a late or bad+ answer just leaves the pack in its normal order. The pack's citations are+ parked per thread (`tools::record_pack_citations`) and `web_chat` takes them+ for the chat's memory chips (`tools::take_turn_citations`).++ ### Background work++ `post_turn` and brain ingests return TinyMemory `BackgroundJob` values+ (belief builds, deferred ingests) instead of running them inline.+ [`lifecycle/jobs.rs`](./lifecycle/jobs.rs) queues them in `<workspace>/memory/jobs.json`,+ de-duplicates them (two builds of one scope are one build), and runs each+ once it is at least `[memory.recall] build_delay_secs` old, because a belief+ build reads facts the engine extracts from the writes and that extraction+ lags. An engine that cannot consolidate answers `Skipped`; the hosted engine+ builds on its own schedule (`Scheduled`).++ Memory registers two system cron jobs, handled by [`bus.rs`](./bus.rs):++ ```text+ CronSystemJobDue+ |+ +-- memory_sources_sync --> sources::sync_due (start due source syncs)+ |+ +-- memory_background (every 5 min)+ 1. import::resume_interrupted (v1 import the app quit mid-way)+ 2. layout_migration::tick (move legacy memory, when free)+ 3. lifecycle::jobs::run_due (belief builds, deferred ingests)+ 4. deletion::drain (deletions still owed)+ ```++ ### The brain and sources++ The brain is the set of documents every agent under a root shares, filed at+ `source:<connector>` nodes with no agent id ([`brain.rs`](./brain.rs)). A file ingested+ from the UI (`memory_brain_ingest`) goes under `files`; synced sources are+ filed by what they read. Files are converted through [`convert.rs`](./convert.rs): PDF,+ DOCX, PPTX and XLSX go through TinyMemory's `OfficeConverter` on Tokio's+ blocking pool when the `documents` feature is on, then `NativeConverter`+ handles text, markdown, HTML and code. Every ingest queues a belief build of+ the source's scope.++ Sources ([`sources/`](./sources/)) are the `[[memory.sources]]` registry in `config.toml`:+ a folder, a file, a web page, a GitHub repository or an RSS feed, plus how+ often to sync it (at least every 15 minutes). Sync reads through+ `tinymemory-integrations`' readers and stores each item as a `Document`+ whose `meta.source` is `{kind, id: <source id>}`, so removing a source can+ forget exactly its items. Per-item failures are logged and skipped. Runtime+ sync state (last run, status, item count) lives in+ `<workspace>/memory/sources_state.json`, not in config.++ ### Deletion++ Deleting a chat thread, forgetting a channel (one thread deletion per thread+ it owned) or removing a source with `forget_items` asks the engine to delete+ for good: matched items are forgotten by `memory_ids` with an explicit+ `redact_events` cascade (the engine's default keeps events). When memory is+ off, or the call fails, [`deletion.rs`](./deletion.rs) records a `PendingDeletion` (`Thread`+ or `Source`) in `<workspace>/memory/pending_deletions.json`. The queue is+ drained on the next stored credential (the `memory::pending_deletions`+ subscriber on `CredentialChanged`, any kind but `cleared`) and on every+ background tick, until it succeeds. `memory_erase_all` erases everything in+ scope.++ ### Consent-gated uploads++ Three flows upload data the user already has locally, and each refuses to+ start without explicit consent and resumes after a restart:++ - [`backfill.rs`](./backfill.rs) stores chats from before turns were logged, walking the+ thread store and writing the same turn items the live hooks would, tagged+ `backfill`. It stops short of the first turn live logging already stored.+ Progress is in `conversations_backfill.json`.+ - [`import.rs`](./import.rs) (with [`import_retry.rs`](./import_retry.rs)) imports a v1 store from+ `<workspace>/memory/memory.db` through `tinymemory-import`. A blocking+ reader walks the store, the async side scrubs, stores and checkpoints+ every 25 items in `import_state.json`. Transient engine failures retry+ with backoff; a stop caused by something that will not pass on its own+ (credits exhausted, signed out) waits for the user.+ - [`layout_migration/`](./layout_migration/) moves memory written before layout v3 from the legacy+ `app:tinymemory/...` tree into the per-user tree. It copies page by page,+ verifies each item by reading it back, switches reads and writes only+ after everything copyable is verified, catches up on writes made in+ between, then cleans up the legacy copies. State is in+ `layout_migration.json`. A legacy tree other accounts may share (a+ self-hosted CortexDB) moves only with the user's consent, claimed through+ a marker in the shared app directory (`claim.rs`).++ Automatic runs of the import and the migration start only when+ `billing::free_period_active` says the work costs the user nothing: always+ for a non-hosted engine, and for the hosted engine only while the backend's+ memory free period is on (`GET /memory/free-period`, cached for 60 seconds).+ Anything unknown counts as not free.++ ### The RPC surface is confined++ The `memory_*` RPCs (and the MCP memory tools that dispatch through them)+ go through [`confine.rs`](./confine.rs). It resolves the identity in scope (the agent of a+ running turn, else the config's own root identity), fills an unset `reach`+ with that identity's subtree, refuses a wider reach with `INVALID_REQUEST`,+ and places a `learn` with no namespace at the identity's learnings node.+ The agent `memory` tool applies the same confinement and overwrites any+ `reach` in the model's filter.++ ## Layout++ | Path | What it does |+ | --- | --- |+ | [`mod.rs`](./mod.rs) | Module declarations and re-exports (`memory_is_on`, `MemoryTool`, the controller aggregators, `register_memory_subscribers`). |+ | [`engine.rs`](./engine.rs) | `resolve` binds the configured engine or says why memory is off; per-fingerprint cache; host engine install; CortexDB key storage. |+ | [`guard.rs`](./guard.rs) | `ScrubbingEngine`: scrubs every write and times every engine call. |+ | [`scope.rs`](./scope.rs) | `MemoryIdentity`, `ResolvedIdentity`, resolution order, `within` / `within_agent`, layout v3 roots. |+ | [`local_root.rs`](./local_root.rs) | The persistent install-id root of a signed-out session. |+ | [`lifecycle/mod.rs`](./lifecycle/mod.rs) | Builds `AgentMemory` for an identity under the `[memory.recall]` policy. |+ | [`lifecycle/hooks.rs`](./lifecycle/hooks.rs) | `pre_turn`, `post_turn`, `compaction`; `TurnPack`, `MemoryTurn`. |+ | [`lifecycle/jobs.rs`](./lifecycle/jobs.rs) | The persisted background job queue and the `memory_background` run. |+ | [`lifecycle/views.rs`](./lifecycle/views.rs) | Policy get/set, pack preview, agents list, jobs list/run for the UI. |+ | [`lifecycle/sender.rs`](./lifecycle/sender.rs) | Maps a channel message's sender to an observed actor. |+ | [`lifecycle/date_hint.rs`](./lifecycle/date_hint.rs) | Optional model call that works out which days a turn refers to. |+ | [`ops.rs`](./ops.rs) | Engine list/get/set, recall, fetch, learn, forget, erase all, items list. |+ | [`confine.rs`](./confine.rs) | Confines the RPC surface to the acting identity's subtree. |+ | [`explore.rs`](./explore.rs) | The facet explorer behind `memory_explore` and `memory_items_get`. |+ | [`brain.rs`](./brain.rs) | Brain source mapping and the `memory_brain_*` ops. |+ | [`convert.rs`](./convert.rs) | The document converter chain used by brain ingest and file sources. |+ | [`sources/`](./sources/) | The `[[memory.sources]]` registry (`mod.rs`), sync state (`state.rs`) and sync (`sync.rs`). |+ | [`channels.rs`](./channels.rs) | Channel to thread records, for forgetting a channel. |+ | [`deletion.rs`](./deletion.rs) | Hard deletes and the pending-deletion queue with its drain. |+ | [`backfill.rs`](./backfill.rs) | Consent-gated, resumable storing of past chats. |-| [`import.rs`](./import.rs), [`import_retry.rs`](./import_retry.rs) | Consent-gated, resumable v1 import, and retrying refused items. |++| [`import.rs`](./import.rs), [`import_retry.rs`](./import_retry.rs) | Consent-gated, resumable v1 import, and retrying refused items. Skips what v1 synced from Composio connectors (`import_open.rs::open_legacy` turns on `LegacyWorkspace::skip_connector_syncs`); the connectors re-sync it. |+ | [`layout_migration/`](./layout_migration/) | Legacy tree to per-user tree migration: `job.rs` (end to end), `copy.rs`, `map.rs` (placement), `cleanup.rs`, `claim.rs`, `state.rs`, `service.rs` (RPC/tick entry points), `app_host.rs` (the real host). |+ | [`billing.rs`](./billing.rs) | Whether background rewrites are free for the user right now. |+ | [`files.rs`](./files.rs) | Owner-only (0600 / 0700 on unix) writes of the local state files. |+ | [`tools.rs`](./tools.rs) | The single `memory` agent tool and per-turn citations. |+ | [`bus.rs`](./bus.rs) | The cron subscriber and the pending-deletions subscriber. |+ | [`schemas.rs`](./schemas.rs), [`schemas/defs.rs`](./schemas/defs.rs), [`schemas/handlers.rs`](./schemas/handlers.rs) | The `openhuman.memory_*` controller schemas and thin handlers. |+ | [`types.rs`](./types.rs) | RPC request and view shapes; contract types are re-exported from `tinymemory_api`. |+ | [`error.rs`](./error.rs) | `MemoryError` and the seven stable error codes. |+ | [`status.rs`](./status.rs) | The memory row of `subsystems.status`. |+ | [`test_fixtures.rs`](./test_fixtures.rs) | Shared in-memory engines for the unit tests. |++ ## Key types and entry points++ - `engine::resolve` / `engine::is_on` (`engine.rs`): the one way to get a+ `BoundEngine`, or learn that memory is off.+ - `engine::install_host_engine` (`engine.rs`): lets an embedder or test+ supply its own `MemoryEngine`.+ - `scope::within_agent` and `scope::resolve_current` (`scope.rs`): set and+ read the acting identity around a turn.+ - `lifecycle::hooks::pre_turn`, `post_turn`, `compaction`+ (`lifecycle/hooks.rs`): what the agent harness calls.+ - `lifecycle::jobs::enqueue` and `run_due` (`lifecycle/jobs.rs`): the+ background queue.+ - `MemoryTool` and `run_action` ([`tools.rs`](./tools.rs)): the `recall | fetch | learn |+ forget` tool. `learn` stamps the item with facts the model does not choose:+ workspace, thread id, memory agent id, the learnings namespace, the tool+ call, and `source.kind = agent`.+ - `deletion::forget_thread` (`deletion.rs`): called by `threads` when a+ thread is deleted. `channels::forget_channel` is called by `channels` on+ disconnect.+ - `MemoryError` ([`error.rs`](./error.rs)): every RPC failure carries one of `MEMORY_OFF`,+ `UNSUPPORTED`, `INVALID_REQUEST`, `UNAUTHORIZED`, `INSUFFICIENT_CREDITS`,+ `UNAVAILABLE` or `ENGINE` in `data.code`. The two account-wide refusals are+ split out so a caller can tell "top up" and "try later" apart from an+ engine fault.++ ## RPC / CLI surface++ All methods are `openhuman.memory_<function>`, listed in+ `schemas/defs.rs::FUNCTIONS` and registered through `core/all.rs`.++ | Group | Functions || --- | --- |- | `engine.rs` | `resolve` binds the `[memory]` engine or says why memory is off; engines are cached per config fingerprint. |- | `guard.rs` | `ScrubbingEngine`, wrapped around every bound engine. |- | `scope.rs` | `MemoryIdentity`, `ResolvedIdentity` and their resolution order; `within_agent` / `within`. |- | `lifecycle/mod.rs` | `AgentMemory` for an identity under the `[memory.recall]` policy. |- | `lifecycle/hooks.rs` | `pre_turn`, `post_turn`, `compaction`; `TurnPack` and `MemoryTurn`. |- | `lifecycle/jobs.rs` | The persisted job queue (`<workspace>/memory/jobs.json`) and the `memory_background` run. |- | `lifecycle/views.rs` | Policy get/set, pack preview, agents list, jobs list/run. |- | `brain.rs` | Brain source mapping and the brain ops. |- | `sources/` | Source registry, state and sync (folder, file, link, github, rss). |- | `channels.rs` | Channel → thread records for forgetting a channel. |- | `deletion.rs` | Hard deletes that must reach the engine: thread forget, the pending-deletion queue (`<workspace>/memory/pending_deletions.json`) and its drain. |- | `backfill.rs` | Past chats from the thread store, resumable, with consent. |- | `import.rs` | Consent-gated, resumable v1 import. Skips what v1 synced from Composio/connectors (`skill-*` and `source:*` documents, email and `gmail:`/`slack:`/`notion:`/`linear:`/`github:`/`clickup:` chunk sources, `*-sync:*` chunk owners, `skill-*` profile facets and graph namespaces); the connectors re-sync it. |- | `tools.rs` | The single `memory` agent tool and the turn's memory citations. |- | `ops.rs`, `explore.rs` | Engine selection, recall, fetch, learn, forget, listing; the explorer. |- | `bus.rs` | The `memory_sources_sync` / `memory_background` cron subscriber; the `memory::pending_deletions` sign-in subscriber. |- | `schemas.rs`, `schemas/` | The `openhuman.memory_*` controllers. |- | `status.rs`, `error.rs`, `types.rs` | Subsystem status, error codes, shared types. |- | `*_tests.rs`, `test_fixtures.rs` | Sibling unit tests. |+ | Engine | `engines_list`, `engine_get`, `engine_set` |+ | Recall policy | `policy_get`, `policy_set`, `pack_preview` |+ | Items | `recall`, `fetch`, `learn`, `forget`, `erase_all`, `items_list`, `explore`, `items_get` |+ | Agents and jobs | `agents_list`, `jobs_list`, `jobs_run` |+ | Past chats | `conversations_backfill_status`, `conversations_backfill_start` |+ | Brain | `brain_sources`, `brain_search`, `brain_ingest`, `brain_forget` |+ | Sources | `sources_list`, `sources_add`, `sources_remove`, `sources_sync` |+ | v1 import | `import_scan`, `import_start`, `import_status`, `import_retry_failed` |+ | Layout migration | `migration_scan`, `migration_start`, `migration_status`, `migration_retry` |## Persistencediff --cc crates/openhuman-core/src/memory/import.rsindex 9d2f7f831f,bd5874eec5..47a769a83e--- a/crates/openhuman-core/src/memory/import.rs+++ b/crates/openhuman-core/src/memory/import.rs@@@ -521,9 -520,9 +521,9 @@@ async fn start_with// it once more.let resuming = !file.checkpoint.is_start() && file.state.total > 0;let scan_dir = workspace_dir.clone();- let total = tokio::task::spawn_blocking(move || {+ let total = crate::core::runtime::spawn_blocking_scoped(move || {if resuming {- LegacyWorkspace::open(&scan_dir).ok().map(|_| None)+ open_legacy(&scan_dir).ok().map(|_| None)} else {count_legacy(&scan_dir).map(|counts| Some(counts.documents + counts.conversations + counts.learnings))diff --cc crates/openhuman-core/src/memory/import_retry.rsindex 03dcdabd90,13dacd6a41..aebc958581--- a/crates/openhuman-core/src/memory/import_retry.rs+++ b/crates/openhuman-core/src/memory/import_retry.rs@@@ -112,8 -113,8 +112,8 @@@ async fn retry_run.filter(|id| !id.is_empty()).collect();let reader_dir = workspace_dir.to_path_buf();- let items = tokio::task::spawn_blocking(move || {+ let items = crate::core::runtime::spawn_blocking_scoped(move || {- let workspace = LegacyWorkspace::open(&reader_dir).map_err(|error| error.to_string())?;+ let workspace = open_legacy(&reader_dir).map_err(|error| error.to_string())?;workspace.items().filter_map(|imported| match imported {diff --cc docs/gitbooks/en/features/memory.mdindex 0000000000,2fbc49e0d8..3c0fd42912mode 000000,100644..100644--- a/docs/gitbooks/en/features/memory.md+++ b/docs/gitbooks/en/features/memory.md@@@ -1,0 -1,115 +1,115 @@@+ ---+ description: >-+ Memory: a pluggable engine that stores your documents, conversations and+ learnings, recalls what matters before every turn, and answers questions+ with citations.+ icon: brain+ ---++ # Memory++ Memory lets the agent remember you across chats: what you are working on, what you prefer, what is in your documents. It is a feature of the app, not a hidden database. You choose who stores it, see what is stored, and delete anything.++ Open it from **Connections > Memory**. It has eight tabs: Engine, Ask, Explorer, Learnings, Conversations, Brain, Background and Settings. The old `/brain` and `/settings/memory-engine` addresses redirect there.++ ## How the agent uses memory++ Memory works around every turn, and the agent does not have to ask for it.++ - **Before the model answers**, OpenHuman logs what you said and recalls a short *memory pack* for the turn, sized to a token budget. The pack holds relevant learnings (and beliefs the engine built from them), documents from your brain, this agent's earlier conversations and, briefly, other agents' conversations. The pack is added to the model request for that turn only. It is never written into the chat, so your conversation stays exactly as you had it.+ - **After the answer**, the reply is logged with a one-line result for each tool it used.+ - **When a long chat is compacted**, OpenHuman recalls what the folded-away turns covered and adds it to the summary that replaces them.+ - **In the background**, every few minutes, the engine builds beliefs from what was stored, such as "the user prefers short answers" or "deploys happen on Fridays".++ Memory chips on an answer show which stored items the pack cited. To see what a turn would get, open **Ask > Pack preview**.++ ## Engines++ An engine stores your memory and answers questions about it. There are two.++ | Engine | What it is | Needs |+ | --- | --- | --- |+ | TinyHumans | Hosted CortexDB run by TinyHumans, reached through the TinyHumans backend | You are signed in, or the host supplies a TinyHumans API key (headless and library hosts) |+ | CortexDB | Your own CortexDB, called directly (managed `api-v1.cortexdb.ai` or self-hosted) | A CortexDB API key (kept in the OS keychain), and an endpoint if it is not the managed one |++ With either engine your memory items live in CortexDB, not on your computer. OpenHuman keeps only bookkeeping locally, such as queued jobs and sync progress. See [Where your memory is stored](privacy-and-security.md#where-your-memory-is-stored).++ Pick an engine on the **Engine** tab. If you are signed out and have neither a CortexDB key nor a host-supplied TinyHumans API key, memory is off. The agent has no memory tool, nothing is stored, and the Memory page tells you why.++ ## What the engine does++ - **Recall** answers a question in plain language and cites the stored items it used.+ - **Fetch** is a raw search over stored items with metadata filters (folder, repo, thread, source, time window). Both engines support hybrid search only.+ - **Store** takes three kinds of items: documents, conversations and learnings.++ ## What gets stored++ ### The brain: documents++ The **Brain** tab holds documents that every agent shares, filed by source type: `pdf`, `markdown`, `notion`, `github`, `web`, and one per other source (`gmail`, `docx` and so on). It shows how many documents each source holds. You can search them, add one (pasted text or a file from your computer), and forget a whole source.++ Below that, synced sources keep the brain up to date. A source is one of:++ | Kind | Target | Filed under |+ | --- | --- | --- |+ | `folder` | A folder on your computer | `pdf`, `web` (HTML) or `markdown`, by file type |+ | `file` | A single file | Same as a folder |+ | `link` | A web page | `web` |+ | `github` | A repository (`owner/repo`) | `github` |+ | `rss` | A feed URL | `web` |++ Sources sync when you press sync and on a schedule you set for each source. An unchanged file that syncs again is not stored twice. Removing a source can also forget the items it produced.++ ### Conversations++ Every turn is logged as it happens: your message before the model runs, and the reply after. Each agent's turns are kept apart. Tool calls are stored by name and id with a one-line result, never their arguments. You can switch turn logging off on the **Conversations** tab, which also lists each agent's stored turns.++ ### Learnings++ A learning is one lasting statement: a preference, fact, procedure or correction. The agent saves them with its `memory` tool (the `learn` action), and you can add or delete them on the **Learnings** tab. Beliefs the engine built are listed there too, marked "Built belief".++ Everything is scrubbed for secrets and personal identifiers before it leaves your machine.++ ### Past conversations++ Chats from before turn logging are not in memory until you sync them. The **Conversations** tab shows how many chats and turns are still unsynced. **Sync past conversations** uploads them after you confirm, in the same form as new turns and without tool arguments. You can close the page while it runs, and syncing again later sends only what is new.++ ## Exploring what memory holds++ The **Explorer** tab shows everything your memory holds, grouped by one property at a time: type, memory node, source, workspace, folder, file, language, repository, link, thread, agent, tool or tag. Each value shows how many items carry it. Click a value to narrow to those items, then group by another property. The breadcrumb at the top takes you back up. The items at each step are listed below. **Open** shows one in full with all its details and a **Forget** button.++ On a very large memory, the counts may cover only the items scanned so far. The tab says so when that happens.++ ## Each agent's own memory++ Memory is organized the way a team works:++ - **Shared by every agent:** learnings and the brain.+ - **Each agent's own:** its conversations. An agent's pack leads with its own history, and other agents' turns appear only briefly.+ - **Teams and tenants:** an agent team gets its own memory below its own root (`team:<id>`), apart from everyone else's.++ By default an agent's memory id is its definition id. In `config.toml`, `[memory.agents.<id>]` can give a definition another memory id (`agent_id`), another root (`root`), or turn off its per-turn pack (`recall = false`).++ A host that runs OpenHuman agents as part of something larger, such as an AI company or a multi-agent product, can bind each agent to its own memory. Use `[memory] agent_id` and `root` on that agent's config, or `AgentSpec::memory(MemoryBinding::new("employee-7").root("team:acme"))` through the [embedding library](../developing/embedding.md).++ ## The agent's memory tool++ The agent has one tool, `memory`, with four actions: `recall`, `fetch`, `learn` and `forget`. OpenHuman's own [MCP server](../developing/mcp-server.md) offers the same abilities to other apps as `memory.recall`, `memory.fetch`, `memory.list`, `memory.learn` and `memory.forget`.++ ## Settings and background work++ The **Settings** tab sets the shape of the pack: on or off, its size in tokens, how many learnings, documents and turns it holds, and how often beliefs are built. The **Background** tab lists queued belief builds and recent runs, with a **Run now** button. With the TinyHumans engine, beliefs are built on the service's own schedule.++ ## Importing your previous memory+-If OpenHuman finds memory from the earlier (v1) version, the Memory page offers a one-time import. It uploads that data to the engine you selected, so it starts only after you consent. It resumes if interrupted.++If OpenHuman finds memory from the earlier (v1) version, the Memory page offers a one-time import. It uploads that data to the engine you selected, so it starts only after you consent. It resumes if interrupted. Data v1 pulled in from connected apps (Gmail, Slack, Notion, Linear, GitHub, ClickUp and the like) is not imported: reconnect the app and it syncs again. Your conversations, memory sources, learnings and profile come across.++ ## What is not here++ The current memory has no memory tree, graph view, goals list, people and contacts, learning profile, `MEMORY.md` or `PROFILE.md` files, or Obsidian vault. Other memory engines (Supermemory, Mem0, Cognee, agentMemory and the local TinyCortex engine) are gone, and so is migrating between engines. The per-turn memory pack replaces the old compiled `context.md` brief.++ ## See also++ - [Memory architecture](../developing/architecture/memory.md)+ - [Pluggable engines](../developing/engines.md)+ - [Privacy and security](privacy-and-security.md)diff --cc gitbooks/features/memory.mdindex 2d44c64819,2fbc49e0d8..3c0fd42912--- a/gitbooks/features/memory.md+++ b/gitbooks/features/memory.md@@@ -100,11 -102,11 +102,11 @@@ The **Settings** tab sets the shape of## Importing your previous memory- If OpenHuman finds memory from the earlier (v1) version, the Memory page offers a one-time import. It uploads that data to the engine you selected, so it only starts after you explicitly consent. It resumes if interrupted. Data v1 pulled in from connected apps (Gmail, Slack, Notion, Linear, GitHub, ClickUp and the like) is not imported: reconnect the app and it syncs again. Your conversations, memory sources, learnings and profile come across.-If OpenHuman finds memory from the earlier (v1) version, the Memory page offers a one-time import. It uploads that data to the engine you selected, so it starts only after you consent. It resumes if interrupted.++If OpenHuman finds memory from the earlier (v1) version, the Memory page offers a one-time import. It uploads that data to the engine you selected, so it starts only after you consent. It resumes if interrupted. Data v1 pulled in from connected apps (Gmail, Slack, Notion, Linear, GitHub, ClickUp and the like) is not imported: reconnect the app and it syncs again. Your conversations, memory sources, learnings and profile come across.- ## Removed+ ## What is not here- The memory tree, graph view, goals list, people and contacts, learning profile, `MEMORY.md` and `PROFILE.md`, the Obsidian vault, the local TinyCortex engine and the Supermemory, Mem0, Cognee and agentMemory engines are gone, as is engine migration. The compiled `context.md` brief is replaced by the per-turn memory pack. See the [spec](https://github.com/tinyhumansai/openhuman/blob/main/docs/specs/memory-v2.md).+ The current memory has no memory tree, graph view, goals list, people and contacts, learning profile, `MEMORY.md` or `PROFILE.md` files, or Obsidian vault. Other memory engines (Supermemory, Mem0, Cognee, agentMemory and the local TinyCortex engine) are gone, and so is migrating between engines. The per-turn memory pack replaces the old compiled `context.md` brief.## See also