Cortex SDK
The official Rust SDK for building native Cortex plugins.
cortex-sdk is intentionally small: it exposes the public plugin ABI, tool traits, runtime metadata, progress hooks, and structured media attachments without depending on Cortex internal crates. A plugin built with this crate compiles to a shared library and is loaded by the Cortex daemon at startup.
What You Build
A Cortex plugin can contribute:
- Tools that the model can call during a turn.
- Skills stored as
SKILL.mdfiles. - Prompt layers loaded from a plugin
prompts/directory. - Media attachments returned from tools as image, audio, video, or file outputs.
The SDK covers the Rust side: plugin entry point, tool definitions, execution results, runtime context, and media DTOs. Packaging and installation are handled by the cortex CLI.
From Zero To Plugin
1. Install Cortex
Install Cortex first, because the CLI provides the scaffold, packer, installer, and local test surface:
|
Check the binary:
2. Scaffold A Plugin
Use the built-in scaffold command:
The generated project contains:
cortex-plugin-hello/
├── Cargo.toml
├── manifest.toml
├── src/
│ └── lib.rs
├── skills/
├── prompts/
└── README.md
The scaffold is deliberately minimal. Keep the layout, then replace the example tool with your domain-specific tools.
3. Understand Cargo.toml
A native plugin is a Rust cdylib:
[]
= "cortex-plugin-hello"
= "0.1.0"
= "2024"
[]
= ["cdylib"]
[]
= "1.0"
= "1"
Only depend on cortex-sdk for Cortex integration. Do not depend on Cortex internal crates; that would couple your plugin to runtime internals and break distribution stability.
4. Understand manifest.toml
Every plugin ships a manifest:
= "hello"
= "0.1.0"
= "Example Cortex plugin"
= "1.0.0"
[]
= ["tools", "skills"]
[]
= "lib/libcortex_plugin_hello.so"
= "cortex_plugin_create_multi"
Rules:
- The repository is usually named
cortex-plugin-{name}. - The manifest
nameis{name}without thecortex-plugin-prefix. Cargo.tomlversion andmanifest.tomlversion should match.[native].libraryis the path inside the installed plugin directory.
Minimal Tool
use *;
;
;
export_plugin!;
Runtime-Aware Tools
Use execute_with_runtime when a tool needs session metadata, progress events, observer text, or foreground/background scope:
Stateful tools should namespace state by actor or session:
Returning Media
Tools can return structured media without channel-specific code:
Ok
Cortex delivers attachments through the active client: HTTP, WebSocket, Telegram, QQ, or another transport. Plugins should not call Telegram, QQ, or browser APIs directly.
Add A Skill
Create skills/review/SKILL.md:
description: Review code changes for correctness and regressions
when_to_use: Use when the user asks for review, audit, or PR feedback.
required_tools:
- - -
${ARGS}
Find correctness issues first. Report findings with file and line references.
Skills are loaded with the plugin when manifest.toml declares skills.
Build
From the plugin repository:
For a Linux release build in Cortex's Docker environment:
Local Install
During development, install from the plugin directory:
If you staged a plugin directory manually, its shape should be:
my-plugin/
├── manifest.toml
├── lib/
│ └── libcortex_plugin_hello.so
├── skills/
└── prompts/
Package
Use the Cortex packer. Do not hand-roll .cpx archives:
The packer reads manifest.toml, resolves the native library from target/release/, and includes skills/ and prompts/ if present.
The output name is:
{repository}-v{version}-{platform}.cpx
Example:
cortex-plugin-hello-v0.1.0-linux-amd64.cpx
Publish A Plugin
Create a GitHub release and attach the .cpx asset:
Users can install latest or a pinned version:
Publish The SDK
This section is for Cortex maintainers publishing cortex-sdk itself.
Checklist:
Rules:
- The SDK must remain independent from Cortex internal crates.
- Public types should be stable DTOs or traits.
- Avoid exposing runtime internals through the SDK.
- Update this README and
docs/plugins.mdwhen the public surface changes.
Reference
Important SDK items:
| Item | Purpose |
|---|---|
MultiToolPlugin |
Plugin entry point returning metadata and tools |
Tool |
Tool interface: name, description, schema, execute |
ToolResult |
Text/error output plus optional media attachments |
ToolError |
Invalid input or execution failure |
Attachment |
Stable image/audio/video/file DTO |
InvocationContext |
Session, actor, source, and execution scope |
ToolRuntime |
Progress and observer bridge |
ToolCapabilities |
Declares progress, observer, and background safety |
PluginInfo |
Name, version, description |
export_plugin! |
Exports the FFI entry point |