Skip to content

API Reference parrot.memory.dream.brain

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.memory.dream.brain

View source

BrainStore — lean wiki writer/reader for the dream cycle (FEAT-390).

Wraps the SQLite wiki retrieval plane (:func:create_wiki_store) directly, WITHOUT constructing the full :class:LLMWikiToolkit (which requires PageIndex/GraphIndex/OKF toolkit dependencies). BrainStore.remember() reproduces LLMWikiToolkit.remember() semantics byte-for-byte so the brain wiki.db remains fully interoperable with LLMWikiToolkit and the wikitoolkit CLI.

Class BrainStore

Lean wiki writer/reader over create_wiki_store (no PI/GI/OKF deps).

Parameter Type Default Description
storage_dir Path Directory in which the SQLite wiki store lives.
wiki_name str Wiki name recorded by the backend.
asserted_by str 'agent' Attribution stamped onto authored/memory pages.

Attributes:

Attribute Type Description
storage_dir Directory holding the wiki's wiki.db file.
wiki_name Name recorded by the underlying store backend.
asserted_by Identity stamped onto pages written via remember() (e.g. "agent:<id>").

Method BrainStore.remember

Save distilled knowledge into the wiki as durable memory.

Replicates LLMWikiToolkit.remember() (toolkit.py:660-725) exactly: the page id is a deterministic hash of the title/category, so remembering the same thing twice updates the existing page instead of duplicating it.

remember(text: str, title: str | None = None, category: str = 'note', related_pages: list[str] | None = None) -> dict[str, Any]

Parameter Type Default Description
text str The knowledge to remember (markdown allowed).
title str | None None Optional short title; derived from the text's first line (truncated to 80 chars) when omitted.
category str 'note' One of note | decision | lesson | concept (open string).
related_pages list[str] | None None Optional page ids to link the memory to via references/asserted edges.

Returns: dict[str, Any] — Dict with keys: page_id, title, category, status ("created" or "updated").

Method BrainStore.search

Search the brain wiki and pack results under a token budget.

Degrades gracefully: any exception or empty result set returns "" — never raises.

search(query: str, top_k: int = 5, max_tokens: int = 600) -> str

Parameter Type Default Description
query str Free-form natural-language query.
top_k int 5 Maximum number of results to consider.
max_tokens int 600 Token budget for the packed text.

Returns: str — Packed, budgeted text block, or "" on no results / error.

Method BrainStore.list_pages

Return page stubs without bodies, or [] when the read fails.

list_pages(category: str | None = None, limit: int = 100) -> list[dict[str, Any]]

Parameter Type Default Description
category str | None None
limit int 100

Returns: list[dict[str, Any]]

Method BrainStore.get_page

Return one page with its body, or None when absent or unreadable.

get_page(page_id: str) -> dict[str, Any] | None

Parameter Type Default Description
page_id str

Returns: dict[str, Any] | None

Method BrainStore.delete_pages

Delete the given pages and return the ids actually deleted, in input order.

delete_pages(page_ids: Sequence[str]) -> list[str]

Parameter Type Default Description
page_ids Sequence[str]

Returns: list[str]

Method BrainStore.remove_pages

Delete pages, telling a page that is gone apart from one that could not be deleted.

Unlike :meth:delete_pages, an absent page counts as handled — the goal is that it no longer exists — and a failed deletion is reported instead of being only logged, so a caller can retry.

remove_pages(page_ids: Sequence[str]) -> tuple[list[str], list[str]]

Parameter Type Default Description
page_ids Sequence[str] Page ids to delete. Duplicates are handled once.

Returns: tuple[list[str], list[str]] — (handled, failed): pages deleted or already absent, and pages that are still present because their deletion raised.

Method BrainStore.copy_page_to

Copy a page into another BrainStore, preserving attribution.

copy_page_to(page_id: str, other: BrainStore) -> str

Parameter Type Default Description
page_id str The page's concept_id in this store.
other BrainStore Destination BrainStore (e.g. the org wiki).

Returns: str — The page id in the destination store (same as page_id when found; the original page_id is returned unchanged even if the source page could not be located, with a WARNING logged).

Alias WikiPageRecord

Re-exported from parrot.knowledge.wiki.store.WikiPageRecord.

Alias create_wiki_store

Re-exported from parrot.knowledge.wiki.create_wiki_store.

Alias estimate_tokens

Re-exported from parrot.knowledge.wiki.store.estimate_tokens.

Alias pack_results

Re-exported from parrot.knowledge.wiki.pack_results.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally