AI Agent Coding Guidelines
When AI agents generate code for KalamDB, use these rules as defaults.
Prefer subscriptions for realtime state
For live UI or state sync, use WebSocket subscriptions:
client.live(sql, callback, options)for materialized row stateclient.liveTableRows(table, callback, options)when table-name sugar is enoughclient.subscribeWithSql(sql, callback, options)only when you need raw protocol events
Use subscriptions as the primary realtime pattern instead of interval polling.
Keep live SQL in the strict supported shape: SELECT ... FROM ... WHERE ....
Do not put ORDER BY or LIMIT inside live subscription SQL; sort or cap rows after they arrive.
Do not use interval polling for realtime updates
Avoid timer-based loops such as:
setInterval(() => fetch(...), 1000)- periodic
SELECTqueries to detect row changes - fixed sleep loops to simulate streaming
These patterns add unnecessary load and increase staleness compared to server-push subscriptions.
Use topics and consumers for background workers
For worker pipelines and asynchronous processing, use topic consumers with ACK semantics:
createConsumerClient({...}).consumer({...}).run(handler)runAgent({...})/runConsumer({...})
This is preferred over polling tables on a schedule.
Reliability defaults for AI-generated code
- Keep writes idempotent.
- Track and restore progress with sequence IDs / offsets when reconnecting.
- Handle subscription
errorevents explicitly. - Use bounded retries and
onFailedpersistence in agent/consumer flows.
Recommended references
Last updated on