Wiki
Read and write a markdown wiki backed by Git, the local filesystem, or Notion.
Read and write to a directory of markdown files. The provider exposes two tools: query_wiki for reading, update_wiki for writing. With a Git backend, writes auto-commit and push. With a Notion backend, writes sync to a Notion database.
Start with a local wiki. Create a virtual environment, run uv pip install -U agno openai, and set OPENAI_API_KEY. Save the following as wiki_context.py, then run python wiki_context.py. It creates a demonstration page only when that file is absent.
import asyncio
from pathlib import Path
from agno.agent import Agent
from agno.context.wiki import WikiContextProvider
from agno.context.wiki.backend import FileSystemBackend
from agno.models.openai import OpenAIResponses
async def main():
root = Path(__file__).resolve().parent / "demo-wiki"
root.mkdir(exist_ok=True)
page = root / "deployment.md"
if not page.exists():
page.write_text("# Deployment\nRun tests before deploying.\n")
wiki = WikiContextProvider(
backend=FileSystemBackend(path=root),
model=OpenAIResponses(id="gpt-5.4-mini"),
write=False,
)
try:
await wiki.asetup()
agent = Agent(
model=OpenAIResponses(id="gpt-5.4"),
tools=wiki.get_tools(),
instructions=wiki.instructions(),
)
await agent.aprint_response("What is documented about deployment?")
finally:
await wiki.aclose()
if __name__ == "__main__":
asyncio.run(main())This example exposes only query_wiki. The backend fragments below replace the provider construction inside main(); configure their prerequisites before running.
Backends
With write=True, updates commit and push changes. Use Git 2.31 or later and a dedicated repository you own with an existing main branch. Set WIKI_REPO_URL to its HTTPS URL and GITHUB_TOKEN to a PAT with the required repository permissions. Use a dedicated local clone directory.
import os
from agno.context.wiki.backend import GitBackend
backend = GitBackend(
repo_url=os.environ["WIKI_REPO_URL"],
branch="main",
github_token=os.environ["GITHUB_TOKEN"],
local_path="./demo-wiki-git",
)
wiki = WikiContextProvider(backend=backend)Local directory, no Git.
from agno.context.wiki.backend import FileSystemBackend
backend = FileSystemBackend(path="./wiki")
wiki = WikiContextProvider(backend=backend)Mirrors the first data source of a Notion database into flat markdown pages. Set NOTION_DATABASE_ID and NOTION_API_KEY, and grant the integration access through the database’s Connections menu. Use a dedicated mirror directory: syncing replaces its markdown snapshot. This configuration starts read-only.
uv pip install -U notion-clientimport os
from agno.context.wiki.backend import NotionDatabaseBackend
backend = NotionDatabaseBackend(
database_id=os.environ["NOTION_DATABASE_ID"],
token=os.environ["NOTION_API_KEY"],
local_path="./demo-wiki-notion",
)
wiki = WikiContextProvider(backend=backend, write=False)
await wiki.asetup()
await wiki.sync() # Populate pages before the first query.Setup resolves database metadata but does not fetch pages. Call sync() before the first read and when you want fresh remote content. Unsupported Notion blocks become placeholders. Enabling writes can replace whole pages and drop unsupported blocks, including on otherwise unchanged mirrored pages; keep this integration read-only for an existing mixed-content database.
token falls back to the NOTION_API_KEY environment variable. NotionPageBackend (nested page trees) is planned and raises NotImplementedError today. See the Notion wiki example.
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
backend | WikiBackend | required | GitBackend, FileSystemBackend, or NotionDatabaseBackend. |
id | str | "wiki" | Tools become query_<id> and update_<id>. |
web | ContextBackend | None | Optional web backend for ingestion (fetch URL → write page). |
model | Model | None | Model for sub-agents. |
read | bool | True | Expose query_wiki. |
write | bool | True | Expose update_wiki. |
Tools Exposed
| Tool | Description |
|---|---|
query_wiki | Search pages, read content, list structure. |
update_wiki | Create pages, edit content. Auto-commits with Git backend. |
Web Ingestion
Configuration fragment for the async runner: add a web backend to let the agent fetch URLs and write them as wiki pages. This enables local file writes:
from agno.context.web import ExaBackend
wiki = WikiContextProvider(
backend=FileSystemBackend(path="./demo-wiki-web"),
web=ExaBackend(),
)
# Agent can now: "Add this article to the wiki: https://..."ExaBackend requires the exa-py package (uv pip install -U exa-py) and the EXA_API_KEY environment variable. See Web for other backends.
Lifecycle Management
Always call await wiki.asetup() before exposing query tools. Direct aquery() and updates run setup, but the current query-tool path does not. Git setup clones or validates the local repository; Notion setup resolves metadata only.
Queries do not automatically refresh remote content. Use await wiki.sync() for a fresh Git/Notion snapshot, including before the first Notion read. Updates sync before writing and call the backend’s commit hook afterward. Git commits and pushes; the filesystem hook is a no-op; Notion writes back its supported markdown subset. Put await wiki.aclose() in finally, particularly when using an MCP web backend.
Example queries
| Query | What happens |
|---|---|
| "What do we have documented about authentication?" | Searches wiki content |
| "Create a page about the new API endpoints" | Creates markdown file, commits |
| "Update the deployment guide with the new steps" | Edits file, commits |