Skip to content

API Reference parrot_tools.wiki.toolkit

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

parrot_tools.wiki.toolkit

View source

LLMWikiToolkit — agent-facing orchestrator for the LLM Wiki (FEAT-260).

Composes :class:PageIndexToolkit, :class:GraphIndexToolkit, and :class:OKFToolkit into Karpathy's 3-layer wiki architecture. Every public async method becomes an LLM-callable tool namespaced under the "wiki" prefix (e.g. wiki_ingest_source, wiki_query, etc.).

Layer mapping:

  • Raw Sources — managed by :class:SourceCollectionManager
  • Wiki Pages — stored in PageIndex trees; synced to GraphIndex nodes
  • Schema — OKF ConceptType / RelationType extensions (FEAT-260)

All async methods accept JSON-serialisable arguments and return plain dicts so that tool responses are directly usable as LLM context.

Class LLMWikiToolkit

Orchestrates PageIndex + GraphIndex + OKF into a persistent LLM wiki.

This is the agent-facing surface of FEAT-260. Construct with three toolkit dependencies and a :class:WikiConfig, then call get_tools() to obtain the list of LLM-callable tools.

Tool prefix: "wiki" — all tools are namespaced as wiki_<method_name> (e.g. wiki_ingest_source, wiki_query).

Example::

toolkit = LLMWikiToolkit(pi_toolkit, gi_toolkit, okf_toolkit, config)
tools = toolkit.get_tools()  # registers 18+ tools with the LLM
Parameter Type Default Description
pageindex_toolkit Any A PageIndexToolkit instance for tree ops.
graphindex_toolkit Any A GraphIndexToolkit instance for graph ops.
okf_toolkit Any An OKFToolkit instance for schema/lint ops.
config WikiConfig :class:WikiConfig for this wiki instance.
agent_id str 'agent' Identity stamped (as agent:<id>) onto pages the agent authors via create_page / remember.
store Optional[BaseWikiStore] None Pre-built retrieval plane to use instead of building one from config. Pass a :class:~parrot.knowledge.wiki.federation.FederatedWikiStore to give the toolkit access to federated namespaces (FEAT-450): list_wikis then enumerates them and the read methods dispatch on wiki_name. Source tracking and every write stay on the local plane.
confine_sources bool False PA-14 host switch (forced through the PA-9 hook): ingest_source accepts a URL or a file under <storage_dir>/sources only, ingest_obsidian_vault a vault under it, and export_okf writes only under <storage_dir>/exports.
**kwargs Any {} Forwarded to :class:AbstractToolkit.

Attributes:

Attribute Type Description
tool_prefix str Set to "wiki" to namespace all tools.
logger logging.Logger

Method LLMWikiToolkit.ingest_source

Ingest a raw source document into the wiki.

Processes the source via TwoStepIngester, creates wiki pages in PageIndex, syncs them to GraphIndex as WIKI_PAGE nodes, and updates the source manifest, index.md, and log.md.

ingest_source(wiki_name: str, source_path: str, source_type: Optional[str] = None) -> dict[str, Any]

Parameter Type Default Description
wiki_name str Name of the target wiki.
source_path str Absolute path to the source file.
source_type Optional[str] None Optional hint for the ingester (e.g. "markdown").

Returns: dict[str, Any] — Dict with keys: source_id, pages_created, graph_nodes_created, duration_ms, status.

Method LLMWikiToolkit.ingest_obsidian_vault

Ingest an Obsidian vault into the wiki (FEAT-392).

Phase 1 stores one PageIndex node per note (no LLM), Phase 1b imports the vault's [[wikilink]] graph into GraphIndex as pre-curated edges, and Phase 2 (opt-in) runs LLM entity/concept extraction over the ingested pages.

ingest_obsidian_vault(wiki_name: str, vault_path: str, incremental: bool = False, extract_entities: bool = False, granularity: str = 'standard') -> dict[str, Any]

