Tutorial
SDK Installation and Usage
For programmatic access and integration into your applications, use the Perstack runtime SDK.
Step 1: Install the Runtime
npm install @perstack/runtimeStep 2: Basic Usage
Create a simple script to run an expert:
import { run } from "@perstack/runtime";
// Run an expert with minimal configuration
const result = await run({
setting: {
expertKey: "@perstack/deep-research",
input: {
text: "Research about Perstack and generate comprehensive tutorial",
},
},
});
// Access the result
const lastMessage = result.messages[result.messages.length - 1];
if (lastMessage.type === "expertMessage") {
const contents = lastMessage.contents;
for (const content of contents) {
if (content.type === "textPart") {
console.log("Result:", content.text);
}
}
}Step 3: Advanced Configuration
Configure experts with custom settings and local expert definitions:
import { run } from "@perstack/runtime";
const result = await run({
setting: {
expertKey: "my-custom-expert",
input: {
text: "Analyze this codebase and suggest improvements",
},
// Define experts inline
experts: {
"my-custom-expert": {
name: "my-custom-expert",
version: "1.0.0",
description: "Custom code analysis expert",
instruction: "Analyze code thoroughly and provide actionable suggestions",
delegates: ["@perstack/code-reviewer"],
skills: {
"file-system": {
type: "mcpStdioSkill",
command: "npx",
args: ["-y", "@perstack/mcp-filesystem"],
},
},
},
},
// Optional: Override model settings
model: "claude-3-5-sonnet-20241022",
temperature: 0.7,
maxSteps: 50,
maxRetries: 3,
},
});Step 4: Working with Checkpoints
Resume or continue from previous runs:
import { run } from "@perstack/runtime";
// Continue from the most recent run
const continued = await run({
setting: {
runId: "previous-run-id",
expertKey: "@perstack/deep-research",
input: {
text: "Add more details about implementation",
},
},
// Resume from a specific checkpoint
checkpoint: {
id: "checkpoint-id",
runId: "previous-run-id",
stepNumber: 10,
// ... other checkpoint data
},
});Step 5: Loading from perstack.toml
Use a configuration file for complex expert setups:
import { run } from "@perstack/runtime";
import { loadConfig } from "@perstack/runtime/config";
// Load expert configuration from perstack.toml
const config = await loadConfig("./perstack.toml");
const result = await run({
setting: {
expertKey: "@my-org/custom-expert",
input: {
text: "Process this request",
},
experts: config.experts,
model: config.model,
temperature: config.temperature,
},
});