Skip to content
Cloudflare Docs

Get started

Use the starter template

To use the Agent starter template and create your first Agent with the Agents SDK:

  1. Create a new project using the agents-starter template.

    Terminal window
    # install it
    npm create cloudflare@latest agents-starter -- --template=cloudflare/agents-starter
  2. Deploy the project.

    Terminal window
    #deploy it
    npx wrangler@latest deploy

Integrate Agents to your existing Worker

  1. Install the agents package directly into an existing project:

    Terminal window
    npm i agents
  2. Define your first Agent by creating a class that extends the Agent class:

    import { Agent, AgentNamespace } from "agents";
    export class MyAgent extends Agent {
    // Define methods on the Agent:
    // https://developers.cloudflare.com/agents/api-reference/agents-api/
    //
    // Every Agent has built in state via this.setState and this.sql
    // Built-in scheduling via this.schedule
    // Agents support WebSockets, HTTP requests, state synchronization and
    // can run for seconds, minutes or hours: as long as the tasks need.
    }
  3. Add the Durable Objects binding to your wrangler file:

    {
    "durable_objects": {
    "bindings": [
    {
    "name": "MyAgent",
    "class_name": "MyAgent"
    }
    ]
    },
    "migrations": [
    {
    "tag": "v1",
    "new_sqlite_classes": [
    "MyAgent"
    ]
    }
    ]
    }

Dive into the Agent SDK reference to learn more about how to use the Agents SDK package and defining an Agent.

Additional resources