MotherDuck
YouTube
Building an agent-native datastore with DuckDB
Ashish from Classflow explains how to build an agent‑native datastore using DuckDB, addressing the need for agents to access raw, lossless data quickly across multiple sources. The solution centers on a single DuckDB file that stores all events in one table, with JSON payloads, extracted labels, and time stamps, enabling efficient queries and trigger‑based notifications. The architecture eliminates external dependencies, brokers, and complex pipelines, making it easy for AI engineers to deploy locally. It demonstrates how to turn real‑time monitoring data into a fast, cost‑effective knowledge base for autonomous agents.
Insights
1. Agent‑Native Datastore Design
1.1 A datastore that not only stores data but also defines data views, triggers, and subscriptions for agents
1.2 It replaces the traditional analyst‑driven cycle by allowing agents to create and consume data directly
1.3 Key requirement: lossless raw data so agents can reason without information loss
2. Event Table Schema and Labeling
2.1 All events stored in a single table with columns: id, timestamp, source, payload (JSON), labels (JSON)
2.2 Labels are extracted from payloads and can be extended by agents to create new dimensions
2.3 Using JSON for payload preserves raw data while labels enable fast filtering and correlation
3. DuckDB’s Columnar Storage for Time‑Series Reads
3.1 DuckDB stores columns separately and groups rows into blocks (~120k rows) with min/max statistics
3.2 Appending only allows DuckDB to skip older blocks during time‑window queries, making reads cheap
3.3 Hot queries avoid touching the large payload column, further improving performance
4. Trigger and Subscription Mechanism
4.1 Triggers are declarative conditions on the event table, similar to Prometheus alerts
4.2 When a trigger fires, it notifies subscribed agents via a lightweight publish/subscribe layer
4.3 This allows agents to react immediately to new data without polling
5. Operational Simplicity and Resource Management
5.1 The system runs in a single Python process with one DuckDB file, no external brokers
5.2 Memory usage is controlled by configuring DuckDB’s in‑memory cache and monitoring disk space
5.3 The ingest process pauses when disk usage exceeds a threshold to prevent crashes
6. Scalability and Future Enhancements
6.1 Current design lacks data retention; future work includes hot‑cold separation for long‑term storage
6.2 Label migration for historical data is expensive; future background jobs can add labels retroactively
6.3 The architecture supports adding new data sources, views, and triggers without downtime
1.1 A datastore that not only stores data but also defines data views, triggers, and subscriptions for agents
1.2 It replaces the traditional analyst‑driven cycle by allowing agents to create and consume data directly
1.3 Key requirement: lossless raw data so agents can reason without information loss
2. Event Table Schema and Labeling
2.1 All events stored in a single table with columns: id, timestamp, source, payload (JSON), labels (JSON)
2.2 Labels are extracted from payloads and can be extended by agents to create new dimensions
2.3 Using JSON for payload preserves raw data while labels enable fast filtering and correlation
3. DuckDB’s Columnar Storage for Time‑Series Reads
3.1 DuckDB stores columns separately and groups rows into blocks (~120k rows) with min/max statistics
3.2 Appending only allows DuckDB to skip older blocks during time‑window queries, making reads cheap
3.3 Hot queries avoid touching the large payload column, further improving performance
4. Trigger and Subscription Mechanism
4.1 Triggers are declarative conditions on the event table, similar to Prometheus alerts
4.2 When a trigger fires, it notifies subscribed agents via a lightweight publish/subscribe layer
4.3 This allows agents to react immediately to new data without polling
5. Operational Simplicity and Resource Management
5.1 The system runs in a single Python process with one DuckDB file, no external brokers
5.2 Memory usage is controlled by configuring DuckDB’s in‑memory cache and monitoring disk space
5.3 The ingest process pauses when disk usage exceeds a threshold to prevent crashes
6. Scalability and Future Enhancements
6.1 Current design lacks data retention; future work includes hot‑cold separation for long‑term storage
6.2 Label migration for historical data is expensive; future background jobs can add labels retroactively
6.3 The architecture supports adding new data sources, views, and triggers without downtime