Skip to main content
Use PostgreSQL for persistent memory storage. Hypertic supports both synchronous and asynchronous operations.

Installation

Install the required packages:
pip install hypertic[postgres]

Setup

Set your PostgreSQL connection string:
export DATABASE_URL=postgresql://postgres:password@localhost:5432/postgres

Usage

PostgreSQL supports both sync and async operations. Tables are created automatically on first use:
import os
from dotenv import load_dotenv
from hypertic.memory import PostgresServer
from hypertic.agents import Agent
from hypertic.models import XAI

load_dotenv()

DB_URL = os.getenv("DATABASE_URL", "postgresql://postgres:password@localhost:5432/postgres")

def main():
    # Setup (tables created automatically on first use)
    memory = PostgresServer(db_url=DB_URL, table_name="agent")

    agent = Agent(
        model=XAI(
            model="grok-3",
            max_tokens=4096,
        ),
        memory=memory
    )
    
    user_id = "user_123" 
    session_id = "session_001"
    
    # Non-streaming response
    response = agent.run("My favorite color is blue.", session_id=session_id, user_id=user_id)
    print(response.content)
    
    # Streaming response
    for event in agent.stream("what is my favorite colour?", session_id=session_id, user_id=user_id):
        if event.type == "content":
            print(event.content, end="", flush=True)

if __name__ == "__main__":
    main()

Configuration Options

  • db_url - PostgreSQL connection string (use postgresql+asyncpg:// for async)
  • table_name - Name of the table to store conversations
Tables are created automatically on first use. No manual setup required.
For more details, see the PostgreSQL documentation.