AI Agent Coding Guidelines
Give your coding agent the project schema, the selected docs version, and a concrete task. The Markdown documentation index and full current-docs corpus provide a starting context; the page’s Copy page menu supplies a focused guide.
Start a KalamDB project with an agent
Use this prompt with your coding agent:
Read CLI migrations before changing schema history. A ready database does not prove the application is running: inspect app output and confirm an actual live update. Keep generated artifacts and schema changes together in version control.
For agents that support external skills, the KalamDB skill package can be installed with:
Review the installed skill’s instructions and keep them aligned with the server version you run. Start with simple-live; use chat-with-ai for a fuller worker application.
Prefer subscriptions for realtime state
For live UI or state sync, use WebSocket subscriptions:
client.live(sql, callback, options)for materialized row stateclient.liveTable(table, callback, options)when table-name sugar is enoughclient.liveEvents(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)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.
Shared tables need CREATE POLICY
KalamDB shared tables enforce row-level security. Do not emit ACCESS_LEVEL table options.
After creating a table with TYPE = 'SHARED', add CREATE POLICY grants for user and service. Prefer
owner_id = CURRENT_USER or membership IN (SELECT … WHERE user_id = CURRENT_USER) over
USING (true) unless every subscriber should see every change.
See Row-Level Security Architecture and CREATE POLICY SQL.