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.1.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.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: axio_context_sqlite-0.6.1.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.1.tar.gz
Algorithm Hash digest
SHA256 806dde375765206f29018f883c71e53daa41c4f222b87eac5cd8d1f8fa711138
MD5 700066a99f3dc7a54c1b348a5d0ca7e4
BLAKE2b-256 47ca70dc9ea9d2f42569e4fababda420fdb0142ab79b255d3066e898c8e11d2c

See more details on using hashes here.

Provenance

The following attestation bundles were made for axio_context_sqlite-0.6.1.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.1-py3-none-any.whl.

File metadata

File hashes

Hashes for axio_context_sqlite-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a2273183f84240ea18f7ca284d1fd14d755f0407a72367ea409db0e19e1efbf3
MD5 d3d88bc7c9a6678e3a7fd4126c9c4d00
BLAKE2b-256 33910525f4ee73cd4300df9a7361a8a0befab7f0ca5b8bf4d044e7acac4d6577

See more details on using hashes here.

Provenance

The following attestation bundles were made for axio_context_sqlite-0.6.1-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