Parameter Type Default Description
wiki_name str Name of the target wiki (tree name = wiki name).
vault_path str Absolute path of the Obsidian vault directory.
incremental bool False Only re-ingest added/changed files and prune deleted ones (uses the source manifest for staleness).
extract_entities bool False Also run Phase-2 LLM entity extraction.
granularity str 'standard' Entity extraction granularity — minimal, standard, fine or custom.

Returns: dict[str, Any] — Dict with the phase reports: raw_ingest, graph_bridge (nodes/edges imported) and optionally entity_extraction.

Method LLMWikiToolkit.query

Query the wiki and optionally file the answer as a new page.

Performs combined search across PageIndex and GraphIndex, collects top results as context, synthesises an answer (by concatenating snippets for now; LLM synthesis can be added when a client is available), and optionally creates a new ANSWER page.

query(wiki_name: str, question: str, file_answer: bool = False, mode: str = 'combined') -> dict[str, Any]

Parameter Type Default Description
wiki_name str Name of the wiki to query.
question str Natural-language question.
file_answer bool False When True, save the synthesised answer as a new wiki page with category ANSWER.
mode str 'combined' Search mode — "combined", "pageindex", or "graphindex".

Returns: dict[str, Any] — Dict with keys: question, answer, sources, filed_page_id.

Method LLMWikiToolkit.lint

Run the shared lint engine against a wiki namespace.

lint(wiki_name: str, fix: bool = False) -> dict[str, Any]

Parameter Type Default Description
wiki_name str Name of the wiki to lint.
fix bool False When True, apply safe auto-correctable fixes.

Returns: dict[str, Any] — A serialised :class:~parrot.knowledge.lint.models.LintReport.

Method LLMWikiToolkit.create_wiki

Create a new wiki with its directory structure.

Creates the following layout under config.storage_dir::

{storage_dir}/
├── sources/         # raw source documents
├── wiki.db          # SQLite retrieval plane (pages/edges/FTS)
├── index.md         # auto-generated content catalog
└── log.md           # append-only operation log

Page content lives in wiki.db (machine plane), not in per-category markdown directories.

create_wiki(wiki_name: str, description: Optional[str] = None) -> dict[str, Any]

Parameter Type Default Description
wiki_name str Human-readable wiki name.
description Optional[str] None Optional description written to index.md header.

Returns: dict[str, Any] — Dict with keys: status, wiki_name, storage_dir, directories_created.

Method LLMWikiToolkit.list_wikis

List every wiki this toolkit can read.

Always the local wiki; when a federated store was injected (FEAT-450), one entry per resolved namespace follows, plus one per namespace that could not be opened (status says why).

list_wikis() -> list[dict[str, Any]]

Returns: list[dict[str, Any]] — List of wiki info dicts. The local entry carries wiki_name, storage_dir and source_count; namespace entries add kind, origin, read_only and status.

Method LLMWikiToolkit.get_wiki_info

Return metadata about a specific wiki.

get_wiki_info(wiki_name: str) -> dict[str, Any]

Parameter Type Default Description
wiki_name str Wiki name to describe.

Returns: dict[str, Any] — Dict with keys: wiki_name, storage_dir, source_count, search_weights, page_categories.

Method LLMWikiToolkit.delete_wiki

Delete a wiki and all its data.

This is a destructive operation — the storage directory is NOT removed; only the manifest and bookkeeping files are cleared. Physical file removal is left to the operator.

delete_wiki(wiki_name: str) -> dict[str, Any]

Parameter Type Default Description
wiki_name str Wiki name to delete.

Returns: dict[str, Any] — Dict with keys: status, wiki_name, message.

Method LLMWikiToolkit.browse_pages

Browse wiki pages, optionally filtered by category or search query.

browse_pages(wiki_name: str, category: Optional[str] = None, search: Optional[str] = None) -> list[dict[str, Any]]

Parameter Type Default Description
wiki_name str Wiki name to browse.
category Optional[str] None Optional category value to filter by (exact match).
search Optional[str] None Optional search query — when given, results come from FTS ranking instead of the recency listing.

Returns: list[dict[str, Any]] — List of page stub dicts (no bodies — use read_page).

Method LLMWikiToolkit.read_page

Read the full content of a wiki page by its ID.

