Agentic Sessions and Protocols ⏱ 10 min read 📁 examples/07_agent_loop.mjs

Lesson 08: Agent Loops, Skills and REPL

Build autonomous agent loops with modular skill directories, human-in-the-loop approval gates, and the AgentLauncher interactive REPL with slash commands.

1. Why This Feature Exists

Production agents need more than one-off tool calls: they need persistent skills, interactive REPL environments for debugging, and human checkpoints to prevent unintended actions.

2. Key Symbols and Exports

SkillsLibrary & loadSkillsFromDirectory()
Discovers and loads modular skill folders containing SKILL.md and executable scripts.
AgentLauncher
Terminal REPL providing tab-autocomplete, live command suggestions, and /slash commands.
LocalFileSessionStore
Persists agent session checkpoints to disk for pausing and resuming interactions.
Human-in-the-Loop (HITL) Gate
Prompts user for explicit confirmation before executing privileged or modifying actions.

3. Implementation Walkthrough

import {
    ProviderType,
    resolveProvider,
    initializeClient,
    loadCredentials,
    getDefaultModel,
    AgentLauncher
} from 'merci-sdk';
import { loadSkillsFromDirectory } from 'merci-sdk/tools';

const PROVIDER = resolveProvider();
const { client } = await initializeClient({ provider: PROVIDER, options: loadCredentials({ provider: PROVIDER }) });

// 1. Load modular skills from directory
const skills = await loadSkillsFromDirectory('examples/skills');

// 2. Instantiate AgentLauncher REPL
const launcher = new AgentLauncher(client, PROVIDER, getDefaultModel({ provider: PROVIDER }))
    .withSkills(skills)
    .withSystemMessage('You are a helpful coding assistant equipped with specialized skills.');

// 3. Start interactive session (supports /help, /skills, /clear, /exit)
console.log('Starting interactive agent REPL...');
// await launcher.runInteractive();

4. Wire and Telemetry Mechanics

Skills are registered as tools with descriptions extracted from SKILL.md. AgentLauncher handles stdin readline parsing and matches slash commands before dispatching to the LLM.

5. Run the Example

Execute the runnable example directly from the repository root:

node examples/07_agent_loop.mjs

Read the full example: examples/07_agent_loop.mjs →

Expected Output: Starts the AgentLauncher REPL. You can type commands, test slash commands (e.g. /skills), and observe skill execution.