Protocols
Protocols define the structure of reasoning missions. They specify the sequence of canonical algorithm steps, conditions for branching, and how artifacts and evidence are aggregated across the mission.
Protocol Definition
A protocol is a sequence of steps. Each step has a name, an action, and optional conditions. Steps can run sequentially, in parallel, or conditionally. Every step must produce artifacts and evidence according to the mission's adaptive depth.
protocol.ts typescript
import { Protocol, Rule } from '@r-think/core';
const missionProtocol = Protocol.define({
id: 'payment-investigation',
version: '1.0.0',
adaptiveDepth: 'L2',
steps: [
{
name: 'observe',
action: (ctx) => ingestTelemetry(ctx.input)
},
{
name: 'understand',
action: (ctx) => buildContext(ctx.observation),
dependsOn: ['observe']
},
{
name: 'validate',
action: (ctx) => validateEvidence(ctx.evidenceGraph),
dependsOn: ['understand']
},
{
name: 'challenge',
action: (ctx) => challengeDecision(ctx.decision),
condition: (ctx) => ctx.riskLevel === 'high'
}
],
retry: {
maxAttempts: 3,
backoff: 'exponential',
retryable: ['network', 'provider_timeout']
}
}); Protocol Types
R-Think provides three built-in protocol types:
- Sequential — Steps run in canonical order. Use when later steps depend on earlier artifacts or state.
- Parallel — Independent steps run concurrently. Use for steps that do not share state or artifact dependencies.
- Conditional — Steps are selected based on runtime conditions. Use for branching logic governed by mission state.
Step Actions
Each step has an action function. The action receives the current context and returns a result. The result becomes available to downstream steps and is captured as an artifact.
step.ts typescript
const step = {
name: 'validate',
action: async (ctx) => {
const validation = await checkEvidence(ctx.evidenceGraph);
return { passed: validation.passed, gaps: validation.gaps };
},
onSuccess: (result) => console.log('Step passed, gaps:', result.gaps),
onFailure: (error) => {
console.log('Rule violation or state error');
throw error;
}
};