tools.notebook_tools module
Tools for interacting with the Notebook Engine and Git version control.
These tools allow agents (primarily the Librarian subagent) to read instance and global tables of contents, retrieve specific state pages, and examine git version history for the notebook.
- async tools.notebook_tools.get_notebook_toc(ctx, instance_uid=None, page=-1, page_size=10)[source]
Read a paginated slice of one notebook instance’s table of contents.
Resolves the target instance UID (falling back to the current context’s
{platform}:{channel_id}and normalizing a bare channel id by prefixing the platform), then delegates toplugins.notebook_engine.read_toc()to fetch that page of TOC entries from the notebook store on the filesystem. This is the agent’s way of browsing what state pages exist for a channel before fetching one in full.Registered in this module’s
TOOLSlist asget_notebook_tocand invoked through the inference worker’s tool dispatch (used primarily by the Librarian subagent); no direct Python callers were found outside the test suite.- Parameters:
ctx (
ToolContext) – The tool context, used forplatform/channel_iddefaults.instance_uid (
str|None) – Explicit{platform}:{channel_id}UID, orNoneto use the current context.page (
int) – Page number to read, with-1meaning the latest page.page_size (
int) – Number of TOC entries per page.
- Returns:
The paginated table-of-contents payload returned by the notebook engine.
- Return type:
- async tools.notebook_tools.get_global_notebook_toc(ctx, page=-1, page_size=10)[source]
Read a paginated slice of the global, cross-instance table of contents.
Unlike
get_notebook_toc(), this is not scoped to one channel: it delegates straight toplugins.notebook_engine.read_global_toc()to page through TOC entries spanning every notebook instance, letting the agent survey notebook activity across the whole deployment.Registered in this module’s
TOOLSlist asget_global_notebook_tocand invoked through the inference worker’s tool dispatch (used primarily by the Librarian subagent); no direct Python callers were found outside the test suite.- Parameters:
ctx (
ToolContext) – The tool context (accepted for dispatch uniformity; not used here).page (
int) – Page number to read, with-1meaning the latest page.page_size (
int) – Number of TOC entries per page.
- Returns:
The paginated global table-of-contents payload returned by the notebook engine.
- Return type:
- async tools.notebook_tools.get_notebook_page(ctx, instance_uid=None, page_num=-1)[source]
Read the full content of one notebook state page for an instance.
Where
get_notebook_toc()lists pages, this fetches the body of a single page. It resolves the instance UID the same way (context default plus platform-prefix normalization) and delegates toplugins.notebook_engine.read_state_page()to load the page from the notebook store on the filesystem, returning a structurederrordict when no such page exists rather than raising.Registered in this module’s
TOOLSlist asget_notebook_pageand invoked through the inference worker’s tool dispatch (used primarily by the Librarian subagent); no direct Python callers were found outside the test suite.- Parameters:
ctx (
ToolContext) – The tool context, used forplatform/channel_iddefaults.instance_uid (
str|None) – Explicit{platform}:{channel_id}UID, orNoneto use the current context.page_num (
int) – Page number to read, with-1meaning the active page.
- Returns:
The page contents from the notebook engine, or a dict with an
errorkey when the page is not found.- Return type:
- async tools.notebook_tools.get_notebook_git_log(ctx, instance_uid=None, count=10)[source]
Retrieve recent git commit history for the notebook repository.
Gives the agent visibility into how the notebook has changed over time by reading the underlying git log. It grabs the shared
NotebookStateManagerviaplugins.notebook_engine.get_notebook_state_manager()and calls its_gitmanager, choosingget_instance_logswhen an instance UID is supplied (normalized with a platform prefix) orget_recent_logsfor a global view. The blocking git calls are wrapped inasyncio.to_thread()so they do not stall the event loop, and they read the notebook git repository on the filesystem.Registered in this module’s
TOOLSlist asget_notebook_git_logand invoked through the inference worker’s tool dispatch (used primarily by the Librarian subagent); no direct Python callers were found outside the test suite.- Parameters:
ctx (
ToolContext) – The tool context, used for theplatformdefault when normalizing a bare instance UID.instance_uid (
str|None) – Optional{platform}:{channel_id}UID to filter the log to one instance;Nonereturns global recent logs.count (
int) – Maximum number of commits to return.
- Returns:
One mapping per commit (hash, message, and related metadata) as produced by the notebook git manager.
- Return type:
- async tools.notebook_tools.get_notebook_git_diff(ctx, commit_hash)[source]
Retrieve the unified diff for a specific notebook commit.
Lets the agent inspect exactly what a given commit (surfaced by
get_notebook_git_log()) changed in the notebook. It obtains the sharedNotebookStateManagerviaplugins.notebook_engine.get_notebook_state_manager()and calls its_gitmanager’sget_difffor the commit, running that blocking git operation inasyncio.to_thread()so the event loop stays responsive; the diff is read from the notebook git repository on the filesystem.Registered in this module’s
TOOLSlist asget_notebook_git_diffand invoked through the inference worker’s tool dispatch (used primarily by the Librarian subagent); no direct Python callers were found outside the test suite.- Parameters:
ctx (
ToolContext) – The tool context (accepted for dispatch uniformity; not used here).commit_hash (
str) – The git commit hash to diff.
- Returns:
A mapping with the requested
commithash and the unifieddifftext.- Return type:
- async tools.notebook_tools.write_notebook_entry(ctx, entry, instance_uid=None, commit_message=None)[source]
Append a new entry to an instance’s notebook and commit it to git.
This is the only write tool in the module: it resolves the instance UID the usual way (context default plus platform-prefix normalization) and delegates to
plugins.notebook_engine.write_entry(), which appends the note to the notebook store and records a git commit (optionally with the supplied message). It therefore mutates the notebook state and the notebook git repository on the filesystem.Registered in this module’s
TOOLSlist aswrite_notebook_entryand invoked through the inference worker’s tool dispatch (used primarily by the Librarian subagent); no direct Python callers were found outside the test suite.- Parameters:
ctx (
ToolContext) – The tool context, used forplatform/channel_iddefaults.entry (
str) – The note content to append.instance_uid (
str|None) – Explicit{platform}:{channel_id}UID, orNoneto use the current context.commit_message (
str|None) – Optional custom git commit message; the engine supplies a default when omitted.
- Returns:
The result payload from the notebook engine describing the written entry and resulting commit.
- Return type:
- async tools.notebook_tools.get_instance_conversation_history(ctx, instance_uid=None, limit=50)[source]
Retrieve recent conversation history for a specific instance.
Unlike the notebook-state tools above, this reads live chat rather than saved notes: it splits the resolved instance UID into platform and channel, constructs a
message_cache.MessageCacheover the context’s Redis connection, and fetches the most recent messages from the Redis-backed message cache. It then flattens them into[role]: contentlines so the Librarian can review what was actually said before summarizing it into the notebook.Registered in this module’s
TOOLSlist asget_instance_conversation_historyand invoked through the inference worker’s tool dispatch (used primarily by the Librarian subagent); no direct Python callers were found outside the test suite.- Parameters:
ctx (
ToolContext) – The tool context, used for theplatformdefault and the Redis connection.instance_uid (
str|None) – Explicit{platform}:{channel_id}UID, orNoneto use the current context.limit (
int) – Maximum number of recent messages to retrieve.
- Returns:
A mapping with the resolved
instance_uid, a newline-joinedhistorystring of formatted messages, and theircount.- Return type: