@perstack/runtime 0.0.61 → 0.0.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +87 -59
- package/dist/src/index.d.ts +427 -386
- package/dist/src/index.js +776 -404
- package/dist/src/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -12,22 +12,22 @@ npm install @perstack/runtime
|
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
14
14
|
|
|
15
|
-
The primary entry point is the `run` function. It takes a `
|
|
15
|
+
The primary entry point is the `run` function. It takes a `JobSetting` object and an optional `RunOptions` object.
|
|
16
16
|
|
|
17
17
|
```typescript
|
|
18
18
|
import { run } from "@perstack/runtime"
|
|
19
|
-
import { type
|
|
19
|
+
import { type JobSetting } from "@perstack/core"
|
|
20
20
|
|
|
21
|
-
// Configure the
|
|
22
|
-
const setting:
|
|
23
|
-
|
|
21
|
+
// Configure the job
|
|
22
|
+
const setting: JobSetting = {
|
|
23
|
+
jobId: "job-123",
|
|
24
24
|
expertKey: "researcher",
|
|
25
25
|
input: { text: "Research quantum computing" },
|
|
26
26
|
// ... configuration for model, experts, etc.
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
// Execute the
|
|
30
|
-
const
|
|
29
|
+
// Execute the job
|
|
30
|
+
const finalJob = await run({ setting }, {
|
|
31
31
|
eventListener: (event) => {
|
|
32
32
|
console.log(`[${event.type}]`, event)
|
|
33
33
|
}
|
|
@@ -40,11 +40,12 @@ The `eventListener` callback receives a `RunEvent` object, which provides granul
|
|
|
40
40
|
|
|
41
41
|
```typescript
|
|
42
42
|
type RunEvent = {
|
|
43
|
-
type: EventType // e.g., "startRun", "
|
|
43
|
+
type: EventType // e.g., "startRun", "callTools"
|
|
44
44
|
id: string // Unique event ID
|
|
45
45
|
timestamp: number // Unix timestamp
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
jobId: string // ID of the Job
|
|
47
|
+
runId: string // ID of the current Run
|
|
48
|
+
stepNumber: number // Current step number within this Run
|
|
48
49
|
// ... plus payload specific to the event type
|
|
49
50
|
}
|
|
50
51
|
```
|
|
@@ -53,9 +54,9 @@ You can narrow down the event type to access specific properties:
|
|
|
53
54
|
|
|
54
55
|
```typescript
|
|
55
56
|
eventListener: (event) => {
|
|
56
|
-
if (event.type === "
|
|
57
|
-
// event is now narrowed to the
|
|
58
|
-
console.log(`Executing
|
|
57
|
+
if (event.type === "callTools") {
|
|
58
|
+
// event is now narrowed to the callTools event type
|
|
59
|
+
console.log(`Executing ${event.toolCalls.length} tools`)
|
|
59
60
|
}
|
|
60
61
|
}
|
|
61
62
|
```
|
|
@@ -72,11 +73,11 @@ eventListener: (event) => {
|
|
|
72
73
|
|
|
73
74
|
The runtime manages skills through specialized Skill Managers. Each skill type has its own manager class:
|
|
74
75
|
|
|
75
|
-
| Type | Manager | Purpose
|
|
76
|
-
| --------------- | ------------------------- |
|
|
77
|
-
| MCP (stdio/SSE) | `McpSkillManager` | External tools via MCP protocol
|
|
78
|
-
| Interactive | `InteractiveSkillManager` | User input tools (
|
|
79
|
-
| Delegate | `DelegateSkillManager` | Expert-to-Expert calls
|
|
76
|
+
| Type | Manager | Purpose |
|
|
77
|
+
| --------------- | ------------------------- | ----------------------------------- |
|
|
78
|
+
| MCP (stdio/SSE) | `McpSkillManager` | External tools via MCP protocol |
|
|
79
|
+
| Interactive | `InteractiveSkillManager` | User input tools (Coordinator only) |
|
|
80
|
+
| Delegate | `DelegateSkillManager` | Expert-to-Expert calls |
|
|
80
81
|
|
|
81
82
|
All managers extend `BaseSkillManager` which provides:
|
|
82
83
|
- `init()` — Initialize the skill (connect MCP servers, parse definitions)
|
|
@@ -84,6 +85,8 @@ All managers extend `BaseSkillManager` which provides:
|
|
|
84
85
|
- `getToolDefinitions()` — Get available tools
|
|
85
86
|
- `callTool()` — Execute a tool call
|
|
86
87
|
|
|
88
|
+
**Note:** Interactive skills are only available to the Coordinator Expert. See [Experts documentation](https://docs.perstack.ai/understanding-perstack/experts#why-no-interactive-tools-for-delegates) for details.
|
|
89
|
+
|
|
87
90
|
### Initialization Flow
|
|
88
91
|
|
|
89
92
|
```
|
|
@@ -92,7 +95,7 @@ getSkillManagers(expert, experts, setting)
|
|
|
92
95
|
├─► Initialize MCP skills (parallel)
|
|
93
96
|
│ └─► McpSkillManager × N
|
|
94
97
|
│
|
|
95
|
-
├─► Initialize Interactive skills (
|
|
98
|
+
├─► Initialize Interactive skills (Coordinator only)
|
|
96
99
|
│ └─► InteractiveSkillManager × N
|
|
97
100
|
│
|
|
98
101
|
└─► Initialize Delegate skills (parallel)
|
|
@@ -113,15 +116,20 @@ graph TD
|
|
|
113
116
|
User((User)) -->|Provides| Input[Input / Query]
|
|
114
117
|
|
|
115
118
|
subgraph Runtime [Runtime Engine]
|
|
116
|
-
subgraph
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
119
|
+
subgraph Job [Job]
|
|
120
|
+
subgraph Run1 [Run: Coordinator]
|
|
121
|
+
State[State Machine]
|
|
122
|
+
Context[Execution Context]
|
|
123
|
+
|
|
124
|
+
subgraph Skills [Skill Layer]
|
|
125
|
+
SM[Skill Manager]
|
|
126
|
+
MCP[MCP Client]
|
|
127
|
+
MCPServer[MCP Server]
|
|
128
|
+
end
|
|
124
129
|
end
|
|
130
|
+
|
|
131
|
+
Run2["Run: Delegate A"]
|
|
132
|
+
Run3["Run: Delegate B"]
|
|
125
133
|
end
|
|
126
134
|
end
|
|
127
135
|
|
|
@@ -130,8 +138,8 @@ graph TD
|
|
|
130
138
|
Workspace[Workspace / FS]
|
|
131
139
|
end
|
|
132
140
|
|
|
133
|
-
Def -->|Instantiates|
|
|
134
|
-
Input -->|Starts|
|
|
141
|
+
Def -->|Instantiates| Run1
|
|
142
|
+
Input -->|Starts| Run1
|
|
135
143
|
|
|
136
144
|
State -->|Reasoning| LLM
|
|
137
145
|
State -->|Act| SM
|
|
@@ -139,13 +147,34 @@ graph TD
|
|
|
139
147
|
MCP -->|Connect| MCPServer
|
|
140
148
|
MCPServer -->|Access| Workspace
|
|
141
149
|
|
|
142
|
-
SM -.->|Delegate|
|
|
143
|
-
|
|
144
|
-
State ~~~ Context
|
|
150
|
+
SM -.->|Delegate| Run2
|
|
151
|
+
SM -.->|Delegate| Run3
|
|
145
152
|
```
|
|
146
153
|
|
|
147
154
|
## Core Concepts
|
|
148
155
|
|
|
156
|
+
### Execution Hierarchy
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
Job (jobId)
|
|
160
|
+
├── Run 1 (Coordinator Expert)
|
|
161
|
+
│ └── Checkpoints...
|
|
162
|
+
├── Run 2 (Delegated Expert A)
|
|
163
|
+
│ └── Checkpoints...
|
|
164
|
+
└── Run 3 (Delegated Expert B)
|
|
165
|
+
└── Checkpoints...
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
| Concept | Description |
|
|
169
|
+
| -------------- | -------------------------------------------- |
|
|
170
|
+
| **Job** | Top-level execution unit. Contains all Runs. |
|
|
171
|
+
| **Run** | Single Expert execution. |
|
|
172
|
+
| **Checkpoint** | Snapshot at step end. Enables pause/resume. |
|
|
173
|
+
|
|
174
|
+
For details on step counting, Coordinator vs. Delegated Expert differences, and the full execution model, see [Runtime](https://docs.perstack.ai/understanding-perstack/runtime).
|
|
175
|
+
|
|
176
|
+
### Events, Steps, Checkpoints
|
|
177
|
+
|
|
149
178
|
The runtime's execution model can be visualized as a timeline where **Events** are points, **Steps** are the lines connecting them, and **Checkpoints** are the anchors.
|
|
150
179
|
|
|
151
180
|
```mermaid
|
|
@@ -164,13 +193,13 @@ graph LR
|
|
|
164
193
|
style CP2 fill:#f96,stroke:#333,stroke-width:4px
|
|
165
194
|
```
|
|
166
195
|
|
|
167
|
-
|
|
196
|
+
#### 1. Events
|
|
168
197
|
**Events** are granular moments in time that occur *during* execution. They represent specific actions or observations, such as "started reasoning", "called tool", or "finished tool".
|
|
169
198
|
|
|
170
|
-
|
|
199
|
+
#### 2. Step
|
|
171
200
|
A **Step** is the continuous process that connects these events. It represents one atomic cycle of the agent's loop (Reasoning -> Act -> Observe, repeat).
|
|
172
201
|
|
|
173
|
-
|
|
202
|
+
#### 3. Checkpoint
|
|
174
203
|
A **Checkpoint** is the immutable result at the end of a Step. It serves as the anchor point that:
|
|
175
204
|
- Finalizes the previous Step.
|
|
176
205
|
- Becomes the starting point for the next Step.
|
|
@@ -185,22 +214,20 @@ stateDiagram-v2
|
|
|
185
214
|
[*] --> Init
|
|
186
215
|
Init --> PreparingForStep: startRun
|
|
187
216
|
PreparingForStep --> GeneratingToolCall: startGeneration
|
|
217
|
+
PreparingForStep --> CallingTools: resumeToolCalls
|
|
218
|
+
PreparingForStep --> FinishingStep: finishAllToolCalls
|
|
188
219
|
|
|
189
|
-
GeneratingToolCall -->
|
|
190
|
-
GeneratingToolCall --> CallingInteractiveTool: callInteractiveTool
|
|
191
|
-
GeneratingToolCall --> CallingDelegate: callDelegate
|
|
220
|
+
GeneratingToolCall --> CallingTools: callTools
|
|
192
221
|
GeneratingToolCall --> FinishingStep: retry
|
|
193
222
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
223
|
+
CallingTools --> ResolvingToolResults: resolveToolResults
|
|
224
|
+
CallingTools --> ResolvingThought: resolveThought
|
|
225
|
+
CallingTools --> GeneratingRunResult: attemptCompletion
|
|
226
|
+
CallingTools --> CallingDelegate: callDelegates
|
|
227
|
+
CallingTools --> CallingInteractiveTool: callInteractiveTool
|
|
199
228
|
|
|
200
|
-
|
|
229
|
+
ResolvingToolResults --> FinishingStep: finishToolCall
|
|
201
230
|
ResolvingThought --> FinishingStep: finishToolCall
|
|
202
|
-
ResolvingPdfFile --> FinishingStep: finishToolCall
|
|
203
|
-
ResolvingImageFile --> FinishingStep: finishToolCall
|
|
204
231
|
|
|
205
232
|
GeneratingRunResult --> Stopped: completeRun
|
|
206
233
|
GeneratingRunResult --> FinishingStep: retry
|
|
@@ -216,25 +243,26 @@ stateDiagram-v2
|
|
|
216
243
|
Events trigger state transitions. They are emitted by the runtime logic or external inputs.
|
|
217
244
|
|
|
218
245
|
- **Lifecycle**: `startRun`, `startGeneration`, `continueToNextStep`, `completeRun`
|
|
219
|
-
- **Tool Execution**: `
|
|
220
|
-
- **Special Types**: `resolveThought
|
|
246
|
+
- **Tool Execution**: `callTools`, `resolveToolResults`, `finishToolCall`, `resumeToolCalls`, `finishAllToolCalls`
|
|
247
|
+
- **Special Types**: `resolveThought`
|
|
248
|
+
- **Delegation**: `callDelegate` (triggers new Run(s) for delegate(s), parallel when multiple)
|
|
249
|
+
- **Interactive**: `callInteractiveTool` (Coordinator only)
|
|
221
250
|
- **Interruption**: `stopRunByInteractiveTool`, `stopRunByDelegate`, `stopRunByExceededMaxSteps`
|
|
222
251
|
- **Error Handling**: `retry`
|
|
223
252
|
|
|
224
253
|
## Checkpoint Status
|
|
225
254
|
|
|
226
|
-
The `status` field in a Checkpoint indicates the current state
|
|
255
|
+
The `status` field in a Checkpoint indicates the current state:
|
|
227
256
|
|
|
228
|
-
-
|
|
229
|
-
-
|
|
230
|
-
-
|
|
231
|
-
-
|
|
232
|
-
- **stoppedByDelegate**: The run is paused, waiting for a delegated sub-agent to complete.
|
|
233
|
-
- **stoppedByExceededMaxSteps**: The run stopped because it reached the maximum allowed steps.
|
|
234
|
-
- **stoppedByError**: The run stopped due to an unrecoverable error.
|
|
257
|
+
- `init`, `proceeding` — Run lifecycle
|
|
258
|
+
- `completed` — Task finished successfully
|
|
259
|
+
- `stoppedByInteractiveTool`, `stoppedByDelegate` — Waiting for external input
|
|
260
|
+
- `stoppedByExceededMaxSteps`, `stoppedByError` — Run stopped
|
|
235
261
|
|
|
236
|
-
|
|
262
|
+
For stop reasons and error handling, see [Error Handling](https://docs.perstack.ai/using-experts/error-handling).
|
|
237
263
|
|
|
238
|
-
|
|
239
|
-
- [State Management](https://perstack.ai/docs/using-experts/state-management) - Understanding checkpoints and state
|
|
264
|
+
## Related Documentation
|
|
240
265
|
|
|
266
|
+
- [Runtime](https://docs.perstack.ai/understanding-perstack/runtime) — Full execution model
|
|
267
|
+
- [State Management](https://docs.perstack.ai/using-experts/state-management) — Jobs, Runs, and Checkpoints
|
|
268
|
+
- [Running Experts](https://docs.perstack.ai/using-experts/running-experts) — CLI usage
|