Skip to navigation

Integration Workflow

Source-accurate setup for protocol execution
View as Markdown

1. Configure API Access

export FORBOCAI_API_URL=https://api.forboc.ai
export FORBOCAI_API_KEY=fb_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

2. Create Store and Runtime Components

import {
createSDKStore,
setNPCInfo,
processNPC,
listMemoryRemoteThunk,
validateBridgeThunk,
remoteExportSoulThunk
} from '@forbocai/core';
import { createNodeCortex } from '@forbocai/node';
const store = createSDKStore();
store.dispatch(setNPCInfo({
id: 'npc_guard_001',
persona: 'A strict city gate guard.',
initialState: { alertLevel: 0 }
}));
const cortex = createNodeCortex('smollm2-135m');
await cortex.init();

3. Run Protocol Turn

const turn = await store.dispatch(processNPC({
npcId: 'npc_guard_001',
text: 'I need entry to the city.',
context: { playerReputation: 12 },
apiUrl: process.env.FORBOCAI_API_URL || 'https://api.forboc.ai',
apiKey: process.env.FORBOCAI_API_KEY,
cortex
})).unwrap();
console.log(turn.dialogue);
console.log(turn.action);

4. Optional Remote Operations

// memory list
const memories = await store.dispatch(listMemoryRemoteThunk({
npcId: 'npc_guard_001',
apiUrl: 'https://api.forboc.ai',
apiKey: process.env.FORBOCAI_API_KEY
})).unwrap();
// bridge validate
const validation = await store.dispatch(validateBridgeThunk({
action: { type: 'OPEN_GATE' },
context: { npcState: { alertLevel: 0 } },
apiUrl: 'https://api.forboc.ai',
apiKey: process.env.FORBOCAI_API_KEY
})).unwrap();
// soul export
const soul = await store.dispatch(remoteExportSoulThunk({
npcId: 'npc_guard_001',
apiUrl: 'https://api.forboc.ai',
apiKey: process.env.FORBOCAI_API_KEY
})).unwrap();
console.log(memories.length, validation.valid, soul.txId);

5. CLI Workflow Alternative

npx forbocai config set apiUrl https://api.forboc.ai
npx forbocai config set apiKey fb_live_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
npx forbocai npc create "A strict city guard"
npx forbocai npc process <npcId> "I need entry to the city"
npx forbocai memory list <npcId>
npx forbocai soul export <npcId>