Source Code:
src/gaia/database/mixin.pyDatabaseMixin provides SQLite database access for GAIA agents. It uses Python’s
built-in sqlite3 module with zero external dependencies, making it lightweight and
fast.
Two Approaches
1. DatabaseAgent (Recommended for prototyping)
UseDatabaseAgent when you want the LLM to have direct database access:
db_query, db_insert, db_update, db_delete, db_tables, db_schema
Composing with Other Mixins
DatabaseAgent can be extended with additional mixins for more capabilities:
2. DatabaseMixin (Recommended for production)
UseDatabaseMixin when you want to expose domain-specific tools:
API Reference
Initialization
CRUD Operations
Schema & Transactions
Examples
Basic CRUD
Transactions
Use transactions when multiple operations must succeed or fail together:Schema Initialization
Best Practices
Use Parameterized Queries
Always use:param placeholders to prevent SQL injection and syntax errors:
Initialize Schema Once
Checktable_exists() before creating tables to avoid errors on restart:
Use Transactions for Related Operations
Ensure data consistency by wrapping related operations in a transaction:Close on Shutdown
Callclose_db() when the agent is done (optional but clean):
Complete Example: Notes Agent
A simple but complete agent that manages notes:Testing Your Agent
Use thetemp_db fixture for isolated tests: