Skip to main content

SQLite-backed context store for Axio

Project description

axio-context-sqlite

PyPI Python License: MIT

SQLite-backed persistent context store for axio.

Installation

pip install axio-context-sqlite

Usage

Open a connection with connect(), then create a SQLiteContextStore bound to a session. The caller owns the connection and is responsible for closing it.

import asyncio
import tempfile
import pathlib
from axio_context_sqlite import connect, SQLiteContextStore
from axio.messages import Message
from axio.blocks import TextBlock

async def main() -> None:
    conn = await connect(pathlib.Path(tempfile.mkdtemp()) / "chat.db")
    try:
        store = SQLiteContextStore(conn, session_id="my-session")
        await store.append(Message(role="user", content=[TextBlock(text="Hello")]))
        history = await store.get_history()
        assert len(history) == 1
    finally:
        await conn.close()

asyncio.run(main())

SQLiteContextStore implements the axio.context.ContextStore ABC and persists conversation history across process restarts. Multiple sessions can coexist in the same database file, isolated by session_id and project.

Agent integration

import asyncio
import tempfile
import pathlib
from axio.agent import Agent
from axio_context_sqlite import connect, SQLiteContextStore

async def main() -> None:
    conn = await connect(pathlib.Path(tempfile.mkdtemp()) / "chat.db")
    try:
        ctx = SQLiteContextStore(conn, session_id="main")
        agent = Agent(system="You are helpful.", tools=[], transport=transport)
        result = await agent.run("Hello!", ctx)
        assert result == "Hi!"
    finally:
        await conn.close()

asyncio.run(main())

Listing sessions

import asyncio
import tempfile
import pathlib
from axio_context_sqlite import connect, SQLiteContextStore
from axio.messages import Message
from axio.blocks import TextBlock

async def main() -> None:
    conn = await connect(pathlib.Path(tempfile.mkdtemp()) / "chat.db")
    try:
        store = SQLiteContextStore(conn, session_id="main", project="/myproject")
        await store.append(Message(role="user", content=[TextBlock(text="hi")]))
        sessions = await store.list_sessions()
        for s in sessions:
            print(s.session_id, s.preview, s.message_count)
        assert len(sessions) == 1
    finally:
        await conn.close()

asyncio.run(main())

Forking

fork() copies the current session's messages into a new session — useful for branching conversations without affecting the original:

import asyncio
import tempfile
import pathlib
from axio_context_sqlite import connect, SQLiteContextStore
from axio.messages import Message
from axio.blocks import TextBlock

async def main() -> None:
    conn = await connect(pathlib.Path(tempfile.mkdtemp()) / "chat.db")
    try:
        store = SQLiteContextStore(conn, session_id="main")
        await store.append(Message(role="user", content=[TextBlock(text="original")]))
        branch = await store.fork()
        assert branch.session_id != store.session_id
        assert len(await branch.get_history()) == 1
    finally:
        await conn.close()

asyncio.run(main())

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

axio_context_sqlite-0.6.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

axio_context_sqlite-0.6.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file axio_context_sqlite-0.6.0.tar.gz.

File metadata

  • Download URL: axio_context_sqlite-0.6.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for axio_context_sqlite-0.6.0.tar.gz
Algorithm Hash digest
SHA256 dca8296716dcb2d99d59d0aa948a54fde19f799b6a32c8efd655ab93bd16e813
MD5 0553fdf94cef49460bb8d8f94076f375
BLAKE2b-256 ca5c26f1188513561670d80109ca5f5d2eecb8553fd1fc5ad34d6ba3b1792f7a

See more details on using hashes here.

Provenance

The following attestation bundles were made for axio_context_sqlite-0.6.0.tar.gz:

Publisher: publish.yml on axio-agent/monorepo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file axio_context_sqlite-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for axio_context_sqlite-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56e6f59b98b0b6720d4499f6c8ef3f027f84592b40788c4cd58bd6cd067fbe00
MD5 36422af7e85f5660e1c465a631145ef4
BLAKE2b-256 925d93723a7d4c92c7fef7e8414aa664a70cf91d237b907bfcdc404e15420339

See more details on using hashes here.

Provenance

The following attestation bundles were made for axio_context_sqlite-0.6.0-py3-none-any.whl:

Publisher: publish.yml on axio-agent/monorepo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page