Services and dependencies
What is a service?
Section titled “What is a service?”In Harness, tools, llm, and agents are services. Each is a named capability mounted on ctx:
ctx.tools // ToolRuntime servicectx.llm // LLM servicectx.agents // Agent serviceAny plugin can provide a service for other plugins to consume.
Consume a service
Section titled “Consume a service”Declare inject to use an existing service:
export const inject = ['tools']
export function apply(ctx: Context) { // ctx.tools exists and is ready here. ctx.tools.register(/* ... */)}When apply runs, every service declared by inject is ready. If a service is not ready, the plugin waits instead of running.
Provide a service
Section titled “Provide a service”Extend Service
Section titled “Extend Service”import { Service, type Context } from '@deepseek-ai/cordis'
export default class MetricsService extends Service { static inject = ['llm'] // A service may depend on other services.
constructor(ctx: Context) { super(ctx, 'metrics') // 'metrics' is the service name. }
// Public service method. record(event: string, value: number) { // ... }}After loading this plugin, consumers access the service as ctx.metrics:
export const inject = ['metrics']
export function apply(ctx: Context) { ctx.metrics.record('tool_call', 1)}Declare its type
Section titled “Declare its type”Use TypeScript declaration merging to type ctx.metrics:
import { Service, type Context } from '@deepseek-ai/cordis'
declare module '@deepseek-ai/cordis' { interface Context { metrics: MetricsService }}
export default class MetricsService extends Service { constructor(ctx: Context) { super(ctx, 'metrics') }
record(event: string, value: number) { /* ... */ }}Dependency behavior
Section titled “Dependency behavior”Required and optional dependencies
Section titled “Required and optional dependencies”// Required: the plugin does not load while the service is absent.export const inject = ['tools']
// Optional: omit inject and query with ctx.get() at the use site.export function apply(ctx: Context) { const metrics = ctx.get('metrics') metrics?.record('plugin_loaded', 1)}When a service disappears
Section titled “When a service disappears”If a required service disappears while the application is running, for example because its provider unloads:
- Dependent plugins dispose automatically.
- They load again when the service returns.
This prevents a plugin from calling a service that no longer exists.
Service isolation
Section titled “Service isolation”cordis.yml can isolate services so separate plugin groups see separate instances of the same service:
- id: group-a name: '@deepseek-ai/cordis-plugin-group' group: true isolate: shell: true config: - name: '@deepseek-ai/dsh-bash-local' config: timeoutMs: 5000 - name: './src/plugin-a.ts'
- id: group-b name: '@deepseek-ai/cordis-plugin-group' group: true isolate: shell: true config: - name: '@deepseek-ai/dsh-bash-local' config: timeoutMs: 60000 - name: './src/plugin-b.ts'plugin-a and plugin-b each see the Bash instance in their own group, with no cross-group effect.
Built-in Harness services
Section titled “Built-in Harness services”The repository generates the service names, public methods, and source locations into each service’s subsystem page. Use those generated regions and the service’s TypeScript interface while developing a plugin; do not maintain a second static list.
Next steps
Section titled “Next steps”- Event system — communicate between plugins without tight coupling
- Capability layering — use services as capability interfaces