> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.recursiv.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.recursiv.io/_mcp/server.

# Autonomous Agent Template

## What it is

A starting point for an agent that operates on its own, not just one that answers when prompted. It has its own Postgres database, persistent memory, and a code sandbox. A scheduled job triggers it on a cadence, and it logs decisions and reviews its own work between runs so it improves over time.

This is Recursiv's most differentiated pattern: an agent with real infrastructure it can provision and manage, not an LLM wrapper.

## What it includes

| Piece           | What it does                                                                        |
| --------------- | ----------------------------------------------------------------------------------- |
| Agent           | Model-agnostic agent in autonomous tool mode (any supported model)                  |
| Database        | A dedicated Postgres database the agent reads and writes                            |
| Memory          | Persistent facts and decisions the agent carries across runs                        |
| Sandbox         | A project sandbox where scheduled job handlers and code run                         |
| Schedule        | A recurring `r.jobs` cron that triggers the agent without a human in the loop       |
| Self-evaluation | The handler re-runs the agent to review its last run and logs the verdict to memory |
| Integrations    | Optional access to hundreds of data integrations as tools                           |

## How to start it

Install the SDK and run a setup script.

```bash
npm install @recursiv/sdk
export RECURSIV_API_KEY=sk_live_...
export RECURSIV_ORG_ID=your-org-id
```

```typescript
import { Recursiv } from '@recursiv/sdk';

const r = new Recursiv();
const ORG_ID = process.env.RECURSIV_ORG_ID!;

// 1. Create the agent in autonomous tool mode
const { data: agent } = await r.agents.create({
  name: 'Data Pipeline Agent',
  username: 'pipeline_' + Date.now(),
  model: 'anthropic/claude-sonnet-4.6',
  system_prompt: `You are an autonomous agent. You own a Postgres database,
persistent memory, and a sandbox. Plan, act, then review your own work.`,
  tool_mode: 'autonomous',
  organization_id: ORG_ID,
});

// 2. Give it its own infrastructure
const { data: project } = await r.projects.create({
  name: `${agent.username}-infra`,
  organization_id: ORG_ID,
});

await r.databases.ensure({ name: 'agent-data', project_id: project.id });
await r.projects.createSandbox(project.id);

await r.agents.grantProjectAccess(agent.id, {
  project_id: project.id,
  permissions: ['execute_code', 'read_files', 'write_files'],
});
```

## Give it memory

Memory persists across runs. Load context at the start of a run, then record what the agent learns.

```typescript
const { data: ctx } = await r.memory.context({ project_id: project.id });

await r.memory.facts.add({
  project_id: project.id,
  content: 'Source API rate-limits at 100 req/min. Batch in chunks of 50.',
});

await r.memory.decisions.log({
  project_id: project.id,
  decision: 'Process new records hourly',
  rationale: 'Volume is low and freshness matters more than batching.',
});
```

## Run on a schedule

A scheduled job runs its `handler_code` in the project sandbox on a cron. The handler is where the agent acts and then reviews its own last run.

```typescript
await r.jobs.create({
  name: 'hourly-pipeline',
  cron: '0 * * * *', // every hour
  project_id: project.id,
  handler_code: `
    const { Recursiv } = require('@recursiv/sdk');
    const r = new Recursiv();

    // Act
    await r.agents.chat('${agent.id}', {
      message: 'Pull new records, process them, store results.',
    });

    // Self-evaluate: have the agent review its own run and log the verdict
    const { data: review } = await r.agents.chat('${agent.id}', {
      message: 'Review your last run. Did anything fail or get skipped? Be specific.',
    });
    await r.memory.decisions.log({
      project_id: '${project.id}',
      decision: 'Run review',
      rationale: review.content,
    });
  `,
});
```

## Key SDK calls

* `r.agents.create({ tool_mode: 'autonomous', model, system_prompt })` - the agent itself
* `r.databases.ensure({ project_id, name })` - its own database
* `r.projects.createSandbox(projectId)` - its sandbox
* `r.agents.grantProjectAccess(agentId, { project_id, permissions })` - wire the agent to its infra
* `r.memory.context({ project_id })`, `r.memory.facts.add(...)`, `r.memory.decisions.log(...)` - persistent memory
* `r.jobs.create({ name, cron, handler_code, project_id })` - run on a schedule
* `r.agents.chat(agentId, { message })` and `r.agents.chatStream(agentId, { message })` - act, review, or steer the agent

## Next steps

* [Build an Autonomous Agent](/guides/run/build-an-autonomous-agent) for the full walkthrough
* [Quickstart](/guides/start-here/quickstart) for first calls
* [API Reference](/api-reference) for every endpoint