@mastra/core 1.5.0 → 1.6.0
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/CHANGELOG.md +386 -0
- package/dist/agent/index.cjs +13 -13
- package/dist/agent/index.js +2 -2
- package/dist/agent/message-list/adapters/AIV5Adapter.d.ts.map +1 -1
- package/dist/agent/message-list/conversion/output-converter.d.ts.map +1 -1
- package/dist/agent/message-list/index.cjs +18 -18
- package/dist/agent/message-list/index.js +1 -1
- package/dist/agent/workflows/prepare-stream/index.d.ts +7 -7
- package/dist/agent/workflows/prepare-stream/prepare-memory-step.d.ts +7 -7
- package/dist/agent/workflows/prepare-stream/schema.d.ts +11 -11
- package/dist/{chunk-CQ4Z6ZAV.cjs → chunk-3U3XFMGJ.cjs} +7 -7
- package/dist/{chunk-CQ4Z6ZAV.cjs.map → chunk-3U3XFMGJ.cjs.map} +1 -1
- package/dist/{chunk-D57U4II4.js → chunk-4WG5K4CK.js} +9 -8
- package/dist/chunk-4WG5K4CK.js.map +1 -0
- package/dist/{chunk-UZFGMMKU.js → chunk-5K45E5VE.js} +37 -3
- package/dist/chunk-5K45E5VE.js.map +1 -0
- package/dist/{chunk-OQ5LZ6OV.cjs → chunk-5VQPSWPG.cjs} +149 -61
- package/dist/chunk-5VQPSWPG.cjs.map +1 -0
- package/dist/{chunk-AIRMLZ43.js → chunk-7EXW4AAG.js} +4 -4
- package/dist/{chunk-AIRMLZ43.js.map → chunk-7EXW4AAG.js.map} +1 -1
- package/dist/{chunk-S4VVZI4E.cjs → chunk-AYHSPIT6.cjs} +326 -5
- package/dist/chunk-AYHSPIT6.cjs.map +1 -0
- package/dist/{chunk-YW54RH77.cjs → chunk-DB7U2C5B.cjs} +12 -5
- package/dist/chunk-DB7U2C5B.cjs.map +1 -0
- package/dist/{chunk-DST75PA4.js → chunk-DGS2KGDI.js} +4 -4
- package/dist/{chunk-DST75PA4.js.map → chunk-DGS2KGDI.js.map} +1 -1
- package/dist/{chunk-YIN5F7VO.js → chunk-EEU5NHHU.js} +4254 -3958
- package/dist/chunk-EEU5NHHU.js.map +1 -0
- package/dist/{chunk-A6EWCOGA.cjs → chunk-H5S4PS44.cjs} +197 -27
- package/dist/chunk-H5S4PS44.cjs.map +1 -0
- package/dist/{chunk-3YMDR4OL.cjs → chunk-HTAUP7ER.cjs} +4 -4
- package/dist/{chunk-3YMDR4OL.cjs.map → chunk-HTAUP7ER.cjs.map} +1 -1
- package/dist/{chunk-OHLVZVIK.js → chunk-IC5OUWKJ.js} +12 -5
- package/dist/chunk-IC5OUWKJ.js.map +1 -0
- package/dist/{chunk-MZIMV2BB.js → chunk-IHDE4CJV.js} +244 -213
- package/dist/chunk-IHDE4CJV.js.map +1 -0
- package/dist/{chunk-3KJW4EMO.js → chunk-IHEYJDJP.js} +3 -3
- package/dist/{chunk-3KJW4EMO.js.map → chunk-IHEYJDJP.js.map} +1 -1
- package/dist/{chunk-CXVMDV2B.js → chunk-IOY7Y5GV.js} +197 -27
- package/dist/chunk-IOY7Y5GV.js.map +1 -0
- package/dist/{chunk-MDC6VYA6.cjs → chunk-KAVAKMOQ.cjs} +4 -8
- package/dist/chunk-KAVAKMOQ.cjs.map +1 -0
- package/dist/{chunk-7WC7ALDW.cjs → chunk-LNKS4TJ6.cjs} +6 -6
- package/dist/{chunk-7WC7ALDW.cjs.map → chunk-LNKS4TJ6.cjs.map} +1 -1
- package/dist/{chunk-R3364RAL.js → chunk-MWGGSA5Q.js} +4 -4
- package/dist/{chunk-R3364RAL.js.map → chunk-MWGGSA5Q.js.map} +1 -1
- package/dist/{chunk-QSN5KQXZ.cjs → chunk-O7PZ4VOO.cjs} +11 -11
- package/dist/{chunk-QSN5KQXZ.cjs.map → chunk-O7PZ4VOO.cjs.map} +1 -1
- package/dist/chunk-OQDRPRKM.cjs +46 -0
- package/dist/chunk-OQDRPRKM.cjs.map +1 -0
- package/dist/{chunk-YV2YGQRY.js → chunk-RHKNKJNM.js} +101 -13
- package/dist/chunk-RHKNKJNM.js.map +1 -0
- package/dist/{chunk-TPDMP7OD.js → chunk-RHYZ6CQN.js} +4 -8
- package/dist/chunk-RHYZ6CQN.js.map +1 -0
- package/dist/{chunk-G5JVVFIG.cjs → chunk-RZNHRIM7.cjs} +9 -9
- package/dist/{chunk-G5JVVFIG.cjs.map → chunk-RZNHRIM7.cjs.map} +1 -1
- package/dist/{chunk-JZ6TH4HQ.cjs → chunk-TL2TTA4X.cjs} +4260 -3962
- package/dist/chunk-TL2TTA4X.cjs.map +1 -0
- package/dist/{chunk-KNXZ7KYL.cjs → chunk-TVPANHLE.cjs} +40 -2
- package/dist/chunk-TVPANHLE.cjs.map +1 -0
- package/dist/{chunk-7S6LA43E.cjs → chunk-VJWRJWSC.cjs} +278 -248
- package/dist/chunk-VJWRJWSC.cjs.map +1 -0
- package/dist/chunk-X2HAI3OX.js +39 -0
- package/dist/chunk-X2HAI3OX.js.map +1 -0
- package/dist/{chunk-FZ5DRHKE.js → chunk-XB3DA67Q.js} +325 -5
- package/dist/chunk-XB3DA67Q.js.map +1 -0
- package/dist/{chunk-NUV3BLRH.cjs → chunk-XWZAKKFT.cjs} +17 -16
- package/dist/chunk-XWZAKKFT.cjs.map +1 -0
- package/dist/{chunk-4GB2GS4S.js → chunk-YM6245EM.js} +5 -5
- package/dist/{chunk-4GB2GS4S.js.map → chunk-YM6245EM.js.map} +1 -1
- package/dist/datasets/index.cjs +17 -17
- package/dist/datasets/index.js +2 -2
- package/dist/docs/SKILL.md +2 -1
- package/dist/docs/assets/SOURCE_MAP.json +417 -391
- package/dist/docs/references/docs-memory-observational-memory.md +2 -0
- package/dist/docs/references/docs-streaming-tool-streaming.md +6 -0
- package/dist/docs/references/docs-workspace-filesystem.md +21 -1
- package/dist/docs/references/reference-harness-harness-class.md +645 -0
- package/dist/docs/references/reference-memory-memory-class.md +1 -1
- package/dist/docs/references/reference-memory-observational-memory.md +1 -0
- package/dist/docs/references/reference-workspace-local-filesystem.md +25 -0
- package/dist/docs/references/reference-workspace-workspace-class.md +1 -24
- package/dist/docs/references/reference.md +1 -0
- package/dist/editor/types.d.ts +20 -1
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/evals/base.d.ts.map +1 -1
- package/dist/evals/index.cjs +20 -20
- package/dist/evals/index.js +3 -3
- package/dist/evals/scoreTraces/index.cjs +5 -5
- package/dist/evals/scoreTraces/index.js +2 -2
- package/dist/events/index.cjs +6 -2
- package/dist/events/index.d.ts +1 -0
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +1 -1
- package/dist/harness/harness.d.ts +105 -35
- package/dist/harness/harness.d.ts.map +1 -1
- package/dist/harness/index.cjs +472 -64
- package/dist/harness/index.cjs.map +1 -1
- package/dist/harness/index.d.ts +2 -1
- package/dist/harness/index.d.ts.map +1 -1
- package/dist/harness/index.js +468 -62
- package/dist/harness/index.js.map +1 -1
- package/dist/harness/tools.d.ts +38 -0
- package/dist/harness/tools.d.ts.map +1 -1
- package/dist/harness/types.d.ts +64 -9
- package/dist/harness/types.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +1 -1
- package/dist/llm/index.cjs +12 -12
- package/dist/llm/index.js +3 -3
- package/dist/llm/model/gateways/models-dev.d.ts.map +1 -1
- package/dist/loop/index.cjs +12 -12
- package/dist/loop/index.js +1 -1
- package/dist/loop/network/index.d.ts +6 -6
- package/dist/loop/network/index.d.ts.map +1 -1
- package/dist/loop/test-utils/options.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/index.d.ts +21 -21
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts +14 -14
- package/dist/loop/workflows/agentic-execution/llm-execution-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts +7 -7
- package/dist/loop/workflows/agentic-execution/llm-mapping-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-execution/tool-call-step.d.ts.map +1 -1
- package/dist/loop/workflows/agentic-loop/index.d.ts +21 -21
- package/dist/loop/workflows/agentic-loop/index.d.ts.map +1 -1
- package/dist/loop/workflows/schema.d.ts +30 -30
- package/dist/loop/workflows/stream.d.ts +0 -13
- package/dist/loop/workflows/stream.d.ts.map +1 -1
- package/dist/mastra/index.cjs +2 -2
- package/dist/mastra/index.js +1 -1
- package/dist/memory/index.cjs +14 -14
- package/dist/memory/index.js +1 -1
- package/dist/models-dev-6P4CM74H.js +3 -0
- package/dist/{models-dev-MDI5E2YA.js.map → models-dev-6P4CM74H.js.map} +1 -1
- package/dist/models-dev-CLLSNT5L.cjs +12 -0
- package/dist/{models-dev-BW2GAM3K.cjs.map → models-dev-CLLSNT5L.cjs.map} +1 -1
- package/dist/processor-provider/index.cjs +256 -0
- package/dist/processor-provider/index.cjs.map +1 -0
- package/dist/processor-provider/index.d.ts +5 -0
- package/dist/processor-provider/index.d.ts.map +1 -0
- package/dist/processor-provider/index.js +243 -0
- package/dist/processor-provider/index.js.map +1 -0
- package/dist/processor-provider/phase-filtered-processor.d.ts +22 -0
- package/dist/processor-provider/phase-filtered-processor.d.ts.map +1 -0
- package/dist/processor-provider/providers/index.d.ts +12 -0
- package/dist/processor-provider/providers/index.d.ts.map +1 -0
- package/dist/processor-provider/types.d.ts +65 -0
- package/dist/processor-provider/types.d.ts.map +1 -0
- package/dist/processors/index.cjs +41 -41
- package/dist/processors/index.js +1 -1
- package/dist/processors/memory/message-history.d.ts.map +1 -1
- package/dist/processors/step-schema.d.ts +14 -14
- package/dist/provider-registry-HMTFO5FV.cjs +40 -0
- package/dist/{provider-registry-4PH2JPIA.cjs.map → provider-registry-HMTFO5FV.cjs.map} +1 -1
- package/dist/provider-registry-TTZ2WN2P.js +3 -0
- package/dist/{provider-registry-VEJ3PN4S.js.map → provider-registry-TTZ2WN2P.js.map} +1 -1
- package/dist/relevance/index.cjs +3 -3
- package/dist/relevance/index.js +1 -1
- package/dist/storage/base.d.ts +2 -1
- package/dist/storage/base.d.ts.map +1 -1
- package/dist/storage/constants.cjs +68 -52
- package/dist/storage/constants.d.ts +6 -2
- package/dist/storage/constants.d.ts.map +1 -1
- package/dist/storage/constants.js +1 -1
- package/dist/storage/domains/index.d.ts +1 -0
- package/dist/storage/domains/index.d.ts.map +1 -1
- package/dist/storage/domains/inmemory-db.d.ts +4 -1
- package/dist/storage/domains/inmemory-db.d.ts.map +1 -1
- package/dist/storage/domains/mcp-servers/base.d.ts +47 -0
- package/dist/storage/domains/mcp-servers/base.d.ts.map +1 -0
- package/dist/storage/domains/mcp-servers/index.d.ts +3 -0
- package/dist/storage/domains/mcp-servers/index.d.ts.map +1 -0
- package/dist/storage/domains/mcp-servers/inmemory.d.ts +31 -0
- package/dist/storage/domains/mcp-servers/inmemory.d.ts.map +1 -0
- package/dist/storage/domains/memory/inmemory.d.ts.map +1 -1
- package/dist/storage/domains/observability/types.d.ts +44 -44
- package/dist/storage/domains/operations/inmemory.d.ts.map +1 -1
- package/dist/storage/index.cjs +178 -154
- package/dist/storage/index.js +2 -2
- package/dist/storage/mock.d.ts.map +1 -1
- package/dist/storage/types.d.ts +220 -6
- package/dist/storage/types.d.ts.map +1 -1
- package/dist/stream/MastraAgentNetworkStream.d.ts +1 -1
- package/dist/stream/MastraWorkflowStream.d.ts +1 -1
- package/dist/stream/aisdk/v5/input.d.ts.map +1 -1
- package/dist/stream/base/input.d.ts +19 -0
- package/dist/stream/base/input.d.ts.map +1 -1
- package/dist/stream/base/output.d.ts.map +1 -1
- package/dist/stream/index.cjs +11 -11
- package/dist/stream/index.js +2 -2
- package/dist/tool-loop-agent/index.cjs +4 -4
- package/dist/tool-loop-agent/index.js +1 -1
- package/dist/vector/index.cjs +9 -9
- package/dist/vector/index.js +2 -2
- package/dist/workflows/evented/execution-engine.d.ts.map +1 -1
- package/dist/workflows/evented/index.cjs +10 -10
- package/dist/workflows/evented/index.js +1 -1
- package/dist/workflows/evented/step-executor.d.ts.map +1 -1
- package/dist/workflows/evented/workflow-event-processor/index.d.ts.map +1 -1
- package/dist/workflows/index.cjs +25 -25
- package/dist/workflows/index.js +1 -1
- package/dist/workflows/step.d.ts.map +1 -1
- package/dist/workspace/constants/index.d.ts +1 -0
- package/dist/workspace/constants/index.d.ts.map +1 -1
- package/dist/workspace/index.cjs +64 -64
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/tools/ast-edit.d.ts +97 -0
- package/dist/workspace/tools/ast-edit.d.ts.map +1 -0
- package/dist/workspace/tools/search.d.ts +1 -1
- package/dist/workspace/tools/tools.d.ts.map +1 -1
- package/package.json +12 -11
- package/processor-provider.d.ts +1 -0
- package/dist/chunk-4D4KB75Y.cjs +0 -9
- package/dist/chunk-4D4KB75Y.cjs.map +0 -1
- package/dist/chunk-7S6LA43E.cjs.map +0 -1
- package/dist/chunk-A6EWCOGA.cjs.map +0 -1
- package/dist/chunk-BVUMKER5.js +0 -7
- package/dist/chunk-BVUMKER5.js.map +0 -1
- package/dist/chunk-CXVMDV2B.js.map +0 -1
- package/dist/chunk-D57U4II4.js.map +0 -1
- package/dist/chunk-FZ5DRHKE.js.map +0 -1
- package/dist/chunk-JZ6TH4HQ.cjs.map +0 -1
- package/dist/chunk-KNXZ7KYL.cjs.map +0 -1
- package/dist/chunk-MDC6VYA6.cjs.map +0 -1
- package/dist/chunk-MZIMV2BB.js.map +0 -1
- package/dist/chunk-NUV3BLRH.cjs.map +0 -1
- package/dist/chunk-OHLVZVIK.js.map +0 -1
- package/dist/chunk-OQ5LZ6OV.cjs.map +0 -1
- package/dist/chunk-S4VVZI4E.cjs.map +0 -1
- package/dist/chunk-TPDMP7OD.js.map +0 -1
- package/dist/chunk-UZFGMMKU.js.map +0 -1
- package/dist/chunk-YIN5F7VO.js.map +0 -1
- package/dist/chunk-YV2YGQRY.js.map +0 -1
- package/dist/chunk-YW54RH77.cjs.map +0 -1
- package/dist/models-dev-BW2GAM3K.cjs +0 -12
- package/dist/models-dev-MDI5E2YA.js +0 -3
- package/dist/provider-registry-4PH2JPIA.cjs +0 -40
- package/dist/provider-registry-VEJ3PN4S.js +0 -3
|
@@ -180,6 +180,8 @@ As the agent converses, message tokens accumulate. At regular intervals (`buffer
|
|
|
180
180
|
|
|
181
181
|
When message tokens reach the `messageTokens` threshold, buffered chunks activate: their observations move into the active observation log, and the corresponding raw messages are removed from the context window. The agent never pauses.
|
|
182
182
|
|
|
183
|
+
Buffered observations also include continuation hints — a suggested next response and the current task — so the main agent maintains conversational continuity after activation shrinks the context window.
|
|
184
|
+
|
|
183
185
|
If the agent produces messages faster than the Observer can process them, a `blockAfter` safety threshold forces a synchronous observation as a last resort.
|
|
184
186
|
|
|
185
187
|
Reflection works similarly — the Reflector runs in the background when observations reach a fraction of the reflection threshold.
|
|
@@ -147,6 +147,12 @@ export const weatherTool = createTool({
|
|
|
147
147
|
|
|
148
148
|
For detailed documentation on all lifecycle hooks, see the [createTool() reference](https://mastra.ai/reference/tools/create-tool).
|
|
149
149
|
|
|
150
|
+
### Streaming tool input in UIs
|
|
151
|
+
|
|
152
|
+
When a model generates a tool call, the arguments arrive incrementally as `tool-call-delta` stream chunks before the final `tool-call` chunk. UIs can listen for the corresponding `tool_input_start`, `tool_input_delta`, and `tool_input_end` events to render tool arguments as they stream in — for example, showing a file path or command immediately rather than waiting for the complete tool call.
|
|
153
|
+
|
|
154
|
+
Using a partial JSON parser on the accumulated `argsTextDelta` fragments lets you extract usable argument values before the JSON is complete. This enables features like live diff previews for edit tools, streaming file content for write tools, and instant display of search patterns or file paths.
|
|
155
|
+
|
|
150
156
|
## Tool using an agent
|
|
151
157
|
|
|
152
158
|
Pipe an agent's `fullStream` to the tool's `writer`. This streams partial output, and Mastra automatically aggregates the agent's usage into the tool run.
|
|
@@ -53,7 +53,27 @@ By default, `LocalFilesystem` runs in **contained mode** — all file operations
|
|
|
53
53
|
|
|
54
54
|
In contained mode, absolute paths that fall within `basePath` are used as-is, while other absolute paths are treated as virtual paths relative to `basePath` (e.g. `/file.txt` resolves to `basePath/file.txt`). Any resolved path that escapes `basePath` throws a `PermissionError`.
|
|
55
55
|
|
|
56
|
-
If your agent needs to access paths outside `basePath
|
|
56
|
+
If your agent needs to access specific paths outside `basePath`, use `allowedPaths` to grant access without disabling containment entirely:
|
|
57
|
+
|
|
58
|
+
```typescript
|
|
59
|
+
const workspace = new Workspace({
|
|
60
|
+
filesystem: new LocalFilesystem({
|
|
61
|
+
basePath: './workspace',
|
|
62
|
+
allowedPaths: ['/home/user/.config', '/home/user/documents'],
|
|
63
|
+
}),
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Allowed paths can be updated at runtime using the `setAllowedPaths()` method:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
// Add a path dynamically
|
|
71
|
+
workspace.filesystem.setAllowedPaths(prev => [...prev, '/home/user/documents']);
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
This is the recommended approach for least-privilege access — the agent can only reach the specific directories you allow.
|
|
75
|
+
|
|
76
|
+
If your agent needs unrestricted access to the entire filesystem, disable containment:
|
|
57
77
|
|
|
58
78
|
```typescript
|
|
59
79
|
const workspace = new Workspace({
|
|
@@ -0,0 +1,645 @@
|
|
|
1
|
+
# Harness Class
|
|
2
|
+
|
|
3
|
+
**Added in:** `@mastra/core@1.1.0`
|
|
4
|
+
|
|
5
|
+
The `Harness` class orchestrates multiple agent modes, shared state, memory, and storage. It provides a control layer that a TUI or other UI can drive to manage threads, switch models and modes, send messages, handle tool approvals, and track events.
|
|
6
|
+
|
|
7
|
+
## Usage example
|
|
8
|
+
|
|
9
|
+
```typescript
|
|
10
|
+
import { Harness } from '@mastra/core/harness';
|
|
11
|
+
import { LibSQLStore } from '@mastra/libsql';
|
|
12
|
+
import { z } from 'zod';
|
|
13
|
+
|
|
14
|
+
const harness = new Harness({
|
|
15
|
+
id: 'my-coding-agent',
|
|
16
|
+
storage: new LibSQLStore({ url: 'file:./data.db' }),
|
|
17
|
+
stateSchema: z.object({
|
|
18
|
+
currentModelId: z.string().optional(),
|
|
19
|
+
}),
|
|
20
|
+
modes: [
|
|
21
|
+
{ id: 'plan', name: 'Plan', default: true, agent: planAgent },
|
|
22
|
+
{ id: 'build', name: 'Build', agent: buildAgent },
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
harness.subscribe((event) => {
|
|
27
|
+
if (event.type === 'message_update') {
|
|
28
|
+
renderMessage(event.message);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
await harness.init();
|
|
33
|
+
await harness.selectOrCreateThread();
|
|
34
|
+
await harness.sendMessage({ content: 'Hello!' });
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Constructor parameters
|
|
38
|
+
|
|
39
|
+
**id:** (`string`): Unique identifier for this harness instance.
|
|
40
|
+
|
|
41
|
+
**resourceId?:** (`string`): Resource ID for grouping threads (e.g., project identifier). Threads are scoped to this resource ID. Defaults to \`id\`.
|
|
42
|
+
|
|
43
|
+
**storage?:** (`MastraCompositeStore`): Storage backend for persistence (threads, messages, state).
|
|
44
|
+
|
|
45
|
+
**stateSchema?:** (`z.ZodObject`): Zod schema defining the shape of harness state. Used for validation and extracting defaults.
|
|
46
|
+
|
|
47
|
+
**initialState?:** (`Partial<z.infer<TState>>`): Initial state values. Must conform to the schema if provided.
|
|
48
|
+
|
|
49
|
+
**memory?:** (`MastraMemory`): Memory configuration shared across all modes. Propagated to mode agents that don't have their own memory.
|
|
50
|
+
|
|
51
|
+
**modes:** (`HarnessMode[]`): Available agent modes. At least one mode is required. Each mode defines an agent and optional defaults.
|
|
52
|
+
|
|
53
|
+
**tools?:** (`ToolsInput | ((ctx) => ToolsInput)`): Tools available to all agents across all modes. It can be a static tools object or a dynamic function that receives the request context.
|
|
54
|
+
|
|
55
|
+
**workspace?:** (`Workspace | WorkspaceConfig | ((ctx) => Workspace)`): Workspace configuration. Accepts a pre-constructed Workspace, a WorkspaceConfig for the harness to construct internally, or a dynamic factory function.
|
|
56
|
+
|
|
57
|
+
**subagents?:** (`HarnessSubagent[]`): Subagent definitions. When provided, the harness creates a built-in \`subagent\` tool that parent agents can call to spawn focused subagents.
|
|
58
|
+
|
|
59
|
+
**resolveModel?:** (`(modelId: string) => MastraLanguageModel`): Converts a model ID string (e.g., \`"anthropic/claude-sonnet-4"\`) to a language model instance. Used by subagents and observational memory model resolution.
|
|
60
|
+
|
|
61
|
+
**omConfig?:** (`HarnessOMConfig`): Default configuration for observational memory (observer/reflector model IDs and thresholds).
|
|
62
|
+
|
|
63
|
+
**heartbeatHandlers?:** (`HeartbeatHandler[]`): Periodic background tasks started during \`init()\`. Use for gateway sync, cache refresh, and similar tasks.
|
|
64
|
+
|
|
65
|
+
**idGenerator?:** (`() => string`): Custom ID generator for threads, messages, and other entities. (Default: `timestamp + random string`)
|
|
66
|
+
|
|
67
|
+
**modelAuthChecker?:** (`ModelAuthChecker`): Custom auth checker for model providers. Return \`true\`/\`false\` to override the default environment variable check, or \`undefined\` to fall back to defaults.
|
|
68
|
+
|
|
69
|
+
**modelUseCountProvider?:** (`ModelUseCountProvider`): Provides per-model use counts for sorting and display in \`listAvailableModels()\`.
|
|
70
|
+
|
|
71
|
+
**toolCategoryResolver?:** (`(toolName: string) => ToolCategory | null`): Maps tool names to permission categories (\`'read'\`, \`'edit'\`, \`'execute'\`, \`'mcp'\`, \`'other'\`). Used by the permission system to resolve category-level policies.
|
|
72
|
+
|
|
73
|
+
**threadLock?:** (`{ acquire, release }`): Thread locking callbacks to prevent concurrent access from multiple processes. \`acquire\` should throw if the lock is held.
|
|
74
|
+
|
|
75
|
+
### HarnessMode
|
|
76
|
+
|
|
77
|
+
Each entry in the `modes` array configures a single agent mode.
|
|
78
|
+
|
|
79
|
+
**id:** (`string`): Unique identifier for this mode (e.g., \`"plan"\`, \`"build"\`).
|
|
80
|
+
|
|
81
|
+
**name?:** (`string`): Human-readable name for display.
|
|
82
|
+
|
|
83
|
+
**default?:** (`boolean`): Whether this is the default mode when the harness starts. (Default: `false`)
|
|
84
|
+
|
|
85
|
+
**defaultModelId?:** (`string`): Default model ID for this mode (e.g., \`"anthropic/claude-sonnet-4-20250514"\`). Used when no per-mode model has been explicitly selected.
|
|
86
|
+
|
|
87
|
+
**color?:** (`string`): Hex color for the mode indicator (e.g., \`"#7c3aed"\`).
|
|
88
|
+
|
|
89
|
+
**agent:** (`Agent | ((state) => Agent)`): The agent for this mode. It can be a static Agent instance or a function that receives harness state and returns an Agent.
|
|
90
|
+
|
|
91
|
+
### HarnessSubagent
|
|
92
|
+
|
|
93
|
+
Each entry in the `subagents` array defines a subagent the harness can spawn.
|
|
94
|
+
|
|
95
|
+
**id:** (`string`): Unique identifier for this subagent type (e.g., \`"explore"\`, \`"execute"\`).
|
|
96
|
+
|
|
97
|
+
**name:** (`string`): Human-readable name shown in tool output.
|
|
98
|
+
|
|
99
|
+
**description:** (`string`): Description of what this subagent does. Used in the auto-generated tool description.
|
|
100
|
+
|
|
101
|
+
**instructions:** (`string`): System prompt for this subagent.
|
|
102
|
+
|
|
103
|
+
**tools?:** (`ToolsInput`): Tools this subagent has direct access to.
|
|
104
|
+
|
|
105
|
+
**allowedHarnessTools?:** (`string[]`): Tool IDs from the harness's shared \`tools\` config. Merged with \`tools\` above to let subagents use a subset of harness tools.
|
|
106
|
+
|
|
107
|
+
**defaultModelId?:** (`string`): Default model ID for this subagent type.
|
|
108
|
+
|
|
109
|
+
## Properties
|
|
110
|
+
|
|
111
|
+
**id:** (`string`): Harness identifier, set at construction.
|
|
112
|
+
|
|
113
|
+
## Methods
|
|
114
|
+
|
|
115
|
+
### Lifecycle
|
|
116
|
+
|
|
117
|
+
#### `init()`
|
|
118
|
+
|
|
119
|
+
Initialize the harness. Loads storage, initializes the workspace, propagates memory and workspace to mode agents, and starts heartbeat handlers. Call this before using the harness.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
await harness.init();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### `selectOrCreateThread()`
|
|
126
|
+
|
|
127
|
+
Select the most recent thread for the current resource, or create one if none exist. Loads thread metadata and acquires a thread lock.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
const thread = await harness.selectOrCreateThread();
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
#### `destroy()`
|
|
134
|
+
|
|
135
|
+
Stop all heartbeat handlers and clean up resources.
|
|
136
|
+
|
|
137
|
+
```typescript
|
|
138
|
+
await harness.destroy();
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
### State
|
|
142
|
+
|
|
143
|
+
#### `getState()`
|
|
144
|
+
|
|
145
|
+
Return a read-only snapshot of the current harness state.
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
const state = harness.getState();
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### `setState(updates)`
|
|
152
|
+
|
|
153
|
+
Update the harness state. Validates against `stateSchema` if provided, and emits a `state_changed` event with the new state and changed keys.
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
await harness.setState({ currentModelId: 'anthropic/claude-sonnet-4-20250514' });
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### Modes
|
|
160
|
+
|
|
161
|
+
#### `listModes()`
|
|
162
|
+
|
|
163
|
+
Return all configured `HarnessMode` instances.
|
|
164
|
+
|
|
165
|
+
```typescript
|
|
166
|
+
const modes = harness.listModes();
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
#### `getCurrentModeId()`
|
|
170
|
+
|
|
171
|
+
Return the ID of the currently active mode.
|
|
172
|
+
|
|
173
|
+
```typescript
|
|
174
|
+
const modeId = harness.getCurrentModeId();
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
#### `getCurrentMode()`
|
|
178
|
+
|
|
179
|
+
Return the `HarnessMode` object for the current mode.
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
const mode = harness.getCurrentMode();
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### `switchMode({ modeId })`
|
|
186
|
+
|
|
187
|
+
Switch to a different mode. Aborts any in-progress generation, saves the current model to the outgoing mode, loads the incoming mode's model, and emits `mode_changed` and `model_changed` events.
|
|
188
|
+
|
|
189
|
+
```typescript
|
|
190
|
+
await harness.switchMode({ modeId: 'build' });
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Models
|
|
194
|
+
|
|
195
|
+
#### `getCurrentModelId()`
|
|
196
|
+
|
|
197
|
+
Return the ID of the currently selected model from state.
|
|
198
|
+
|
|
199
|
+
```typescript
|
|
200
|
+
const modelId = harness.getCurrentModelId();
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### `getModelName()`
|
|
204
|
+
|
|
205
|
+
Return a short display name from the current model ID. For example, `"claude-sonnet-4"` from `"anthropic/claude-sonnet-4"`.
|
|
206
|
+
|
|
207
|
+
```typescript
|
|
208
|
+
const name = harness.getModelName();
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
#### `getFullModelId()`
|
|
212
|
+
|
|
213
|
+
Return the complete model ID string.
|
|
214
|
+
|
|
215
|
+
```typescript
|
|
216
|
+
const fullId = harness.getFullModelId();
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
#### `hasModelSelected()`
|
|
220
|
+
|
|
221
|
+
Check if a model ID is currently selected.
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
if (harness.hasModelSelected()) {
|
|
225
|
+
// Ready to send messages
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
#### `switchModel({ modelId, scope?, modeId? })`
|
|
230
|
+
|
|
231
|
+
Switch the active model. When `scope` is `'thread'`, the model ID is persisted to thread metadata so it's restored when switching back. Emits a `model_changed` event.
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
// Set for current session only
|
|
235
|
+
await harness.switchModel({ modelId: 'anthropic/claude-sonnet-4-20250514' });
|
|
236
|
+
|
|
237
|
+
// Persist to the current thread
|
|
238
|
+
await harness.switchModel({ modelId: 'anthropic/claude-sonnet-4-20250514', scope: 'thread' });
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
#### `getCurrentModelAuthStatus()`
|
|
242
|
+
|
|
243
|
+
Check if the current model's provider has authentication configured. Uses `modelAuthChecker` if provided, falling back to environment variable checks from the provider registry.
|
|
244
|
+
|
|
245
|
+
```typescript
|
|
246
|
+
const status = await harness.getCurrentModelAuthStatus();
|
|
247
|
+
// { hasAuth: true, apiKeyEnvVar: 'ANTHROPIC_API_KEY' }
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
#### `listAvailableModels()`
|
|
251
|
+
|
|
252
|
+
Retrieve all available models from the provider registry, including their authentication status and use counts.
|
|
253
|
+
|
|
254
|
+
```typescript
|
|
255
|
+
const models = await harness.listAvailableModels();
|
|
256
|
+
// [{ id, provider, modelName, hasApiKey, apiKeyEnvVar, useCount }]
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
### Threads
|
|
260
|
+
|
|
261
|
+
#### `getCurrentThreadId()`
|
|
262
|
+
|
|
263
|
+
Return the ID of the currently active thread.
|
|
264
|
+
|
|
265
|
+
```typescript
|
|
266
|
+
const threadId = harness.getCurrentThreadId();
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
#### `createThread({ title? })`
|
|
270
|
+
|
|
271
|
+
Create a new thread. Initializes thread metadata, saves it to storage, acquires a thread lock, and emits a `thread_created` event.
|
|
272
|
+
|
|
273
|
+
```typescript
|
|
274
|
+
const thread = await harness.createThread({ title: 'New conversation' });
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
#### `switchThread({ threadId })`
|
|
278
|
+
|
|
279
|
+
Switch to a different thread. Aborts any in-progress operations, acquires a lock on the new thread, releases the lock on the previous thread, loads the thread's metadata, and emits a `thread_changed` event.
|
|
280
|
+
|
|
281
|
+
```typescript
|
|
282
|
+
await harness.switchThread({ threadId: 'thread-abc123' });
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
#### `listThreads(options?)`
|
|
286
|
+
|
|
287
|
+
List threads from storage. By default, only threads for the current resource are returned.
|
|
288
|
+
|
|
289
|
+
```typescript
|
|
290
|
+
// List threads for current resource
|
|
291
|
+
const threads = await harness.listThreads();
|
|
292
|
+
|
|
293
|
+
// List all threads across resources
|
|
294
|
+
const allThreads = await harness.listThreads({ allResources: true });
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
#### `renameThread({ title })`
|
|
298
|
+
|
|
299
|
+
Update the title of the current thread.
|
|
300
|
+
|
|
301
|
+
```typescript
|
|
302
|
+
await harness.renameThread({ title: 'Updated title' });
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
#### `getResourceId()`
|
|
306
|
+
|
|
307
|
+
Return the current resource ID.
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
const resourceId = harness.getResourceId();
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
#### `setResourceId({ resourceId })`
|
|
314
|
+
|
|
315
|
+
Set the resource ID and clear the current thread.
|
|
316
|
+
|
|
317
|
+
```typescript
|
|
318
|
+
harness.setResourceId({ resourceId: 'project-xyz' });
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
#### `getSession()`
|
|
322
|
+
|
|
323
|
+
Return current session information including thread ID, mode ID, and the list of threads.
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
const session = await harness.getSession();
|
|
327
|
+
// { currentThreadId, currentModeId, threads }
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
### Messages
|
|
331
|
+
|
|
332
|
+
#### `sendMessage({ content, images? })`
|
|
333
|
+
|
|
334
|
+
Send a message to the current agent. Creates a thread if none exists, builds a `RequestContext` and toolsets, and streams the agent's response. Handles tool calls, approvals, and errors automatically.
|
|
335
|
+
|
|
336
|
+
```typescript
|
|
337
|
+
await harness.sendMessage({ content: 'Explain the authentication flow' });
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
#### `listMessages(options?)`
|
|
341
|
+
|
|
342
|
+
Retrieve messages for the current thread.
|
|
343
|
+
|
|
344
|
+
```typescript
|
|
345
|
+
const messages = await harness.listMessages();
|
|
346
|
+
|
|
347
|
+
// Limit to the last 50 messages
|
|
348
|
+
const recent = await harness.listMessages({ limit: 50 });
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
#### `listMessagesForThread({ threadId, limit? })`
|
|
352
|
+
|
|
353
|
+
Retrieve messages for a specific thread.
|
|
354
|
+
|
|
355
|
+
```typescript
|
|
356
|
+
const messages = await harness.listMessagesForThread({ threadId: 'thread-abc123' });
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
#### `getFirstUserMessageForThread({ threadId })`
|
|
360
|
+
|
|
361
|
+
Retrieve the first user message for a given thread.
|
|
362
|
+
|
|
363
|
+
```typescript
|
|
364
|
+
const firstMsg = await harness.getFirstUserMessageForThread({ threadId: 'thread-abc123' });
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Flow control
|
|
368
|
+
|
|
369
|
+
#### `abort()`
|
|
370
|
+
|
|
371
|
+
Abort any in-progress generation.
|
|
372
|
+
|
|
373
|
+
```typescript
|
|
374
|
+
harness.abort();
|
|
375
|
+
```
|
|
376
|
+
|
|
377
|
+
#### `steer({ content })`
|
|
378
|
+
|
|
379
|
+
Steer the agent mid-stream by injecting an instruction into the current generation.
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
harness.steer({ content: 'Focus on security implications' });
|
|
383
|
+
```
|
|
384
|
+
|
|
385
|
+
#### `followUp({ content })`
|
|
386
|
+
|
|
387
|
+
Queue a follow-up message to be sent after the current generation completes. If no operation is running, sends the message immediately.
|
|
388
|
+
|
|
389
|
+
```typescript
|
|
390
|
+
harness.followUp({ content: 'Now apply those changes' });
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
### Tool approvals
|
|
394
|
+
|
|
395
|
+
#### `respondToToolApproval({ decision })`
|
|
396
|
+
|
|
397
|
+
Respond to a pending tool approval request. Called when a `tool_approval_required` event is received.
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
harness.respondToToolApproval({ decision: 'approve' });
|
|
401
|
+
harness.respondToToolApproval({ decision: 'decline' });
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Questions and plans
|
|
405
|
+
|
|
406
|
+
#### `respondToQuestion({ questionId, answer })`
|
|
407
|
+
|
|
408
|
+
Respond to a pending question from the `ask_user` built-in tool.
|
|
409
|
+
|
|
410
|
+
```typescript
|
|
411
|
+
harness.respondToQuestion({ questionId: 'q-123', answer: 'Yes, proceed with the refactor' });
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
#### `respondToPlanApproval({ planId, response })`
|
|
415
|
+
|
|
416
|
+
Respond to a pending plan approval from the `submit_plan` built-in tool. The `response` object contains `action` (`'approved'` or `'rejected'`) and an optional `feedback` string.
|
|
417
|
+
|
|
418
|
+
```typescript
|
|
419
|
+
harness.respondToPlanApproval({ planId: 'plan-123', response: { action: 'approved' } });
|
|
420
|
+
harness.respondToPlanApproval({ planId: 'plan-123', response: { action: 'rejected', feedback: 'Needs more detail' } });
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### Permissions
|
|
424
|
+
|
|
425
|
+
#### `grantSessionCategory({ category })`
|
|
426
|
+
|
|
427
|
+
Grant a tool category for the current session. Tools in this category are auto-approved without prompting.
|
|
428
|
+
|
|
429
|
+
```typescript
|
|
430
|
+
harness.grantSessionCategory({ category: 'edit' });
|
|
431
|
+
```
|
|
432
|
+
|
|
433
|
+
#### `grantSessionTool({ toolName })`
|
|
434
|
+
|
|
435
|
+
Grant a specific tool for the current session.
|
|
436
|
+
|
|
437
|
+
```typescript
|
|
438
|
+
harness.grantSessionTool({ toolName: 'mastra_workspace_execute_command' });
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
#### `getSessionGrants()`
|
|
442
|
+
|
|
443
|
+
Return currently granted session categories and tools.
|
|
444
|
+
|
|
445
|
+
```typescript
|
|
446
|
+
const grants = harness.getSessionGrants();
|
|
447
|
+
// { categories: Set<string>, tools: Set<string> }
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
#### `setPermissionForCategory({ category, policy })`
|
|
451
|
+
|
|
452
|
+
Set the permission policy for a tool category.
|
|
453
|
+
|
|
454
|
+
```typescript
|
|
455
|
+
harness.setPermissionForCategory({ category: 'execute', policy: 'ask' });
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
#### `setPermissionForTool({ toolName, policy })`
|
|
459
|
+
|
|
460
|
+
Set the permission policy for a specific tool. Per-tool policies take precedence over category policies.
|
|
461
|
+
|
|
462
|
+
```typescript
|
|
463
|
+
harness.setPermissionForTool({ toolName: 'dangerous_tool', policy: 'deny' });
|
|
464
|
+
```
|
|
465
|
+
|
|
466
|
+
#### `getPermissionRules()`
|
|
467
|
+
|
|
468
|
+
Return the current permission rules.
|
|
469
|
+
|
|
470
|
+
```typescript
|
|
471
|
+
const rules = harness.getPermissionRules();
|
|
472
|
+
// { categories: { execute: 'ask' }, tools: { dangerous_tool: 'deny' } }
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
#### `getToolCategory({ toolName })`
|
|
476
|
+
|
|
477
|
+
Resolve a tool's category using the configured `toolCategoryResolver`.
|
|
478
|
+
|
|
479
|
+
```typescript
|
|
480
|
+
const category = harness.getToolCategory({ toolName: 'mastra_workspace_write_file' });
|
|
481
|
+
// 'edit'
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
### Observational memory
|
|
485
|
+
|
|
486
|
+
#### `loadOMProgress()`
|
|
487
|
+
|
|
488
|
+
Load observational memory records for the current thread and emit an `om_status` event with reconstructed progress.
|
|
489
|
+
|
|
490
|
+
```typescript
|
|
491
|
+
await harness.loadOMProgress();
|
|
492
|
+
```
|
|
493
|
+
|
|
494
|
+
#### `getObserverModelId()`
|
|
495
|
+
|
|
496
|
+
Return the observer model ID from state or the default from `omConfig`.
|
|
497
|
+
|
|
498
|
+
```typescript
|
|
499
|
+
const modelId = harness.getObserverModelId();
|
|
500
|
+
```
|
|
501
|
+
|
|
502
|
+
#### `getReflectorModelId()`
|
|
503
|
+
|
|
504
|
+
Return the reflector model ID from state or the default from `omConfig`.
|
|
505
|
+
|
|
506
|
+
```typescript
|
|
507
|
+
const modelId = harness.getReflectorModelId();
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
#### `switchObserverModel({ modelId })`
|
|
511
|
+
|
|
512
|
+
Switch the observer model. Persists the setting to thread metadata and emits an `om_model_changed` event.
|
|
513
|
+
|
|
514
|
+
```typescript
|
|
515
|
+
await harness.switchObserverModel({ modelId: 'anthropic/claude-haiku-3.5' });
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
#### `switchReflectorModel({ modelId })`
|
|
519
|
+
|
|
520
|
+
Switch the reflector model. Persists the setting to thread metadata and emits an `om_model_changed` event.
|
|
521
|
+
|
|
522
|
+
```typescript
|
|
523
|
+
await harness.switchReflectorModel({ modelId: 'anthropic/claude-haiku-3.5' });
|
|
524
|
+
```
|
|
525
|
+
|
|
526
|
+
#### `getObservationThreshold()`
|
|
527
|
+
|
|
528
|
+
Return the observation threshold in tokens from state or the default from `omConfig`.
|
|
529
|
+
|
|
530
|
+
```typescript
|
|
531
|
+
const threshold = harness.getObservationThreshold();
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
#### `getReflectionThreshold()`
|
|
535
|
+
|
|
536
|
+
Return the reflection threshold in tokens from state or the default from `omConfig`.
|
|
537
|
+
|
|
538
|
+
```typescript
|
|
539
|
+
const threshold = harness.getReflectionThreshold();
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
### Subagents
|
|
543
|
+
|
|
544
|
+
#### `getSubagentModelId({ agentType? })`
|
|
545
|
+
|
|
546
|
+
Retrieve the subagent model ID. Prioritizes per-type settings over the global setting.
|
|
547
|
+
|
|
548
|
+
```typescript
|
|
549
|
+
const modelId = harness.getSubagentModelId({ agentType: 'explore' });
|
|
550
|
+
```
|
|
551
|
+
|
|
552
|
+
#### `setSubagentModelId({ modelId, agentType? })`
|
|
553
|
+
|
|
554
|
+
Set the subagent model ID. Pass an `agentType` to set a per-type override, or omit it to set the global default. Persists to thread settings and emits a `subagent_model_changed` event.
|
|
555
|
+
|
|
556
|
+
```typescript
|
|
557
|
+
// Set global subagent model
|
|
558
|
+
await harness.setSubagentModelId({ modelId: 'anthropic/claude-sonnet-4-20250514' });
|
|
559
|
+
|
|
560
|
+
// Set per-type model
|
|
561
|
+
await harness.setSubagentModelId({ modelId: 'anthropic/claude-haiku-3.5', agentType: 'explore' });
|
|
562
|
+
```
|
|
563
|
+
|
|
564
|
+
### Events
|
|
565
|
+
|
|
566
|
+
#### `subscribe(listener)`
|
|
567
|
+
|
|
568
|
+
Register an event listener. Returns an unsubscribe function.
|
|
569
|
+
|
|
570
|
+
```typescript
|
|
571
|
+
const unsubscribe = harness.subscribe((event) => {
|
|
572
|
+
switch (event.type) {
|
|
573
|
+
case 'message_update':
|
|
574
|
+
renderMessage(event.message);
|
|
575
|
+
break;
|
|
576
|
+
case 'tool_approval_required':
|
|
577
|
+
showApprovalPrompt(event.toolName);
|
|
578
|
+
break;
|
|
579
|
+
case 'error':
|
|
580
|
+
console.error(event.error);
|
|
581
|
+
break;
|
|
582
|
+
}
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
// Later:
|
|
586
|
+
unsubscribe();
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
## Events
|
|
590
|
+
|
|
591
|
+
The harness emits events through registered listeners. The following table lists the available event types:
|
|
592
|
+
|
|
593
|
+
| Event type | Description |
|
|
594
|
+
| -------------------------- | ------------------------------------------------------------------- |
|
|
595
|
+
| `mode_changed` | The active mode changed. |
|
|
596
|
+
| `model_changed` | The active model changed. |
|
|
597
|
+
| `thread_changed` | The active thread changed. |
|
|
598
|
+
| `thread_created` | A new thread was created. |
|
|
599
|
+
| `state_changed` | Harness state was updated. |
|
|
600
|
+
| `agent_start` | The agent started processing. |
|
|
601
|
+
| `agent_end` | The agent finished processing. |
|
|
602
|
+
| `message_start` | A new message started streaming. |
|
|
603
|
+
| `message_update` | A message was updated with new content. |
|
|
604
|
+
| `message_end` | A message finished streaming. |
|
|
605
|
+
| `tool_start` | A tool call started. |
|
|
606
|
+
| `tool_approval_required` | A tool call requires user approval. |
|
|
607
|
+
| `tool_update` | A tool call was updated with progress. |
|
|
608
|
+
| `tool_end` | A tool call finished. |
|
|
609
|
+
| `tool_input_start` | Tool input started streaming. |
|
|
610
|
+
| `tool_input_delta` | Tool input received a streaming delta. |
|
|
611
|
+
| `tool_input_end` | Tool input finished streaming. |
|
|
612
|
+
| `usage_update` | Token usage was updated. |
|
|
613
|
+
| `error` | An error occurred. |
|
|
614
|
+
| `info` | An informational message was emitted. |
|
|
615
|
+
| `follow_up_queued` | A follow-up message was queued. |
|
|
616
|
+
| `workspace_status_changed` | The workspace status changed. |
|
|
617
|
+
| `workspace_ready` | The workspace finished initializing. |
|
|
618
|
+
| `workspace_error` | The workspace encountered an error. |
|
|
619
|
+
| `om_status` | Observational memory status update. |
|
|
620
|
+
| `om_observation_start` | An observation started. |
|
|
621
|
+
| `om_observation_end` | An observation completed. |
|
|
622
|
+
| `om_reflection_start` | A reflection started. |
|
|
623
|
+
| `om_reflection_end` | A reflection completed. |
|
|
624
|
+
| `ask_question` | The agent asked a question via the `ask_user` tool. |
|
|
625
|
+
| `plan_approval_required` | The agent submitted a plan for approval via the `submit_plan` tool. |
|
|
626
|
+
| `plan_approved` | A plan was approved. |
|
|
627
|
+
| `subagent_start` | A subagent started processing. |
|
|
628
|
+
| `subagent_text_delta` | A subagent emitted a text delta. |
|
|
629
|
+
| `subagent_tool_start` | A subagent started a tool call. |
|
|
630
|
+
| `subagent_tool_end` | A subagent finished a tool call. |
|
|
631
|
+
| `subagent_end` | A subagent finished processing. |
|
|
632
|
+
| `subagent_model_changed` | A subagent's model changed. |
|
|
633
|
+
| `task_updated` | A task list was updated. |
|
|
634
|
+
|
|
635
|
+
## Built-in tools
|
|
636
|
+
|
|
637
|
+
The harness provides built-in tools to agents in every mode:
|
|
638
|
+
|
|
639
|
+
| Tool | Description |
|
|
640
|
+
| ------------- | ------------------------------------------------------------------------------------------------ |
|
|
641
|
+
| `ask_user` | Ask the user a question and wait for their response. |
|
|
642
|
+
| `submit_plan` | Submit a plan for user review and approval. |
|
|
643
|
+
| `task_write` | Create or update a structured task list for tracking progress. |
|
|
644
|
+
| `task_check` | Check the completion status of the current task list. |
|
|
645
|
+
| `subagent` | Spawn a focused subagent with constrained tools (only available when `subagents` is configured). |
|