@botbotgo/agent-harness 0.0.9 → 0.0.11

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.
Files changed (2) hide show
  1. package/README.md +512 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,512 @@
1
+ # @botbotgo/agent-harness
2
+
3
+ `@botbotgo/agent-harness` is a TypeScript framework for running local agent workspaces with declarative config, reusable tools, reusable skills, and configurable host-agent routing.
4
+
5
+ It is designed for two common use cases:
6
+
7
+ - build a reusable agent runtime package and publish it to npm
8
+ - build an application workspace that ships its own agents, tools, skills, and model config
9
+
10
+ The public API stays intentionally small:
11
+
12
+ - `createAgentHarness(...)`
13
+ - `run(...)`
14
+ - `subscribe(...)`
15
+ - `getThread(...)`
16
+ - `stop(...)`
17
+
18
+ ## Product Overview
19
+
20
+ Agent Harness loads a workspace from disk, compiles its config into runnable agent bindings, and executes requests through either a lightweight LangChain v1 path or a DeepAgent path.
21
+
22
+ Out of the box, the framework supports:
23
+
24
+ - workspace loading from a directory root
25
+ - declarative `Model`, `EmbeddingModel`, `VectorStore`, `LangChainAgent`, `DeepAgent`, and `Runtime` objects
26
+ - host-agent routing between a direct path and an orchestration path
27
+ - tool loading from resource packages and external sources
28
+ - skill discovery from filesystem roots
29
+ - subagent discovery from filesystem roots
30
+ - thread persistence, run history, and resumable state
31
+
32
+ The default package config in this repo shows the intended model:
33
+
34
+ - `direct`: low-latency host for simple one-step requests
35
+ - `orchestra`: default host for multi-step work, tools, skills, and delegation
36
+
37
+ ## Quick Start
38
+
39
+ Install the package:
40
+
41
+ ```bash
42
+ npm install @botbotgo/agent-harness
43
+ ```
44
+
45
+ Create a workspace with at least:
46
+
47
+ ```text
48
+ your-workspace/
49
+ AGENTS.md
50
+ config/
51
+ model.yaml
52
+ runtime.yaml
53
+ direct.yaml
54
+ orchestra.yaml
55
+ ```
56
+
57
+ Minimal usage:
58
+
59
+ ```ts
60
+ import { createAgentHarness, run, stop } from "@botbotgo/agent-harness";
61
+
62
+ const harness = await createAgentHarness("/absolute/path/to/your-workspace");
63
+
64
+ try {
65
+ const result = await run(harness, {
66
+ agentId: "direct",
67
+ input: "Summarize what this workspace is for.",
68
+ });
69
+
70
+ console.log(result.output);
71
+ } finally {
72
+ await stop(harness);
73
+ }
74
+ ```
75
+
76
+ If you want the framework to choose the host agent automatically, pass `agentId: "auto"` when your workspace has runtime routing configured.
77
+
78
+ ## How To Use
79
+
80
+ There are two common ways to use the framework.
81
+
82
+ ### 1. Use It As A Library
83
+
84
+ Load a workspace from disk and run requests through the public API.
85
+
86
+ #### SDK Surface
87
+
88
+ The SDK is intentionally small:
89
+
90
+ - `createAgentHarness(...)`: load a workspace and initialize the runtime
91
+ - `run(...)`: start a new run or answer an approval request
92
+ - `subscribe(...)`: observe runtime events for logging or UI updates
93
+ - `getThread(...)`: fetch persisted thread state and messages
94
+ - `stop(...)`: release runtime resources when your process is done
95
+
96
+ #### Create A Harness From A Workspace Path
97
+
98
+ This is the standard entry point. Pass the workspace root and let the harness load `AGENTS.md`, `config/`, resource sources, skills, tools, and agent bindings from disk.
99
+
100
+ ```ts
101
+ import { createAgentHarness } from "@botbotgo/agent-harness";
102
+
103
+ const harness = await createAgentHarness("/absolute/path/to/workspace");
104
+ ```
105
+
106
+ If you omit the path, the SDK uses `process.cwd()`:
107
+
108
+ ```ts
109
+ const harness = await createAgentHarness();
110
+ ```
111
+
112
+ #### Create A Harness From A Prebuilt WorkspaceBundle
113
+
114
+ If your application already compiled a workspace, or you want tighter control in tests, you can pass a `WorkspaceBundle` directly instead of a filesystem path.
115
+
116
+ ```ts
117
+ import { createAgentHarness } from "@botbotgo/agent-harness";
118
+
119
+ const harness = await createAgentHarness(workspaceBundle);
120
+ ```
121
+
122
+ #### Run A Simple Request
123
+
124
+ Use `run(...)` with an `agentId` and plain-text `input`. The return value includes:
125
+
126
+ - `threadId`: stable conversation id
127
+ - `runId`: the current execution id
128
+ - `state`: final state such as `completed` or `waiting_for_approval`
129
+ - `output`: final visible model output
130
+
131
+ ```ts
132
+ import { createAgentHarness, run, stop } from "@botbotgo/agent-harness";
133
+
134
+ const harness = await createAgentHarness("/absolute/path/to/workspace");
135
+
136
+ try {
137
+ const result = await run(harness, {
138
+ agentId: "direct",
139
+ input: "Summarize what this workspace is for.",
140
+ });
141
+
142
+ console.log(result.threadId);
143
+ console.log(result.runId);
144
+ console.log(result.state);
145
+ console.log(result.output);
146
+ } finally {
147
+ await stop(harness);
148
+ }
149
+ ```
150
+
151
+ #### Let The Harness Choose The Host Agent
152
+
153
+ If your workspace defines runtime routing, use `agentId: "auto"` to let the harness choose between host agents such as `direct` and `orchestra`.
154
+
155
+ ```ts
156
+ const result = await run(harness, {
157
+ agentId: "auto",
158
+ input: "Inspect this repository and explain how the release flow works.",
159
+ });
160
+ ```
161
+
162
+ Use this mode when your application should not hardcode the host agent choice.
163
+
164
+ #### Stream Chunks And Runtime Events
165
+
166
+ `run(...)` accepts listeners for streamed output and runtime activity. This is the main SDK path for CLIs, chat UIs, and debug logging.
167
+
168
+ ```ts
169
+ const result = await run(harness, {
170
+ agentId: "orchestra",
171
+ input: "Inspect the workspace and explain the available agents.",
172
+ listeners: {
173
+ onChunk(chunk) {
174
+ process.stdout.write(chunk);
175
+ },
176
+ onEvent(event) {
177
+ console.log("event:", event.eventType, event.payload);
178
+ },
179
+ onStep(step) {
180
+ console.log("step:", step);
181
+ },
182
+ onToolResult(item) {
183
+ console.log("tool:", item.toolName, item.output);
184
+ },
185
+ },
186
+ });
187
+ ```
188
+
189
+ Listener usage by type:
190
+
191
+ - `onChunk`: streamed user-visible response text
192
+ - `onEvent`: raw runtime events
193
+ - `onStep`: higher-level execution step messages
194
+ - `onToolResult`: completed tool outputs
195
+ - `onReasoning`: reasoning-channel text when available from the runtime
196
+
197
+ #### Subscribe To Global Harness Events
198
+
199
+ Use `subscribe(...)` when you want a process-wide event feed rather than per-run listeners.
200
+
201
+ ```ts
202
+ import { subscribe } from "@botbotgo/agent-harness";
203
+
204
+ const unsubscribe = subscribe(harness, (event) => {
205
+ console.log(event.threadId, event.runId, event.eventType);
206
+ });
207
+
208
+ // later
209
+ unsubscribe();
210
+ ```
211
+
212
+ This is useful when one process is handling multiple runs or updating a central UI.
213
+
214
+ #### Continue An Existing Thread
215
+
216
+ Pass an existing `threadId` to keep the conversation on the same persisted thread.
217
+
218
+ ```ts
219
+ const first = await run(harness, {
220
+ agentId: "direct",
221
+ input: "Remember that the release branch is master.",
222
+ });
223
+
224
+ const second = await run(harness, {
225
+ agentId: "direct",
226
+ threadId: first.threadId,
227
+ input: "What did I just tell you about the release branch?",
228
+ });
229
+ ```
230
+
231
+ #### Read Back Thread State
232
+
233
+ Use `getThread(...)` to fetch persisted thread data after a run completes.
234
+
235
+ ```ts
236
+ import { getThread } from "@botbotgo/agent-harness";
237
+
238
+ const thread = await getThread(harness, result.threadId);
239
+
240
+ console.log(thread?.threadId);
241
+ console.log(thread?.messages.at(-1)?.content);
242
+ ```
243
+
244
+ Use this when your app needs to reopen a conversation, render history, or inspect the latest assistant message.
245
+
246
+ #### Handle Approval Or Interrupt Flows
247
+
248
+ Some runs can pause with `state: "waiting_for_approval"`. In that case, call `run(...)` again with the thread or approval decision payload instead of starting a new request.
249
+
250
+ ```ts
251
+ const pending = await run(harness, {
252
+ agentId: "orchestra",
253
+ input: "Run the protected action if approval is required.",
254
+ });
255
+
256
+ if (pending.state === "waiting_for_approval" && pending.approvalId) {
257
+ const resumed = await run(harness, {
258
+ threadId: pending.threadId,
259
+ runId: pending.runId,
260
+ approvalId: pending.approvalId,
261
+ decision: "approve",
262
+ });
263
+
264
+ console.log(resumed.output);
265
+ }
266
+ ```
267
+
268
+ Use `decision: "edit"` plus `editedInput` when your application exposes approval-time parameter editing.
269
+
270
+ #### Always Stop The Harness
271
+
272
+ Call `stop(...)` before process exit so the runtime can close adapters and flush state cleanly.
273
+
274
+ ```ts
275
+ await stop(harness);
276
+ ```
277
+
278
+ For most applications, the safe pattern is `try/finally`.
279
+
280
+ #### Complete SDK CLI Example
281
+
282
+ The following example shows a small CLI-style integration that:
283
+
284
+ - loads a workspace from disk
285
+ - starts a first run with streaming output
286
+ - continues the same thread
287
+ - reads the saved thread state back
288
+ - shuts the harness down cleanly
289
+
290
+ ```ts
291
+ import { createAgentHarness, getThread, run, stop } from "@botbotgo/agent-harness";
292
+
293
+ const workspaceRoot = "/absolute/path/to/workspace";
294
+ const harness = await createAgentHarness(workspaceRoot);
295
+
296
+ try {
297
+ const first = await run(harness, {
298
+ agentId: "auto",
299
+ input: "Explain what agents and tools are available in this workspace.",
300
+ listeners: {
301
+ onChunk(chunk) {
302
+ process.stdout.write(chunk);
303
+ },
304
+ onStep(step) {
305
+ console.log("\n[step]", step);
306
+ },
307
+ },
308
+ });
309
+
310
+ console.log("\nfirst run:", first.runId, first.state);
311
+
312
+ const second = await run(harness, {
313
+ agentId: "auto",
314
+ threadId: first.threadId,
315
+ input: "Now give me the shortest possible summary in 3 bullets.",
316
+ });
317
+
318
+ console.log("\nsecond run output:\n", second.output);
319
+
320
+ const thread = await getThread(harness, first.threadId);
321
+ console.log("\nthread message count:", thread?.messages.length ?? 0);
322
+ } finally {
323
+ await stop(harness);
324
+ }
325
+ ```
326
+
327
+ For a real CLI entrypoint, wrap this in an async `main()` and feed the prompt from `process.argv`.
328
+
329
+ ```ts
330
+ import { createAgentHarness, getThread, run, subscribe, stop } from "@botbotgo/agent-harness";
331
+
332
+ const harness = await createAgentHarness("/absolute/path/to/workspace");
333
+
334
+ const unsubscribe = subscribe(harness, (event) => {
335
+ console.log(event.eventType, event.payload);
336
+ });
337
+
338
+ try {
339
+ const firstRun = await run(harness, {
340
+ agentId: "orchestra",
341
+ input: "Inspect the workspace and explain the available agents.",
342
+ listeners: {
343
+ onChunk(chunk) {
344
+ process.stdout.write(chunk);
345
+ },
346
+ },
347
+ });
348
+
349
+ const thread = await getThread(harness, firstRun.threadId);
350
+ console.log(thread?.messages.at(-1)?.content);
351
+ } finally {
352
+ unsubscribe();
353
+ await stop(harness);
354
+ }
355
+ ```
356
+
357
+ ### 2. Use It Inside An App Workspace
358
+
359
+ The example app in [`examples/stock-research-app`](/Users/boqiang.liang/900-project/agent-harness3/examples/stock-research-app/README.md) is the reference shape for an application workspace. It keeps the framework package separate from app-specific agents, tools, and skills.
360
+
361
+ Run the example:
362
+
363
+ ```bash
364
+ cd examples/stock-research-app
365
+ npm install
366
+ npm run start -- "Investigate NVDA and produce a balanced stock research brief."
367
+ ```
368
+
369
+ ## How To Configure
370
+
371
+ Agent Harness is workspace-first. The runtime is assembled from files on disk rather than from a large constructor API.
372
+
373
+ ### Core Files
374
+
375
+ - `AGENTS.md`: durable instructions and operating rules loaded into agent memory where configured
376
+ - `config/model.yaml`: default chat model
377
+ - `config/runtime.yaml`: workspace-wide runtime defaults such as `runRoot` and host routing
378
+ - `config/direct.yaml`: lightweight direct-response host agent
379
+ - `config/orchestra.yaml`: default orchestration host agent
380
+ - `config/embedding-model.yaml`: embeddings preset for retrieval flows
381
+ - `config/vector-store.yaml`: vector store preset for retrieval flows
382
+
383
+ ### Minimal Model Config
384
+
385
+ ```yaml
386
+ apiVersion: agent-harness/v1alpha1
387
+ kind: Model
388
+ metadata:
389
+ name: default
390
+ spec:
391
+ provider: ollama
392
+ model: gpt-oss:latest
393
+ init:
394
+ baseUrl: http://localhost:11434
395
+ temperature: 0.2
396
+ ```
397
+
398
+ ### Runtime Routing
399
+
400
+ `config/runtime.yaml` controls shared runtime behavior. In this repo it defines:
401
+
402
+ - `runRoot`: where thread state, run artifacts, approvals, and indexes are stored
403
+ - `routing.systemPrompt`: how the harness chooses between the primary and secondary host agents when `agentId: "auto"` is used
404
+
405
+ ### Agent Config
406
+
407
+ Agent objects are declarative YAML files. The package currently supports:
408
+
409
+ - `LangChainAgent`
410
+ - `DeepAgent`
411
+
412
+ Typical fields include:
413
+
414
+ - `metadata.name`
415
+ - `metadata.description`
416
+ - `spec.modelRef`
417
+ - `spec.systemPrompt`
418
+ - `spec.checkpointer`
419
+ - `spec.memory`
420
+ - `spec.store`
421
+ - `spec.backend`
422
+
423
+ Use `LangChainAgent` for a fast direct path. Use `DeepAgent` when you need richer orchestration, tool-heavy execution, memory backends, and delegation.
424
+
425
+ ## How To Extend
426
+
427
+ The extension model is filesystem-based. You extend the harness by adding new config objects, new discovery roots, or new resource packages.
428
+
429
+ ### Add More Agents
430
+
431
+ Subagents can be discovered from configured roots. The discovery layer supports:
432
+
433
+ - local filesystem paths
434
+ - external resource sources
435
+ - builtin discovery paths
436
+
437
+ The harness scans YAML files under the discovered agent roots and adds them to the workspace graph.
438
+
439
+ ### Add Skills
440
+
441
+ Skills are discovered from roots that contain either:
442
+
443
+ - a direct `SKILL.md`
444
+ - child directories where each directory contains its own `SKILL.md`
445
+
446
+ A practical layout looks like this:
447
+
448
+ ```text
449
+ your-workspace/
450
+ resources/
451
+ skills/
452
+ code-review/
453
+ SKILL.md
454
+ release-check/
455
+ SKILL.md
456
+ ```
457
+
458
+ ### Add Tools
459
+
460
+ Tools can come from:
461
+
462
+ - resource packages
463
+ - external sources
464
+ - builtin resources
465
+ - declarative tool objects that bundle or reference other tools
466
+
467
+ The example application demonstrates a clean pattern: keep app-specific tools under `resources/tools/` and keep one tool per module.
468
+
469
+ ### Add Retrieval
470
+
471
+ If your workspace needs RAG-style behavior:
472
+
473
+ 1. add an `EmbeddingModel`
474
+ 2. add a `VectorStore`
475
+ 3. point retrieval-oriented tools at those refs
476
+
477
+ This repo already includes `config/embedding-model.yaml` and `config/vector-store.yaml` as the default pattern.
478
+
479
+ ### Extend The Runtime In Code
480
+
481
+ The public API also accepts a prebuilt `WorkspaceBundle`, which lets you compile or inject workspace data yourself before creating the harness. That path is useful when you need tighter control in tests or in a higher-level product.
482
+
483
+ ## Suggested Workspace Layout
484
+
485
+ ```text
486
+ your-workspace/
487
+ AGENTS.md
488
+ config/
489
+ model.yaml
490
+ runtime.yaml
491
+ direct.yaml
492
+ orchestra.yaml
493
+ embedding-model.yaml
494
+ vector-store.yaml
495
+ resources/
496
+ agents/
497
+ skills/
498
+ tools/
499
+ .agent/
500
+ ```
501
+
502
+ ## Development
503
+
504
+ Build and test this package locally:
505
+
506
+ ```bash
507
+ npm run build
508
+ npm run check
509
+ npm test
510
+ ```
511
+
512
+ The example workspace under [`examples/stock-research-app`](/Users/boqiang.liang/900-project/agent-harness3/examples/stock-research-app/README.md) is the fastest way to understand how an app should package its own agents, tools, and skills around this framework.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botbotgo/agent-harness",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Agent Harness framework package",
5
5
  "type": "module",
6
6
  "packageManager": "npm@10.9.2",
@@ -44,7 +44,7 @@
44
44
  "scripts": {
45
45
  "build": "rm -rf dist tsconfig.tsbuildinfo && tsc -p tsconfig.json && cp -R config dist/",
46
46
  "check": "tsc -p tsconfig.json --noEmit",
47
- "test": "vitest run test/public-api.test.ts test/resource-optional-provider.test.ts test/stock-research-app-load-harness.test.ts test/release-workflow.test.ts test/release-version.test.ts test/gitignore.test.ts test/package-lock.test.ts",
47
+ "test": "vitest run test/public-api.test.ts test/resource-optional-provider.test.ts test/stock-research-app-load-harness.test.ts test/release-workflow.test.ts test/release-version.test.ts test/gitignore.test.ts test/package-lock.test.ts test/readme.test.ts",
48
48
  "release:pack": "npm pack --dry-run",
49
49
  "release:publish": "npm publish --access public --registry https://registry.npmjs.org/"
50
50
  },