AIR

Example: persistent (SQLite) sessions

python
import asyncio
import os
 
from air import AIR
from air.providers.groq import GroqProvider
 
 
async def main():
    air = AIR(persist="air-sessions.db")
    air.add_provider(GroqProvider(api_key=os.environ["GROQ_API_KEY"], model="llama-3.3-70b-versatile"))
 
    session = air.session("user-123")
    await session.chat("My name is Alex.")
 
    air.close()  # close the SQLite connection when done with this AIR instance
 
 
async def reopen():
    # A later process, pointed at the same file, sees the same session.
    air = AIR(persist="air-sessions.db")
    air.add_provider(GroqProvider(api_key=os.environ["GROQ_API_KEY"], model="llama-3.3-70b-versatile"))
 
    print(await air.list_sessions())  # includes "user-123"
 
    session = air.session("user-123")
    response = await session.chat("What is my name?")
    print(response.content)
 
    air.close()
 
 
if __name__ == "__main__":
    asyncio.run(main())
    asyncio.run(reopen())

Passing persist="air-sessions.db" switches session storage from the default in memory store to a local SQLite file (created if it does not already exist). No server or cloud database is involved. See ../core/sessions.md for the schema and exactly what fields are stored.