Add interactive chat REPL with persistent sessions#18
Merged
Conversation
Introduces `openkb chat`, a multi-turn conversation REPL that stores each session under `.openkb/chats/<id>.json` so conversations survive across invocations and can be resumed by id or prefix. Built on prompt_toolkit for input editing and a bottom toolbar, and reuses the existing query agent so tool calls and streaming behavior match `openkb query`. Supports `--resume`, `--list`, `--delete`, and `--no-color`, plus in-REPL slash commands (/exit, /clear, /save, /help) where /save exports a human-readable transcript to wiki/explorations/.
Three related touch-ups to the three agent prompts: - Fix a copy-paste bug where the Q&A and lint agents were told to "Write all wiki content in X language" — the Q&A agent doesn't write wiki content, and the lint agent writes reports. Switch them to "Answer in X" and "Write the lint report in X" respectively. The compiler agent keeps its original wording since it actually writes wiki content. - Give all three agents an OpenKB identity in their opening line so the model introduces itself consistently when asked who it is. - In the Q&A search strategy, finish the thought on summaries (tell the model to follow the `full_text` path when a summary is too thin), trim step 5 so the get_image tool's "when to call" guidance lives in the tool docstring instead of the instructions template, and reword step 5 to refer to the tool by name with "the ... tool".
The Q&A agent had an odd naming wart: the helper in openkb.agent.tools was called get_page_content (no wiki_ prefix like its siblings read_wiki_file, list_wiki_files, read_wiki_image, write_wiki_file), so the @function_tool wrapper had to be named get_page_content_tool and do a lazy local import to avoid a name collision. The instructions template meanwhile referred to the tool as get_page_content — a third name — leaving three spellings for one concept. Rename the helper to get_wiki_page_content so it matches the wiki_ convention, rename the wrapper to get_page_content so the tool name the model sees matches what the instructions have always said, and drop the lazy-import workaround. Update the test imports, call sites, class name, and the one assertion in test_query that was still checking for the old wrapper name (that assertion was already broken by earlier work).
Previously openkb/__init__.py had a hand-written __version__ = "0.1.0" that drifted out of sync with pyproject.toml's version = "0.1.0.dev0", and the chat REPL had a three-level try/except fallback to paper over which string it would actually read. Make pyproject.toml the single source of truth by having __init__.py pull its __version__ from the installed package metadata via importlib.metadata, and simplify _openkb_version in chat.py to just import __version__.
Add a dedicated "Interactive chat" subsection under Usage that covers what chat is, how it differs from one-off query, the session management flags, and where to find the slash commands. Add the `openkb chat` row to the Commands table, add a chat step in the Quick start (replacing the lint step, which was already covered by its own bullet), and surface chat as its own feature bullet. While there, polish a few of the existing feature bullets: rename "Any format" to "Broad format support" to avoid overclaiming, tighten the "Auto wiki" bullet into "Compiled Wiki" with a single sentence that ends on the "kept in sync" value prop, and tag the "Query" bullet as one-off so it reads in contrast to chat.
11 tasks
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Introduces
openkb chat, a multi-turn conversation REPL for the knowledge base. Conversations are automatically persisted to.openkb/chats/<id>.jsonand can be resumed across invocations. Also bundles a handful of adjacent cleanups that were surfaced while building it.Supersedes #16 (same content, squashed into logical commits, plus one new commit sanitizing image payloads from persisted chat history).
Main feature
openkb chatCLI command with--resume [ID](latest or by id / unique prefix),--list,--delete ID, and--no-color./exitquit cleanly./exit,/clear(start a fresh session, previous is kept on disk),/save [name](export markdown transcript towiki/explorations/),/help.openkb query(dim tool-call lines flush against the preceding text, blank line separating a tool batch from the following response paragraph).<kb dir> · <model> · session <id>, then a short key hint.... N earlier turns omitted).build_query_agentso tool behavior is identical to single-shotquery.get_imagetool outputs and replaces them with a text reference (source path + "call get_image again" hint), so.openkb/chats/<id>.jsonstays small and legacy sessions are sanitized on load.Prompt / agent polish bundled in
full_textwhen a summary is too thin), move theget_image"when to call" guidance into the tool docstring, and reword step 5 to refer to the tool by name.Refactor bundled in
get_page_contentnaming: rename the helper inopenkb.agent.toolstoget_wiki_page_content(matching the*_wiki_*sibling convention), rename the agent-side wrapper fromget_page_content_tooltoget_page_contentso the tool name the model sees matches what the instructions have always said, drop the lazy-import workaround, and fix a stale test assertion.openkb.__version__from installed package metadata (importlib.metadata) sopyproject.tomlis the single source of truth for the version string.Test plan
openkb chatfrom a kb root starts a new session, header renders, prompt works/savewrites a readable transcript towiki/explorations//clearstarts a fresh session; previous shows up inopenkb chat --list/exitquit with the friendly goodbye messageopenkb chat --resumepicks up the latest session;--resume <prefix>resolves a unique prefixopenkb chat --listand--delete <id>workget_image, the saved.openkb/chats/<id>.jsonno longer contains the base64 data URLopenkb querystill works (shared agent)pytest tests/test_agent_tools.py tests/test_query.py tests/test_chat_session.pypasses