The BaseDb class is the abstract base for all database implementations in Agno. It defines the interface for storing sessions, memories, knowledge, metrics, and more.
Constructor
session_table
str
default: "agno_sessions"
Name of the table for storing sessions.
memory_table
str
default: "agno_memories"
Name of the table for storing user memories.
knowledge_table
str
default: "agno_knowledge"
Name of the table for storing knowledge content.
metrics_table
str
default: "agno_metrics"
Name of the table for storing metrics.
eval_table
str
default: "agno_eval_runs"
Name of the table for storing evaluation runs.
Name of the table for storing traces.
components_table
str
default: "agno_components"
Name of the table for storing component definitions.
learnings_table
str
default: "agno_learnings"
Name of the table for storing learning records.
approvals_table
str
default: "agno_approvals"
Name of the table for storing approval records.
Unique identifier for the database instance.
Session Methods
get_session()
Retrieve a session from the database.
session = db.get_session(
session_id = "abc123" ,
session_type = SessionType. AGENT ,
user_id = "user_1"
)
upsert_session()
Create or update a session.
db.upsert_session(session)
delete_session()
Delete a session.
db.delete_session( session_id = "abc123" , user_id = "user_1" )
get_sessions()
Query sessions with filters.
sessions = db.get_sessions(
session_type = SessionType. AGENT ,
user_id = "user_1" ,
limit = 10
)
Memory Methods
get_user_memories()
Retrieve user memories.
memories = db.get_user_memories(
user_id = "user_1" ,
limit = 10
)
upsert_user_memory()
Create or update a memory.
db.upsert_user_memory(memory)
delete_user_memory()
Delete a memory.
db.delete_user_memory( memory_id = "mem_123" , user_id = "user_1" )
clear_memories()
Clear all memories.
Knowledge Methods
get_knowledge_content()
Get a knowledge row.
row = db.get_knowledge_content( id = "doc_123" )
upsert_knowledge_content()
Create or update knowledge content.
db.upsert_knowledge_content(knowledge_row)
delete_knowledge_content()
Delete knowledge content.
db.delete_knowledge_content( id = "doc_123" )
Component Methods
upsert_component()
Create or update a component (agent/team/workflow).
db.upsert_component(
component_id = "my_agent" ,
component_type = ComponentType. AGENT ,
name = "My Agent"
)
get_config()
Get component configuration.
config = db.get_config(
component_id = "my_agent" ,
label = "production"
)
Trace Methods
upsert_trace()
Store a trace record.
get_traces()
Query traces with filters.
traces = db.get_traces(
agent_id = "my_agent" ,
limit = 20
)
Example Usage
SQLite
PostgreSQL
With Agent
from agno.db.sqlite import SQLiteDb
db = SQLiteDb( db_file = "agent.db" )