-
Notifications
You must be signed in to change notification settings - Fork 5
Plugin Authoring
idapixl edited this page Mar 15, 2026
·
1 revision
Build custom plugins to extend cortex-engine with new tools.
tools-<name>/
├── src/
│ └── index.ts # Plugin definition and tool handlers
├── package.json # cortex-engine as peerDependency
├── tsconfig.json
├── README.md
└── tests/
└── index.test.ts
// src/index.ts
import type { CortexPlugin, CortexInstance } from 'cortex-engine';
export const myPlugin: CortexPlugin = {
name: 'my-plugin',
version: '0.1.0',
tools: [
{
name: 'my_custom_tool',
description: 'A tool that does something useful for the agent',
parameters: {
type: 'object',
properties: {
input: {
type: 'string',
description: 'The input to process',
},
},
required: ['input'],
},
handler: async (cortex: CortexInstance, params: { input: string }) => {
// You have full access to the cortex instance
const related = await cortex.query(params.input);
// Process and return
return {
processed: true,
related_count: related.length,
summary: `Found ${related.length} related memories`,
};
},
},
],
};{
"name": "@fozikio/tools-my-plugin",
"version": "0.1.0",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"peerDependencies": {
"cortex-engine": ">=0.4.0"
},
"scripts": {
"build": "tsc",
"test": "vitest"
}
}Plugins access Firestore through the cortex instance:
handler: async (cortex, params) => {
const db = cortex.firestore;
// Read from a custom collection
const doc = await db.collection('my_collection').doc(params.id).get();
// Write
await db.collection('my_collection').add({
content: params.input,
created_at: new Date(),
});
return { success: true };
}Follow these patterns for consistency with the official plugin ecosystem:
-
Naming:
tools-<name>for the repo,@fozikio/tools-<name>for the npm package -
Tool names: Use
snake_case— e.g.,thread_create,journal_write - Return values: Always return an object, never a bare string or number
- Descriptions: Write tool descriptions for LLMs — be clear about when to use the tool and what it returns
- Error handling: Throw descriptive errors, don't return error objects
Reference implementations to study:
| Plugin | Tools | Complexity |
|---|---|---|
| tools-vitals | 2 | Simple — good starting point |
| tools-journal | 2 | Simple — read/write pattern |
| tools-threads | 4 | Medium — CRUD with state |
| tools-graph | 4 | Advanced — graph analysis |
| tools-reasoning | 6 | Advanced — multi-step cognition |
npm run build
npm publish --access publicThen tell people to install it:
npm install @fozikio/tools-my-pluginAnd register it:
import { CortexEngine } from 'cortex-engine';
import { myPlugin } from '@fozikio/tools-my-plugin';
const cortex = new CortexEngine({
projectId: 'your-project',
plugins: [myPlugin],
});