feat(examples): SQLR-39 Python LLM agent with persistent memory#140
Merged
Conversation
…LRite The first SQLR-38 example app. A Python CLI chat agent whose long-term memory is one .sqlrite file. Each turn embeds the user input, runs hybrid recall (vector KNN via HNSW + BM25 via Phase 8 fts_match), assembles a system prompt from the recalled facts/summaries/messages, calls the LLM, and writes the new turn back. Persists across process restarts because the entire memory layer is a regular SQLRite database — the demo's whole point. Package: examples/python-agent/ (Python 3.11+, pinned to sqlrite>=0.10,<0.11). Binds only to the SDK's documented surface (sqlrite.connect, Connection, Cursor); no internals. Layers: - db.py: schema + migrations + SQL (3 tables, HNSW + FTS indexes) - sqlutil.py: safe SQL-literal inlining (the SDK doesn't bind params yet) - embeddings.py: hash / OpenAI / sentence-transformers - facts.py: regex-based (subject, predicate, object) extraction - memory.py: hybrid recall (vector + lexical + facts) with merge - chat.py: Anthropic / Echo (offline fallback so zero-key first run works) - agent.py: turn loop, prompt assembly, manual summarize_window() - cli.py: interactive REPL + /facts /recall /summarize slash commands 31 offline tests; runs end-to-end without an API key. Adds /examples landing page to sqlritedb.com (nav link + sitemap entry). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
First app under the SQLR-38 example-apps umbrella: a Python CLI chat agent whose entire long-term memory is one local
.sqlritefile. Demonstrates the agentic/AI use case end-to-end on the Python SDK.examples/python-agent/— binds only tosqlrite.connect/Connection/Cursor, pinned tosqlrite>=0.10,<0.11.fts_match/bm25_score+ a structuredfactstable for deterministic retrieval. The SQLR-39 ticket budgeted for aLIKEfallback if Phase 8 wasn't ready; Phase 8 is shipped, so the agent uses real BM25.echochat meanspython -m sqlrite_agentworks on a fresh machine with no API key. Swap to OpenAI / sentence-transformers / Anthropic via CLI flags./exampleslanding page to sqlritedb.com (nav link + sitemap entry) with a card linking to the agent's README.Layout
SQLR-38 umbrella decisions made during this PR
The umbrella ticket said to record these before starting child #1. Suggested for follow-up comments on SQLR-38:
examples/<name>/insiderust_sqlite. Discoverability, single CI lane, examples track the engine version in lockstep.sqlrite>=X.Y,<X.(Y+1)in its own manifest. This example pinssqlrite>=0.10.0,<0.11.0. CI flags breakage when the engine cuts the next minor; we bump in lockstep with the release-PR.Engine quirk worth filing as a follow-up
db.py:_migrateworks aroundCREATE TABLE IF NOT EXISTSraisingCannot create, table already existson reopen — theIF NOT EXISTSclause doesn't short-circuit when the table is present. The migration uses a try/except aroundSELECT version FROM schema_versionto detect existing schemas instead.Test plan
pytest— 31 offline tests pass (no API keys, no network)/quit, reopen,/factsand/recallsurface them across the restartcd web && npm run build—/examplesroute prerenders as static, nav + sitemap include itANTHROPIC_API_KEYset, the second-session reply should cite the recalled fact (not "I don't remember").sqlritein thesqlriteREPL and runSELECT * FROM facts;— the headline demoFollow-ups to file
/summarize.CREATE TABLE IF NOT EXISTSshort-circuit on existing tables./examplesfor real cards.🤖 Generated with Claude Code