Autonomous Agent Template

An agent with its own database, memory, and sandbox that runs on a schedule and self-evaluates

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

PieceWhat it does
AgentModel-agnostic agent in autonomous tool mode (any supported model)
DatabaseA dedicated Postgres database the agent reads and writes
MemoryPersistent facts and decisions the agent carries across runs
SandboxA project sandbox where scheduled job handlers and code run
ScheduleA recurring r.jobs cron that triggers the agent without a human in the loop
Self-evaluationThe handler re-runs the agent to review its last run and logs the verdict to memory
IntegrationsOptional access to hundreds of data integrations as tools

How to start it

Install the SDK and run a setup script.

$npm install @recursiv/sdk
$export RECURSIV_API_KEY=sk_live_...
$export RECURSIV_ORG_ID=your-org-id
1import { Recursiv } from '@recursiv/sdk';
2
3const r = new Recursiv();
4const ORG_ID = process.env.RECURSIV_ORG_ID!;
5
6// 1. Create the agent in autonomous tool mode
7const { data: agent } = await r.agents.create({
8 name: 'Data Pipeline Agent',
9 username: 'pipeline_' + Date.now(),
10 model: 'anthropic/claude-sonnet-4.6',
11 system_prompt: `You are an autonomous agent. You own a Postgres database,
12persistent memory, and a sandbox. Plan, act, then review your own work.`,
13 tool_mode: 'autonomous',
14 organization_id: ORG_ID,
15});
16
17// 2. Give it its own infrastructure
18const { data: project } = await r.projects.create({
19 name: `${agent.username}-infra`,
20 organization_id: ORG_ID,
21});
22
23await r.databases.ensure({ name: 'agent-data', project_id: project.id });
24await r.projects.createSandbox(project.id);
25
26await r.agents.grantProjectAccess(agent.id, {
27 project_id: project.id,
28 permissions: ['execute_code', 'read_files', 'write_files'],
29});

Give it memory

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

1const { data: ctx } = await r.memory.context({ project_id: project.id });
2
3await r.memory.facts.add({
4 project_id: project.id,
5 content: 'Source API rate-limits at 100 req/min. Batch in chunks of 50.',
6});
7
8await r.memory.decisions.log({
9 project_id: project.id,
10 decision: 'Process new records hourly',
11 rationale: 'Volume is low and freshness matters more than batching.',
12});

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.

1await r.jobs.create({
2 name: 'hourly-pipeline',
3 cron: '0 * * * *', // every hour
4 project_id: project.id,
5 handler_code: `
6 const { Recursiv } = require('@recursiv/sdk');
7 const r = new Recursiv();
8
9 // Act
10 await r.agents.chat('${agent.id}', {
11 message: 'Pull new records, process them, store results.',
12 });
13
14 // Self-evaluate: have the agent review its own run and log the verdict
15 const { data: review } = await r.agents.chat('${agent.id}', {
16 message: 'Review your last run. Did anything fail or get skipped? Be specific.',
17 });
18 await r.memory.decisions.log({
19 project_id: '${project.id}',
20 decision: 'Run review',
21 rationale: review.content,
22 });
23 `,
24});

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