Extending Your Agent
Questi contenuti non sono ancora disponibili nella tua lingua.
Soleri agents follow a three-layer model:
- Engine (
@soleri/core) — vault, brain, planner, curator, loops, governance. Updated vianpm update. - Agent shell (
src/index.ts) — persona, activation, domain facades. Generated by forge. - 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.
Getting started
Section titled “Getting started”If your agent was scaffolded with Soleri v5.10+, the src/extensions/ directory already exists. For older agents:
npx @soleri/cli extend initThis creates:
src/extensions/ index.ts # Extension manifest (auto-discovered at startup) ops/example.ts # Example custom op facades/ # Custom facades (empty) middleware/ # Middleware (empty)Adding custom ops
Section titled “Adding custom ops”Custom ops are merged into your agent’s core facade alongside the 200+ built-in ops.
npx @soleri/cli extend add-op summarize_prThen 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)], };}Adding custom facades
Section titled “Adding custom facades”Facades are separate MCP tools. Use them to group related ops under a distinct namespace.
npx @soleri/cli extend add-facade githubThis creates src/extensions/facades/github.ts with a facade named {agent-id}_github. Register it in src/extensions/index.ts under the facades array.
Adding middleware
Section titled “Adding middleware”Middleware wraps all ops across all facades with before/after hooks.
npx @soleri/cli extend add-middleware audit-loggerMiddleware 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; },};Lifecycle hooks
Section titled “Lifecycle hooks”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 }, }, };}What NOT to edit
Section titled “What NOT to edit”| File | Why |
|---|---|
src/index.ts | Regenerated by forge on upgrades |
src/activation/ | Managed by activation system |
node_modules/@soleri/core/ | Overwritten by npm update |
Keep all customization in src/extensions/.
Upgrading
Section titled “Upgrading”npm update @soleri/core # Engine upgrades — your extensions are untouchednpx @soleri/cli upgrade # CLI upgradesOther extension commands
Section titled “Other extension commands”| Command | What 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 full | Add quality gate hooks |
npx @soleri/cli governance --preset moderate | Set vault governance policy |
For full command documentation, see CLI Reference. For configuration details, see Customizing Your Agent.