Progressive disclosure: search returns compact stubs with each page's token cost; call this only for pages worth their tokens, optionally capping the spend with max_tokens.

read_page(wiki_name: str, page_id: str, max_tokens: Optional[int] = None) -> dict[str, Any]

Parameter Type Default Description
wiki_name str Wiki name containing the page.
page_id str Stable concept_id of the page (a volatile PageIndex node_id is also accepted).
max_tokens Optional[int] None Optional ceiling on returned content tokens — the body is deterministically truncated when over.

Returns: dict[str, Any] — Dict with keys: page_id, title, category, summary, content, token_count, truncated, source_id. Returns {"error": "not_found"} when the page does not exist.

Method LLMWikiToolkit.create_page

Create a new wiki page with the given content.

Inserts the page into the PageIndex tree and creates a corresponding WIKI_PAGE node in GraphIndex.

create_page(wiki_name: str, title: str, content: str, category: str = 'concept', related_pages: Optional[list[str]] = None) -> dict[str, Any]

Parameter Type Default Description
wiki_name str Wiki name to create the page in.
title str Page title.
content str Markdown content for the page.
category str 'concept' WikiPageCategory string value.
related_pages Optional[list[str]] None Optional list of related page IDs to link.

Returns: dict[str, Any] — Dict with keys: page_id, title, category, status. status is "refused" when category is the reserved ADR category.

Method LLMWikiToolkit.update_page

Update the content of an existing wiki page.

Refreshes the WikiStore retrieval plane (row, FTS) so queries see the new content immediately, and best-effort re-inserts the markdown into the PageIndex authoring plane.

update_page(wiki_name: str, page_id: str, content: str, reason: Optional[str] = None) -> dict[str, Any]

Parameter Type Default Description
wiki_name str Wiki name containing the page.
page_id str Node ID of the page to update.
content str New Markdown content.
reason Optional[str] None Optional reason for the update (logged).

Returns: dict[str, Any] — Dict with keys: page_id, status, reason. status is "not_found" when the page does not exist in the store.

Method LLMWikiToolkit.remember

Save a fact, decision, or lesson into the wiki as durable memory.

The page id is a deterministic hash of the title/text, so remembering the same thing twice updates the existing memory instead of duplicating it. Links to related pages are recorded as asserted edges.

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

Parameter Type Default Description
wiki_name str Wiki to save the memory in.
text str The knowledge to remember (markdown allowed).
title Optional[str] None Optional short title; derived from the text when omitted.
category str 'note' One of note, decision, lesson, concept (open string).
related_pages Optional[list[str]] None Optional page ids to link the memory to.

Returns: dict[str, Any] — Dict with keys: page_id, title, category, status.

Method LLMWikiToolkit.delete_page

Delete a wiki page.

Deletes the page from the WikiStore retrieval plane (row, FTS entry, embeddings, and edges) and best-effort removes the corresponding node from the PageIndex tree.

delete_page(wiki_name: str, page_id: str) -> dict[str, Any]

Parameter Type Default Description
wiki_name str Wiki name containing the page.
page_id str Stable concept_id (or PageIndex node_id).

Returns: dict[str, Any] — Dict with keys: page_id, status, message. status is "not_found" when the page does not exist, "refused" when it is a managed ADR record.

Method LLMWikiToolkit.list_sources

List all tracked raw sources for a wiki.

list_sources(wiki_name: str) -> list[dict[str, Any]]

Parameter Type Default Description
wiki_name str Wiki name to list sources for.

Returns: list[dict[str, Any]] — List of source dicts (serialised :class:SourceManifestEntry).

Method LLMWikiToolkit.get_source_info

Get metadata for a single tracked source.

get_source_info(wiki_name: str, source_id: str) -> dict[str, Any]

Parameter Type Default Description
wiki_name str Wiki name.
source_id str Stable source identifier.

Returns: dict[str, Any] — Source manifest entry dict, or {"error": "not_found"} when the source_id is unknown.

Method LLMWikiToolkit.reingest_source

Force re-ingest of a source regardless of staleness.

