Skip to content
Back to skills

Agentdb Learning

ASecurity

Run reinforcement-learning sessions with AgentDB's LearningSystem (q-learning, sarsa, dqn, policy-gradient, actor-critic, ppo, decision-transformer, mcts, model-based session types), record episodes with ReflexionMemory, and drive the agentdb train/learn/reflexion CLI verbs. Use when building agents that learn from rewarded experience.

  • 82,861 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 2, 2026
ai-agentstypescriptgobashsqlnodegitapidatabase

Works with

  • cli
  • api
  • mcp

Security analysis

A92/100
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned November 29, 2026

npx -y skills add ruvnet/ruflo --skill agentdb-learning --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Agentdb Learning?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Agentdb Learning
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ruvnet-agentdb-learning-4b2f349b/badge)](https://www.skillsdirectory.com/skills/ruvnet-agentdb-learning-4b2f349b)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: agentdb-learning
description: "Run reinforcement-learning sessions with AgentDB's LearningSystem (q-learning, sarsa, dqn, policy-gradient, actor-critic, ppo, decision-transformer, mcts, model-based session types), record episodes with ReflexionMemory, and drive the agentdb train/learn/reflexion CLI verbs. Use when building agents that learn from rewarded experience."
---

# AgentDB Learning

## What This Skill Does

Shows how to make an agent learn from rewarded experience with the interfaces the `agentdb`
package actually ships:

- **`LearningSystem`** - RL session lifecycle: start a session, submit feedback, predict the next
  action, train the policy, end the session.
- **`ReflexionMemory`** (via `AgentDB#getController('reflexion')`) - store episodes with a reward
  and a self-critique, then retrieve the relevant ones for a new task.
- **The `agentdb` CLI** - `reflexion`, `skill`, `learner`, `train`, `learn` and `store-pattern` verbs.

There is no plugin generator: `agentdb` has no `create-plugin`, `list-templates`, `list-plugins`
or `plugin-info` command, and no `createAgentDBAdapter` factory. Use the classes and verbs below.

## Prerequisites

- Node.js 20+
- `agentdb` 3.10+ (`npm install agentdb`; it is also a dependency of `@claude-flow/cli`)

---

## Quick Start with the API

```typescript
import { AgentDB, EmbeddingService, LearningSystem } from 'agentdb';

// Open (or create) a database. initialize() must be awaited before use.
const db = new AgentDB({ dbPath: '.agentdb/learning.db' });
await db.initialize();

const embedder = new EmbeddingService({
  model: 'Xenova/all-MiniLM-L6-v2',
  dimension: 384,
  provider: 'transformers',
});
await embedder.initialize();

const learning = new LearningSystem(db.database, embedder);

// sessionType is one of the nine values listed below
const sessionId = await learning.startSession('agent-1', 'q-learning', {
  learningRate: 0.1,
  discountFactor: 0.99,
  explorationRate: 0.1,
});

// Feed back what happened after taking an action in a state
await learning.submitFeedback({
  sessionId,
  state: 'login-form-empty',
  action: 'fill-credentials',
  reward: 1,
  nextState: 'logged-in',
  success: true,
  timestamp: Date.now(),
});

// Ask for the best action in a state
const prediction = await learning.predict(sessionId, 'login-form-empty');
console.log(prediction.action, prediction.confidence, prediction.alternatives);

// Batch-train the policy: train(sessionId, epochs, batchSize, learningRate)
const result = await learning.train(sessionId, 10, 32, 0.1);
console.log(result.epochsCompleted, result.finalLoss, result.avgReward);

await learning.endSession(sessionId);
await db.close();
```

`train()` returns `{ epochsCompleted, finalLoss, avgReward, convergenceRate, trainingTimeMs }`.

---

## Session Types

`LearningSystem#startSession` accepts these `sessionType` values:

| sessionType | Family |
|---|---|
| `q-learning` | value-based, off-policy |
| `sarsa` | value-based, on-policy |
| `dqn` | deep Q-network |
| `policy-gradient` | policy gradient |
| `actor-critic` | policy gradient with a value baseline |
| `ppo` | proximal policy optimization |
| `decision-transformer` | offline, sequence-modelling RL |
| `mcts` | Monte Carlo tree search |
| `model-based` | model-based RL |

All of them share the same config (`LearningConfig`): `learningRate`, `discountFactor`, and the
optional `explorationRate`, `batchSize` and `targetUpdateFrequency`. Treat the session type as a
label for how the stored experience is scored, not as a separate neural network per type, and
measure on your own task before relying on one type over another.

---

## Episodic Memory with Reflexion

`ReflexionMemory` stores whole task attempts with a reward and a critique, so a later attempt can
start from what worked and what failed.

```typescript
import { AgentDB } from 'agentdb';

const db = new AgentDB({ dbPath: '.agentdb/learning.db' });
await db.initialize();
const reflexion = db.getController('reflexion');

await reflexion.storeEpisode({
  sessionId: 'session-1',
  task: 'fix login bug',
  input: 'users are logged out after 5 minutes',
  output: 'extended token refresh window',
  critique: 'check token expiry before touching the session store',
  reward: 0.9,
  success: true,
});

// Retrieve the most relevant past attempts for a new task
const episodes = await reflexion.retrieveRelevant({ task: 'login bug', k: 5 });
for (const e of episodes) console.log(e.task, e.reward, e.critique);

// Aggregated lessons from past attempts
console.log(await reflexion.getCritiqueSummary({ task: 'login bug' }));

await db.close();
```

`getController` accepts `'reflexion'` (alias `'memory'`), `'skills'` and `'causal'`
(alias `'causalGraph'`).

---

## CLI Operations

The CLI reads the database from `AGENTDB_PATH` (default `./agentdb.db`).

```bash
# Create the database
npx agentdb@latest init ./agentdb.db --dimension 384

# Store an episode: <session-id> <task> <reward> <success> [critique] [input] [output]
npx agentdb@latest reflexion store "session-1" "fix_login_bug" 0.9 true "check token expiry first"

# Retrieve relevant episodes
npx agentdb@latest reflexion retrieve "login bug" --k 5 --only-successes

# Aggregated critique lessons for a task
npx agentdb@latest reflexion critique-summary "fix_login_bug"

# Turn repeated successful episodes into reusable skills
npx agentdb@latest skill consolidate 3 0.7 7
npx agentdb@latest skill search "authentication" 5

# Discover causal edges from episode outcomes
npx agentdb@latest learner run 3 0.6 0.7

# Store a learned pattern and trigger pattern learning / skill consolidation
npx agentdb@latest store-pattern --type "experience" --domain "code-edits" --pattern '{"success":true}' --confidence 0.9
npx agentdb@latest train --domain "code-edits" --epochs 10 --batch-size 32

# Embedding-space training from a data file: curriculum, contrastive or hard-negatives
npx agentdb@latest learn --mode curriculum --data train.json --schedule cosine

# Database statistics
npx agentdb@latest db stats
```

Run `npx agentdb@latest --help` for every verb and its options.

---

## Using It from Ruflo

Inside a ruflo session the same learning loop is exposed as MCP tools, with no code to write:

- `mcp__claude-flow__agentdb_pattern-store` / `mcp__claude-flow__agentdb_pattern-search` - store
  and retrieve learned patterns.
- `mcp__claude-flow__agentdb_feedback` - record the outcome of a task.
- `mcp__claude-flow__agentdb_episode-recall` - recall past episodes.
- `mcp__claude-flow__neural_train` / `mcp__claude-flow__neural_status` - ruflo's own pattern
  training and its status.

---

## Troubleshooting

### `better-sqlite3 was built for a different Node.js ABI`
AgentDB falls back to sql.js (WASM) and keeps working, more slowly. Run `npm rebuild better-sqlite3`,
or clear the npx cache if you run through `npx`.

### `AgentDB not initialized. Call initialize() first.`
`getController()` and `database` need `await db.initialize()` first.

### Predictions are always the same action
`predict()` only knows the actions it has seen feedback for in that session. Submit feedback for
each action you want it to choose between, with rewards that separate them.

---

## Learn More

- `npx agentdb@latest --help` - the full CLI reference for the installed version
- Type definitions: `node_modules/agentdb/dist/src/controllers/LearningSystem.d.ts` and
  `ReflexionMemory.d.ts`
- Source: https://github.com/ruvnet/agentic-flow/tree/main/packages/agentdb

---

**Category**: Machine Learning / Reinforcement Learning
**Difficulty**: Intermediate

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.