OpenClaw SDK Integration
OpenClaw and similar TypeScript-based agent frameworks can use the @knowledgepulse/sdk directly for native integration. This guide demonstrates using KPCapture and KPRetrieval to add transparent knowledge capture and retrieval to any TypeScript agent.
Overview
Unlike the Python integrations that use HTTP, TypeScript frameworks benefit from direct SDK usage:
- KPCapture: wraps agent functions to automatically capture and score reasoning traces.
- KPRetrieval: searches the registry and formats results as few-shot prompts.
┌──────────────────────────────────────────┐
│ TypeScript Agent │
│ │
│ ┌────────────────────────────────────┐ │
│ │ KPCapture.wrap() │ │
│ │ (transparent trace capture) │ │
│ └──────────────┬─────────────────────┘ │
│ │ │
│ ┌──────────────▼─────────────────────┐ │
│ │ KPRetrieval.search() │ │
│ │ (few-shot knowledge injection) │ │
│ └──────────────┬─────────────────────┘ │
│ │ │
└─────────────────┼─────────────────────────┘
│
┌──────▼──────────────┐
│ KP Registry (:3000)│
└─────────────────────┘
Prerequisites
- Bun or Node.js 20+
- A running KnowledgePulse registry:
bun run registry/src/index.ts
bun add @knowledgepulse/sdk
Knowledge Capture
Wrapping an Agent Function
KPCapture.wrap() takes any async function and returns a wrapped version that automatically captures the reasoning trace when the function runs. If the trace scores above the quality threshold, it is contributed to the registry.
import { KPCapture } from "@knowledgepulse/sdk";
const capture = new KPCapture({
domain: "code_review",
visibility: "network",
valueThreshold: 0.75,
registryUrl: "http://localhost:3000",
});
// Your existing agent function
async function codeReviewAgent(codeSnippet: string): Promise<string> {
// Agent logic here...
return `Analysis complete for: ${codeSnippet}`;
}
// Wrap it — knowledge capture happens automatically
const wrappedAgent = capture.wrap(codeReviewAgent);
// Use as normal
const result = await wrappedAgent("function processData(items) { ... }");
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
domain | string | "general" | Task domain for scoring weight selection |
visibility | string | "network" | Visibility scope: "private", "org", "network" |
valueThreshold | number | 0.75 | Minimum score to contribute (0.0 -- 1.0) |
registryUrl | string |