tools.librarian_tool module
Autonomous Librarian subagent dispatch tool.
The Librarian handles long-term memory management for Stargazer agents by recording notes in a git-versioned paginated notebook. It operates asynchronously with a scoped toolset.
- Follows the established Redis-backed subagent lifecycle:
_create_subagent → _call_subagent → _delete_subagent
as used by the Swarm Supervisor (scripts/swarm_supervisor.py).
- async tools.librarian_tool.dispatch_librarian(ctx, instruction, model='gemini-3-flash')[source]
Spawn the Librarian subagent to manage the notebook in the background.
The
dispatch_librariantool handler. After an authorization check it schedules the Librarian runner as a detached asyncio task and returns immediately, so the LLM gets an instant confirmation while the actual notebook analysis and writing happen out of band; results land in the system log rather than the reply.Interactions: gates on
_check_subagent_access(); launches_librarian_runner()viaasyncio.create_taskand keeps a strong reference in the module-level_active_librariansset (with a done-callback that discards it) so the loop does not GC-cancel the in-flight task. The runner itself, not this function, touches Redis, subagents, and the LLM. Dispatched by name throughtool_loaderfrom theTOOLSlist (and exercised directly bytests/test_librarian_tool.pyandtests/test_subagent_access_gating.py).- Parameters:
ctx (
ToolContext) – The tool context, supplying identity, Redis, platform, and channel.instruction (
str) – The task for the Librarian (e.g. summarize a decision).model (
str) – The LLM model the Librarian should use; defaults to_DEFAULT_LIBRARIAN_MODEL.
- Returns:
A plain confirmation string on dispatch, or the JSON error from
_check_subagent_access()when the caller is unauthorized.- Return type: