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.5.1.tar.gz (5.4 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.5.1-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: axio_context_sqlite-0.5.1.tar.gz
  • Upload date:
  • Size: 5.4 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.5.1.tar.gz
Algorithm Hash digest
SHA256 2bb182e5a31a02ec11fee27bfe19801283859e98c0964fc15014265d28eae293
MD5 febca617c0032e15386c893ed730d2f4
BLAKE2b-256 aa7ee64b1f7f7b911fa7752028f384f4b49f9596c72a8593b69b36a30b106aa3

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for axio_context_sqlite-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a45994b71fc4265cd5e31adb7f1d3b4b7a84a28a7ff23cc23b9fa6c2fe2f6fa5
MD5 7cd044368a2ff94283cdec4282f667b2
BLAKE2b-256 b8366a394480f668d2a9b7b460245d6f0755de476beed8e72aff65baf22986f1

See more details on using hashes here.

Provenance

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