dcyfr.codes
beginnertypescript

Basic Delegation Contract

Delegate a task to a subagent with typed inputs, expected outputs, and a timeout. The contract is the unit of trust.

Code

import { delegate } from '@dcyfr/ai';

const result = await delegate({
  to: 'documentation-expert',
  intent: 'Generate API reference for @dcyfr/ai exports',
  inputs: {
    packagePath: './dcyfr-ai/src',
    format: 'markdown',
  },
  expectedOutputs: {
    type: 'markdown',
    minLength: 500,
  },
  timeoutMs: 30_000,
  fallbackBehavior: 'return-partial',
});

console.log(result.output);
console.log('Duration:', result.durationMs, 'ms');

How it works

The `delegate()` function sends work to a named subagent with explicit contracts. `fallbackBehavior: 'return-partial'` means if the agent times out, you get whatever it produced rather than an error — useful for non-critical documentation tasks.