reingest_source(wiki_name: str, source_id: str) -> dict[str, Any]

Parameter Type Default Description
wiki_name str Wiki name.
source_id str Stable source identifier to re-ingest.

Returns: dict[str, Any] — class:IngestReport dict, or an error dict when the source is not tracked.

Method LLMWikiToolkit.search

Search the wiki with a natural-language query.

search(wiki_name: str, query: str, mode: str = 'combined') -> list[dict[str, Any]]

Parameter Type Default Description
wiki_name str Wiki name to search.
query str Natural-language search query.
mode str 'combined' One of "combined", "pageindex", "graphindex".

Returns: list[dict[str, Any]] — List of :class:WikiSearchResult dicts sorted by score (desc).

Method LLMWikiToolkit.search_compact

Search and return token-budgeted compact stubs (preferred).

Each stub carries the page id, title, lead sentence, score, and the token cost of reading the full page — so the caller can decide what to read_page next without paying for bodies up front.

search_compact(wiki_name: str, query: str, budget_tokens: int = DEFAULT_BUDGET_TOKENS, mode: str = 'combined') -> dict[str, Any]

Parameter Type Default Description
wiki_name str Wiki name to search.
query str Natural-language search query.
budget_tokens int DEFAULT_BUDGET_TOKENS Hard token ceiling for the packed context.
mode str 'combined' "combined", "lexical", or "vector".

Returns: dict[str, Any] — Dict with keys: context (packed text), stubs, tokens_used, results_packed, total_available, truncated.

Method LLMWikiToolkit.expand

Progressively disclose a page's graph neighbourhood as stubs.

expand(wiki_name: str, page_id: str, rel: Optional[str] = None, budget_tokens: int = DEFAULT_BUDGET_TOKENS) -> dict[str, Any]

Parameter Type Default Description
wiki_name str Wiki name.
page_id str Seed page concept_id.
rel Optional[str] None Optional exact relation filter (e.g. "summarizes", "references").
budget_tokens int DEFAULT_BUDGET_TOKENS Token ceiling for the packed stubs.

Returns: dict[str, Any] — Dict with keys: page_id, context, stubs, tokens_used, total_available, truncated.

Method LLMWikiToolkit.find_related

Find pages related to a given page via graph traversal.

find_related(wiki_name: str, page_id: str, depth: int = 2) -> list[dict[str, Any]]

Parameter Type Default Description
wiki_name str Wiki name.
page_id str GraphIndex node ID of the seed page.
depth int 2 Maximum traversal depth (hops).

Returns: list[dict[str, Any]] — List of neighbour node dicts from GraphIndexToolkit.

Method LLMWikiToolkit.export_okf

Export the wiki as an OKF v0.1 markdown bundle (interchange).

The wiki's internal store is machine-first SQLite; this tool lazily projects it into Open Knowledge Format — one markdown file per page with YAML frontmatter (type from the page category, relates_to from the edges table), grouped in category directories with a root index.md.

export_okf(wiki_name: str, output_dir: str) -> dict[str, Any]

Parameter Type Default Description
wiki_name str Wiki to export.
output_dir str Destination directory for the bundle.

Returns: dict[str, Any] — Export report dict: files_written, categories, index_generated, output_dir.

Method LLMWikiToolkit.get_index

Return the current index.md content for a wiki.

get_index(wiki_name: str) -> str

Parameter Type Default Description
wiki_name str Wiki name.

Returns: str — Markdown string of the wiki's index.md, or an empty string when the file has not been generated yet.

Method LLMWikiToolkit.get_log

Return the last last_n entries from log.md.

get_log(wiki_name: str, last_n: int = 50) -> str

Parameter Type Default Description
wiki_name str Wiki name.
last_n int 50 Maximum number of trailing log lines to return.

Returns: str — String containing up to last_n log lines.

Method LLMWikiToolkit.rebuild_index

Regenerate index.md from the current wiki state.

rebuild_index(wiki_name: str) -> dict[str, Any]

Parameter Type Default Description
wiki_name str Wiki name.

Returns: dict[str, Any] — Dict with keys: status, wiki_name, index_length.

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