Skip to Content
Summarizer Agent

Summarizer Agent

The worker-only example in the set — no browser UI, just a topic consumer that enriches database rows.

Source: examples/summarizer-agent/

There is no model dependency. The summarizer is deterministic so the example is easy to read and the test is stable.

What it does

  1. A row lands in blog.blogs
  2. KalamDB routes the change into blog.summarizer
  3. The worker consumes the topic with runConsumer()
  4. The worker writes summary back into the same row
  5. Failures are stored in blog.summary_failures

Use change.data as the blog row inside onChange(). Because blog.blogs is a SHARED table, change.user is undefined in this example.

Prerequisites

  • Node.js 18+
  • Kalam CLI

Quick start

BASH
cd examples/summarizer-agentnpm installkalam dev

kalam dev starts the local server, applies kalam/schema.sql, keeps kalam/migrations/ current, and runs the worker with npm run start.

Schema and topic route

SQL
CREATE NAMESPACE IF NOT EXISTS blog; CREATE SHARED TABLE IF NOT EXISTS blog.blogs (    blog_id BIGINT PRIMARY KEY DEFAULT SNOWFLAKE_ID(),    content TEXT NOT NULL,    summary TEXT,    created TIMESTAMP NOT NULL DEFAULT NOW(),    updated TIMESTAMP NOT NULL DEFAULT NOW()); CREATE SHARED TABLE IF NOT EXISTS blog.summary_failures (    run_key TEXT PRIMARY KEY,    blog_id TEXT NOT NULL,    error TEXT NOT NULL,    created TIMESTAMP NOT NULL DEFAULT NOW(),    updated TIMESTAMP NOT NULL DEFAULT NOW()); CREATE TOPIC blog.summarizer;ALTER TOPIC blog.summarizer ADD SOURCE blog.blogs ON INSERT WITH (payload = 'full');ALTER TOPIC blog.summarizer ADD SOURCE blog.blogs ON UPDATE WITH (payload = 'full');

Worker pattern

typescript
await runConsumer({    client,    name: 'summarizer',    topic: 'blog.summarizer',    groupId: 'summarizer',    onChange: async (_ctx, change) => {        const row = change.data;        const summary = `Summary: ${row.content.slice(0, 80)}`;        // UPDATE blog.blogs SET summary = ... WHERE blog_id = row.blog_id    },});

Files worth reading

FilePurpose
src/agent.tsFull worker logic
kalam.tomlkalam dev project config
kalam/schema.sqlSchema, topic route, and seed row
kalam/migrations/0001_init.sqlInitial migration

Verify it works

BASH
npm test

The integration test inserts a blog row and waits until the worker writes the summary field back.

Next steps

Last updated on