Brain
TheBrain class orchestrates interactions with Claude’s API, handling vision input, tool use, conversation history, and intelligent query routing.
Constructor
Optional notes manager for Obsidian integration
Methods
ask()
Send a question to Claude and return the exchange.The user’s question text
Base64-encoded JPEG image from document camera
Context from previous sessions (SQLite knowledge profile)
Context from Obsidian notes
Callback invoked with each complete sentence during streaming
Routing policy controlling context inclusion and sentence caps
Contains user text, assistant response, image, searches performed, and notes change flag
decide_route()
Classify the question into a context routing policy.The user’s question to classify
Policy controlling context usage, history depth, and sentence limits
ENABLE_QUERY_ROUTER is false in config, returns a default route decision.
reload_clients()
Recreate API clients to pick up key changes fromconfig.reload().
set_notes_manager()
Update the notes manager and rebuild available tools.clear_history()
Clear all conversation history.get_history_for_display()
Reconstruct exchanges from raw history for display purposes.trim_history()
Keep only the last N user/assistant turn pairs to manage context size.limit_sentences() (static)
Hard-limit text to at mostmax_sentences sentences.
Exchange
A dataclass representing a single Q&A turn in a conversation.The user’s question
Claude’s response
Base64-encoded camera image if included
List of web searches performed during this turn
Whether notes were modified during this exchange