This sample demonstrates how to run an A2A agent with persistent database storage using:
DatabaseTaskStore— persists task snapshots, status updates, messages, and artifacts.DatabasePushNotificationStore— persists webhook configurations registered by clients.
Both stores connect through a single Kysely instance to a local SQLite database (a2a.db).
agent_executor.ts— handles execution turns, publishing initial task state, status updates, and output artifacts.index.ts— Express A2A server initialized withDatabaseTaskStoreandDatabasePushNotificationStorebacked by SQLite.webhook.ts— standalone webhook endpoint receiving push notifications forwarded by the agent using configs stored in SQLite.client.ts— client script that submits tasks, registers push notification configs, and fetches tasks & push configs by ID to verify persistence across server restarts.
Database-backed stores require the schema to be initialized before the server starts. Navigate to src/samples and initialize the SQLite database:
cd src/samples
# Option A: Online migration via a2a-db CLI
npm run a2a-db -- upgrade --url sqlite:./a2a.dbNote: In a standalone project where
@a2a-js/sdkis installed, runnpx a2a-dbdirectly.
Alternatively, you can generate and execute the SQL script offline:
cd src/samples
# Option B: Render SQL offline and execute it
npm run a2a-db -- upgrade --sql --dialect sqlite > schema.sql
sqlite3 a2a.db < schema.sqlYou can verify the migration status with:
npm run a2a-db -- status --url sqlite:./a2a.dbOpen two terminals inside src/samples:
Terminal 1 — start the agent server:
npm run agents:database-agentThe server will start on http://localhost:41241 and connect to a2a.db.
Terminal 2 — start the webhook receiver:
cd src/samples
npm run agents:database-webhookThe webhook listener will start on http://localhost:42424/webhook/task-updates.
In a third terminal:
cd src/samples
npm run agents:database-clientThe client will:
- Submit a new task with a push notification webhook configuration pointing to
http://localhost:42424/webhook/task-updates. - The agent server stores the push config in SQLite (
DatabasePushNotificationStore), runs the task, and sends event updates to the webhook. - Terminal 2 will log incoming event notifications in real time.
- Terminal 3 receives the completed task and displays the created task ID (e.g.
task-abc-123).
-
In Terminal 1, stop the agent server.
-
Restart the server:
npm run agents:database-agent
-
In Terminal 3 (client), fetch the task created earlier using its ID:
npm run agents:database-client -- <taskId>
The client will retrieve:
- The task, history, status, and generated artifact content from
DatabaseTaskStore. - The registered webhook configuration from
DatabasePushNotificationStore.
Example output:
[Client] Task found in persistent storage! [Client] ID: c922765e-... [Client] State: TASK_STATE_COMPLETED [Client] Messages: 2 [Client] Artifacts: 1 [Client] Artifact 1: "Agent Execution Result" [Client] Content: Agent Analysis Complete: [Client] Successfully processed request: "Hello from persistent client!". [Client] Execution result, history, and status have been persisted to SQLite via DatabaseTaskStore. [Client] Push Notification Configs: 1 [Client] Target URL: http://localhost:42424/webhook/task-updates [Client] Success! Both task and push configs were restored from SQLite. - The task, history, status, and generated artifact content from
Both stores successfully persist and restore state from SQLite across server restarts!
You can also inspect the SQLite tables directly:
sqlite3 a2a.db "SELECT id, status_state FROM tasks;"
sqlite3 a2a.db "SELECT task_id, config_data FROM push_notification_configs;"
sqlite3 a2a.db "SELECT name, timestamp FROM a2a_tasks_migrations;"