/ examples / persistence / sqlite_local.py
sqlite_local.py
 1  """
 2  SQLite Local Database
 3  
 4  Use SQLite for simple local persistence without external services.
 5  
 6  Run:
 7      python sqlite_local.py
 8  
 9  Expected output:
10      - Agent responds
11      - Data persisted to local SQLite file
12  """
13  
14  from praisonaiagents import Agent, db
15  import tempfile
16  import os
17  
18  # Create SQLite database (local file)
19  db_path = os.path.join(tempfile.gettempdir(), "my_agent.db")
20  my_db = db.SQLiteDB(path=db_path)
21  
22  print(f"Database: {db_path}")
23  
24  # Create agent
25  agent = Agent(
26      name="LocalBot",
27      instructions="You are a helpful assistant.",
28      db=my_db,
29      session_id="local-session"
30  )
31  
32  # Chat
33  response = agent.chat("Hello! What can you help me with?")
34  print(f"Response: {response}")
35  
36  # Verify
37  data = my_db.export_session("local-session")
38  print(f"\nMessages stored: {len(data.get('messages', []))}")
39  
40  my_db.close()
41  print("✅ Done")