Agent Framework history
Microsoft Agent Framework loads and stores conversation history through
a HistoryProvider. agent-framework-persql keeps that history in a
PerSQL database, so agent threads survive restarts and live in an
isolated SQLite database you can query like any other.
pip install agent-framework-persqlimport osfrom persql import PerSQLfrom agent_framework_persql import PerSQLHistoryProvider
client = PerSQL(token=os.environ["PERSQL_TOKEN"])provider = PerSQLHistoryProvider(client.database("acme/agent-state"))
agent = chat_client.as_agent(instructions="Be helpful.", context_providers=[provider])session = agent.create_session(session_id="user-42")await agent.run("hi", session=session)await agent.run("remember me?", session=session) # history persistsThe standard HistoryProvider flags work as in the built-in providers,
so the same class covers primary memory, audit-only storage
(load_messages=False), and evaluation capture. Async PerSQL databases
are awaited natively; sync databases run via asyncio.to_thread.
One database per agent
Section titled “One database per agent”Histories are keyed by session id and can share one database. For hard isolation, give each tenant its own database instead:
provider = PerSQLHistoryProvider(client.database(f"acme/tenant-{tenant_id}"))PerSQL databases are provisioned on first write and billed by usage, so per-tenant history stores cost what they’re actually used for.
Inspect history with SQL
Section titled “Inspect history with SQL”SELECT json_extract(message_data, '$.role') AS role, created_atFROM agent_framework_messagesWHERE session_id = 'user-42'ORDER BY id;