Skip to main content
Detailed Spec: spec/database-mixin The DatabaseMixin 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

Use DatabaseAgent when you want the LLM to have direct database access:
Auto-registered tools: 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:
Use DatabaseMixin 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

Check table_exists() before creating tables to avoid errors on restart:
Ensure data consistency by wrapping related operations in a transaction:

Close on Shutdown

Call close_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 the temp_db fixture for isolated tests:

Design Notes