Salta ai contenuti
← Torna al sito
Soleri | Docs

Extending Your Agent

Questi contenuti non sono ancora disponibili nella tua lingua.

Soleri agents follow a three-layer model:

  1. Engine (@soleri/core) — vault, brain, planner, curator, loops, governance. Updated via npm update.
  2. Agent shell (src/index.ts) — persona, activation, domain facades. Generated by forge.
  3. User extensions (src/extensions/) — your custom ops, facades, middleware, and hooks. Never touched by upgrades.

Extensions are additive — they can’t break the engine. npm update @soleri/core is always safe.

If your agent was scaffolded with Soleri v5.10+, the src/extensions/ directory already exists. For older agents:

Terminal window
npx @soleri/cli extend init

This creates:

src/extensions/
index.ts # Extension manifest (auto-discovered at startup)
ops/example.ts # Example custom op
facades/ # Custom facades (empty)
middleware/ # Middleware (empty)

Custom ops are merged into your agent’s core facade alongside the 200+ built-in ops.

Terminal window
npx @soleri/cli extend add-op summarize_pr

Then implement your logic in src/extensions/ops/summarize-pr.ts:

import { z } from 'zod';
import type { OpDefinition, AgentRuntime } from '@soleri/core';
export function createSummarizePrOp(runtime: AgentRuntime): OpDefinition {
return {
name: 'summarize_pr',
description: 'Summarize a GitHub PR using vault context.',
auth: 'read',
schema: z.object({
prUrl: z.string().describe('GitHub PR URL'),
}),
handler: async (params) => {
const context = runtime.brain.search(params.prUrl as string, { limit: 5 });
return { summary: '...', relatedPatterns: context };
},
};
}

Register it in src/extensions/index.ts:

import { createSummarizePrOp } from './ops/summarize-pr.js';
export default function loadExtensions(runtime) {
return {
ops: [createSummarizePrOp(runtime)],
};
}

Facades are separate MCP tools. Use them to group related ops under a distinct namespace.

Terminal window
npx @soleri/cli extend add-facade github

This creates src/extensions/facades/github.ts with a facade named {agent-id}_github. Register it in src/extensions/index.ts under the facades array.

Middleware wraps all ops across all facades with before/after hooks.

Terminal window
npx @soleri/cli extend add-middleware audit-logger

Middleware follows the onion model:

  • before hooks run first → last (outermost middleware sees raw params)
  • after hooks run last → first (outermost middleware sees final result)
import type { OpMiddleware } from '@soleri/core';
export const auditLogger: OpMiddleware = {
name: 'audit-logger',
before: async (ctx) => {
console.error(`[audit] ${ctx.facade}.${ctx.op} called`);
return ctx.params;
},
after: async (ctx) => {
console.error(`[audit] ${ctx.facade}.${ctx.op} returned`);
return ctx.result;
},
};
export default function loadExtensions(runtime) {
return {
hooks: {
onStartup: async (rt) => {
// Runs after runtime init, before MCP server starts
},
onShutdown: async (rt) => {
// Runs on SIGTERM/SIGINT before process exits
},
},
};
}
FileWhy
src/index.tsRegenerated by forge on upgrades
src/activation/Managed by activation system
node_modules/@soleri/core/Overwritten by npm update

Keep all customization in src/extensions/.

Terminal window
npm update @soleri/core # Engine upgrades — your extensions are untouched
npx @soleri/cli upgrade # CLI upgrades
CommandWhat it does
npx @soleri/cli add-domain <name>Add a domain facade with 5 ops
npx @soleri/cli install-knowledge <path>Import a knowledge bundle into the vault
npx @soleri/cli hooks add-pack fullAdd quality gate hooks
npx @soleri/cli governance --preset moderateSet vault governance policy

For full command documentation, see CLI Reference. For configuration details, see Customizing Your Agent.