### Run Electric Agents Quickstart Source: https://electric.ax/blog/2026/04/29/introducing-electric-agents Execute the command to start the Electric Agents runtime server and scaffold the chat starter. ```bash npx electric-ax agents quickstart ``` -------------------------------- ### Configure and Run Playground Source: https://electric.ax/docs/agents/examples/playground Navigate to the playground directory, copy the environment configuration, install dependencies, and start the development server. The app server will register entity types with the agent server. ```bash cd examples/agents-playground cp .env.example .env pnpm install pnpm dev ``` -------------------------------- ### Start Development Server Source: https://electric.ax/docs/sync/quickstart Start the development server for your Electric application. This command is used after the initial project setup to run the app locally. ```shell pnpm dev ``` -------------------------------- ### Start Local Agents Infrastructure Source: https://electric.ax/docs/agents/examples/playground Use this command to start the local agents infrastructure from the monorepo root. Ensure you have the necessary tools installed. ```bash npx electric-ax agents start ``` -------------------------------- ### Initial Sync Request Example Source: https://electric.ax/docs/sync/api/http Make an initial request to sync data for a shape, requesting all data from the start. ```sh curl -i 'http://localhost:3000/v1/shape?table=foo&offset=-1' ``` -------------------------------- ### Set Up Shell Completions Source: https://electric.ax/docs/agents/reference/cli Configures shell tab-completion for Electric Agents commands. Use 'install' to auto-install or follow manual setup instructions. ```bash electric agents completion # Show setup instructions ``` ```bash electric agents completion install # Auto-install into your shell init file ``` -------------------------------- ### Project Setup and Development Commands Source: https://electric.ax/AGENTS Commands to create a new TanStack DB web project, set up environment variables, install dependencies, run the development server, and apply database migrations. ```sh npx gitpick electric-sql/electric/tree/main/examples/tanstack-db-web-starter my-tanstack-db-project cd my-tanstack-db-project cp .env.example .env pnpm install pnpm dev # in new terminal pnpm migrate ``` -------------------------------- ### Install Durable Streams Go Package Source: https://electric.ax/blog/2025/12/23/durable-streams-0.1.0 Installs the Durable Streams Go client library using the go get command. ```bash go get github.com/durable-streams/durable-streams-go ``` -------------------------------- ### Start Electric Agents Dev Server Source: https://electric.ax/docs/agents/walkthrough Installs and starts the Electric Agents development server using its CLI. This command requires Docker to be running and will set up necessary containers. ```sh pnpx electric-ax@latest agents start ``` -------------------------------- ### AWS Terraform Example Repository Source: https://electric.ax/docs/sync/integrations/aws An example repository demonstrating how to deploy Electric SQL infrastructure on AWS using Terraform. This provides a starting point for automating your AWS deployments. ```markdown We have an example Terraform repo at [electric-sql/terraform-aws](https://github.com/electric-sql/terraform-aws). ``` -------------------------------- ### Install TypeScript Client Source: https://electric.ax/docs/sync/api/clients/typescript Install the ElectricSQL TypeScript client using npm. ```sh npm i @electric-sql/client ``` -------------------------------- ### Initialize Yjs Provider Source: https://electric.ax/docs/streams/integrations/yjs Quick start example demonstrating how to initialize the YjsProvider with a Yjs document, awareness, and server details. The provider automatically connects and synchronizes the document. ```typescript import { YjsProvider } from "@durable-streams/y-durable-streams" import * as Y from "yjs" import { Awareness } from "y-protocols/awareness" const doc = new Y.Doc() const awareness = new Awareness(doc) const provider = new YjsProvider({ doc, baseUrl: "http://localhost:4438/v1/yjs/my-service", docId: "my-document", awareness, }) provider.on("synced", (synced) => { console.log("Synced:", synced) }) ``` -------------------------------- ### Start Electric-AX Runtime Server and Agents Source: https://electric.ax/docs/agents/quickstart Run these commands to start the runtime server and its components independently. The `start` command runs the server and UI in the background using Docker, while `start-builtin` runs the Horton and worker agents in the foreground. ```sh npx electric-ax agents start # runtime server + UI (background, Docker) ``` ```sh npx electric-ax agents start-builtin # built-in Horton and worker (foreground) ``` -------------------------------- ### Install @electric-sql/react Source: https://electric.ax/docs/sync/integrations/react Install the ElectricSQL React hooks package using npm. ```shell npm i @electric-sql/react ``` -------------------------------- ### Start Supabase and Serve Functions Source: https://electric.ax/docs/sync/integrations/supabase Start Supabase services locally and serve the created edge functions. ```shell supabase start supabase functions serve ``` -------------------------------- ### Install Project Dependencies Source: https://electric.ax/blog/2025/04/09/building-ai-apps-on-sync Install all necessary project dependencies using pnpm. Ensure Node.js and pnpm are installed. ```sh pnpm install ``` -------------------------------- ### Install Electric React Client Source: https://electric.ax/docs/sync/llms/_quickstart_redux Navigate into the created React application directory and install the `@electric-sql/react` package. This package provides hooks and components for integrating with Electric. ```sh cd react-app npm install @electric-sql/react ``` -------------------------------- ### Install Dependencies Source: https://electric.ax/docs/streams/integrations/tanstack-ai Install the necessary client and transport packages for TanStack AI integration. ```bash pnpm add @durable-streams/client @durable-streams/tanstack-ai-transport ``` -------------------------------- ### Run Caddy as a Local Reverse Proxy Source: https://electric.ax/docs/sync/guides/troubleshooting Use this command to start Caddy, enabling HTTP/2 for faster shape synchronization by proxying requests to your Electric backend. Ensure Caddy is installed and its certificate is trusted. ```shell caddy run \ --config - \ --adapter caddyfile \ <( "http://localhost:5133", createClient("ws://localhost:5133/ws"), { console: console } ); // Sync into Redis async function syncToRedis() { // Subscribe to all tables await electric.db.வுகளை.subscribe(); // Listen for changes and update Redis await electric.db.வுகளை.listen(async (rows) => { for (const row of rows) { // Example: Store the entire row as a JSON string in Redis // You might want to store specific fields or use a different Redis data structure await redis.set(`வுகளை:${row.id}`, JSON.stringify(row)); console.log(`Updated Redis key: vౌvౌs:${row.id}`); } }); console.log("Electric sync to Redis started."); } // Start the sync process syncToRedis().catch(console.error); // Handle incoming HTTP requests (e.g., for Electric's webhook) // This part is simplified and assumes a Hono setup // In a real application, you would integrate this with your web framework // Example of a Hono request handler (if using Hono) // const app = new Hono(); // app.post("/electric-webhook", async (c) => { // const req = c.req as HonoRequest; // await electric.sync(req); // return c.text("Electric sync processed"); // }); // export default app; ``` -------------------------------- ### Quickstart Electric Agents Source: https://electric.ax/docs/agents/reference/cli Begin with the coordinator server, display onboarding instructions, and run the built-in agents runtime. An Anthropic API key is required for the built-in Horton server. ```bash electric agents quickstart --anthropic-api-key sk-ant-... ``` -------------------------------- ### Start Caddy Server Source: https://electric.ax/docs/agents/walkthrough Command to start the Caddy server in the background. Ensure Caddy is installed and trusted on your system. ```sh caddy start ``` -------------------------------- ### Read Stream from Start Source: https://electric.ax/streams Read all messages from a stream starting from the beginning using a GET request to the /v1/stream/{streamName} endpoint with offset=-1. ```sh # Read from the start curl "http://localhost:4437/v1/stream/hello?offset=-1" ``` -------------------------------- ### Start Electric SQL Project with CLI Source: https://electric.ax/agents Initialize a new project using the Electric SQL CLI command. ```bash npx @electric-sql/start my-app ``` -------------------------------- ### Run the Demo Application Source: https://electric.ax/blog/2025/04/09/building-ai-apps-on-sync Launch the frontend demo application. After starting, access it via your web browser at localhost:5173. ```sh pnpm dev:app ``` -------------------------------- ### Start and Stop Built-in Agents Server Source: https://electric.ax/docs/agents/usage/embedded-builtins Use `BuiltinAgentsServer` to register and start the built-in Horton and worker runtime within your process. This example shows how to instantiate the server, start it, log the runtime URL, and later stop the server. ```typescript import { BuiltinAgentsServer } from "@electric-ax/agents" const server = new BuiltinAgentsServer({ agentServerUrl: "http://localhost:4437", workingDirectory: process.cwd(), loadProjectMcpConfig: true, pullWake: { runnerId: "builtin-agents", ownerPrincipal: "/principal/system%3Abuiltin-agents", registerRunner: true, }, }) const runtimeUrl = await server.start() console.log(runtimeUrl) // "pull-wake:builtin-agents" // Later, during shutdown: await server.stop() ``` -------------------------------- ### Full CLI Workflow Example Source: https://electric.ax/docs/streams/cli A comprehensive example demonstrating a typical CLI session: setting the stream URL, creating a JSON stream, reading from it, writing messages, piping data, and finally deleting the stream. ```bash export STREAM_URL=http://localhost:4437/v1/stream # Create a JSON stream durable-stream create chat --json # In another terminal, start following the stream durable-stream read chat # Back in the first terminal, write messages durable-stream write chat '{"user": "alice", "text": "Hello!"}' --json durable-stream write chat '{"user": "bob", "text": "Hi there!"}' --json # Pipe data in echo '{"user": "alice", "text": "How are you?"}' | durable-stream write chat --json # Clean up durable-stream delete chat ``` -------------------------------- ### Start Electric App (Cloud) Source: https://electric.ax/docs/sync/quickstart Run the starter script to create a new Electric application in the cloud environment. This command initializes the project structure and necessary configurations. ```shell npx @electric-sql/start my-electric-app ``` -------------------------------- ### Initialize Electric App with Docker Source: https://electric.ax/docs/sync/quickstart Initialize a new Electric application using the starter template and Docker for local backend services. This command clones the template and sets up the project directory. ```shell npx gitpick electric-sql/electric/tree/main/examples/tanstack-db-web-starter my-electric-app ``` -------------------------------- ### Start Local Server Source: https://electric.ax/docs/agents/reference/cli Initiate the local Electric Agents coordinator server, along with Postgres and the Electric UI, using Docker Compose. ```bash electric agents start ``` -------------------------------- ### Initialize New Electric Agents Project Source: https://electric.ax/docs/agents/reference/cli Scaffolds a new Electric Agents project using the bundled starter template. Provide a project name to customize the app name. ```bash electric agents init ``` ```bash electric agents init my-agents-app ``` -------------------------------- ### Run Expo App Source: https://electric.ax/docs/sync/integrations/expo Start your Expo application, for example, in a web browser environment, using the command `npm run web`. ```shell npm run web ``` -------------------------------- ### Clone the AI Chat Demo Repository Source: https://electric.ax/blog/2025/04/09/building-ai-apps-on-sync Clone the Electric AI chat demo repository from GitHub to get started with the project. ```sh git clone https://github.com/electric-sql/electric-ai-chat.git cd electric-ai-chat ``` -------------------------------- ### Provision an Electric Sync Source Source: https://electric.ax/cloud/cli Create a new project, then an environment within that project, and finally provision a PostgreSQL service with the specified database URL and region. ```shell electric projects create --name "my-app" electric environments create --project proj_abc --name "staging" electric services create postgres \ --environment env_abc \ --database-url "postgresql://user:pass@host:5432/db" \ --region us-east-1 ``` -------------------------------- ### Reading from a Stream with Offset Source: https://electric.ax/docs/streams Example of reading from a stream starting from the beginning (offset -1). The response includes the next offset to use for subsequent reads. ```http GET /streams/my-stream?offset=-1 < 200 OK < Stream-Next-Offset: 01JQXK5V00 < …response body… ``` -------------------------------- ### Full Context Composition Example Source: https://electric.ax/docs/agents/usage/context-composition This example demonstrates combining built-in and custom tools, and configuring multiple context sources with specific budgets and caching strategies. Use this when you need fine-grained control over agent context and resource allocation. ```typescript async handler(ctx, wake) { const tools = [...ctx.electricTools, ...customTools] ctx.useContext({ sourceBudget: 18_000, sources: { docs_toc: { content: () => renderCompressedToc(), max: 3_000, cache: "stable", }, retrieved_docs: { content: () => renderRetrievedDocs(wake, ctx.events), max: 6_000, cache: "volatile", }, conversation: { content: () => ctx.timelineMessages(), max: 9_000, cache: "volatile", }, }, }) ctx.useAgent({ systemPrompt: "You are a helpful assistant.", model: "claude-sonnet-4-6", tools, }) await ctx.agent.run() } ``` -------------------------------- ### Long-Poll Live Mode Request Source: https://electric.ax/docs/streams Example GET request to enable long-polling for real-time updates. The server holds the connection until new data arrives or a timeout occurs. ```http GET /stream?offset=01JQXK5V00&live=long-poll ``` -------------------------------- ### SSE Live Mode Request Source: https://electric.ax/docs/streams Example GET request to enable Server-Sent Events (SSE) for real-time updates. This mode delivers data and control events over a persistent connection. ```http GET /stream?offset=01JQXK5V00&live=sse ``` -------------------------------- ### Electric Agents Development Quick Start Commands Source: https://electric.ax/AGENTS Provides essential commands for setting up, building, starting, and managing the Electric Agents development environment. Ensure API keys are set in `.env`. ```sh ./scripts/dev.sh build # install + build typescript-client, agents-runtime, # agents-mcp, agents-server, agents ./scripts/dev.sh start # docker + 5 dev processes; Ctrl-C stops everything ./scripts/dev.sh start --with-agents # also spawn built-in agents (Horton + Worker) ./scripts/dev.sh desktop # run the Electron desktop app (in a separate terminal, # against an already-running stack) ./scripts/dev.sh stop # stop processes + docker compose down ./scripts/dev.sh teardown # also remove Postgres volume + .streams-data/ ``` -------------------------------- ### Running Electric Sync Service with Docker Source: https://electric.ax/docs/sync/api/config This example demonstrates how to run the Electric sync service using Docker, setting essential environment variables for database connection and port mapping. ```shell docker run \ -e "DATABASE_URL=postgresql://..." \ -e "ELECTRIC_DB_POOL_SIZE=10" \ -p 3000:3000 \ electricsql/electric ``` -------------------------------- ### Add Persistence to an Electric Collection Source: https://electric.ax/blog/2026/03/25/tanstack-db-0.6-app-ready-with-persistence-and-includes This example demonstrates how to add persistence to an Electric-backed collection using the React Native SQLite adapter. Ensure you have the necessary adapters installed for your environment (React Native, browser, or Node). ```typescript import { open } from '@op-engineering/op-sqlite' import { createCollection } from '@tanstack/db' import { electricCollectionOptions } from '@tanstack/electric-db-collection' import { createReactNativeSQLitePersistence, persistedCollectionOptions, } from '@tanstack/react-native-db-sqlite-persistence' const database = open({ name: 'electric-app.sqlite', location: 'default', }) const persistence = createReactNativeSQLitePersistence({ database }) // Add persistence to one Electric-backed collection. const items = createCollection( persistedCollectionOptions({ persistence, schemaVersion: 1, ...electricCollectionOptions({ id: 'items', schema: itemSchema, getKey: (row) => row.id, shapeOptions: { url: '/api/items' }, onInsert: async ({ transaction, collection }) => { const { txid } = await api.items.create(transaction.mutations[0].modified) await collection.utils.awaitTxId(txid) }, }), }), ) ``` -------------------------------- ### Docker Compose for Multi-instance Electric Source: https://electric.ax/docs/sync/guides/sharding Example demonstrating how to configure and deploy multiple Electric instances using Docker Compose, with each instance dedicated to a specific PostgreSQL shard. ```yaml services: # Electric for Shard 0 electric-shard-0: image: electricsql/electric:latest environment: DATABASE_URL: postgresql://postgres:password@postgres-shard-0:5432/myapp ELECTRIC_INSTANCE_ID: electric-shard-0 ELECTRIC_REPLICATION_STREAM_ID: shard-0 ELECTRIC_STORAGE_DIR: /var/lib/electric/data ELECTRIC_SECRET: ${ELECTRIC_SECRET} ports: - "3001:3000" volumes: - electric_data_0:/var/lib/electric/data # Electric for Shard 1 electric-shard-1: image: electricsql/electric:latest environment: DATABASE_URL: postgresql://postgres:password@postgres-shard-1:5432/myapp ELECTRIC_INSTANCE_ID: electric-shard-1 ELECTRIC_REPLICATION_STREAM_ID: shard-1 ELECTRIC_STORAGE_DIR: /var/lib/electric/data ELECTRIC_SECRET: ${ELECTRIC_SECRET} ports: - "3002:3000" volumes: - electric_data_1:/var/lib/electric/data # Add more shards as needed... volumes: electric_data_0: electric_data_1: ``` -------------------------------- ### Install System Dependencies with ASDF Source: https://electric.ax/docs/sync/guides/installation Install system dependencies for Electric using ASDF version manager. Ensure Elixir, Erlang, Node.js, and pnpm are installed and configured. ```shell asdf plugin-add elixir asdf plugin-add erlang asdf plugin-add nodejs asdf plugin-add pnpm asdf install ``` -------------------------------- ### Initialize Agent with System Prompt and Model Source: https://electric.ax/docs/agents/usage/configuring-the-agent Use `ctx.useAgent` to configure the agent with a system prompt, model, and tools. The `ctx.agent` reference is equivalent to the returned `AgentHandle`. ```typescript async handler(ctx) { ctx.useAgent({ systemPrompt: 'You are a helpful assistant.', model: 'claude-sonnet-4-6', tools: [...ctx.electricTools], }) await ctx.agent.run() } ``` -------------------------------- ### Install Agent Skills with TanStack Intent Source: https://electric.ax/blog/2026/03/06/agent-skills-now-shipping Run this command to install agent skills for your project's dependencies. This loads a skill inside your agent that installs relevant skills for your project. ```bash npx @tanstack/intent install ``` -------------------------------- ### Listing Available Webhook Sources Programmatically Source: https://electric.ax/docs/agents/usage/webhook-sources Example of fetching a list of available webhook sources using the `createRuntimeServerClient`. ```typescript const sources = await client.listWebhookSources() ``` -------------------------------- ### Navigate to Project Directory Source: https://electric.ax/docs/sync/quickstart Change the current directory to the newly created Electric application folder. ```shell cd my-electric-app ``` -------------------------------- ### Install Yjs Dependencies Source: https://electric.ax/docs/streams/integrations/yjs Install the necessary packages for Yjs integration with Durable Streams. ```bash npm install @durable-streams/y-durable-streams yjs y-protocols lib0 ``` -------------------------------- ### Deploy with Electric Cloud CLI Source: https://electric.ax/AGENTS Commands to start a new Electric SQL project and deploy it using the Electric Cloud command-line interface. ```bash npx @electric-sql/start my-app pnpm claim && pnpm deploy ``` -------------------------------- ### Programmatic CLI Setup with electric-ax Source: https://electric.ax/docs/agents/reference/cli Programmatically set up and run the Electric CLI using the 'electric-ax' package. Configure environment variables for agent URL, identity, and principal. ```typescript import { createElectricCliHandlers, createElectricProgram, getElectricCliEnv, run, } from "electric-ax" const env = getElectricCliEnv({ ...process.env, ELECTRIC_AGENTS_URL: "http://localhost:4437", ELECTRIC_AGENTS_IDENTITY: "docs@example.com", ELECTRIC_AGENTS_PRINCIPAL: "user:docs@example.com", }) const handlers = createElectricCliHandlers(env, "electric agents") const program = createElectricProgram({ env, handlers, commandName: "electric", commandPrefix: "electric agents", }) await program.parseAsync(["node", "electric", "agents", "types"]) ``` -------------------------------- ### Install Durable Streams Package Source: https://electric.ax/docs/sync/integrations/vercel Install the necessary package for Durable Transport using npm. ```bash npm install @electric-sql/durable-streams ```