@j-o-r/hello-dave 0.0.5 → 0.0.6
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 +8 -1
- package/bin/dave.js +114 -94
- package/examples/memory_agent.js +134 -23
- package/examples/test_agent.js +0 -2
- package/lib/genericToolset.js +4 -88
- package/lib/wsIO.js +1 -11
- package/package.json +2 -2
- package/README.md +0 -601
- package/README.md.backup +0 -269
- package/README.md.bak +0 -523
- package/README.md.bak.1774780058 +0 -338
- package/README.md.bak2 +0 -531
- package/docs.bak.1774780058/agent-manager.md +0 -167
- package/docs.bak.1774780058/agent-manager.md.bak +0 -137
- package/docs.bak.1774780058/agent-manager.md.bak2 +0 -157
- package/docs.bak.1774780058/codeserver-pattern.md +0 -191
- package/docs.bak.1774780058/path-resolution-best-practices.md +0 -104
- package/docs.bak.1774780058/project-overview.md +0 -67
- package/docs.bak.1774780058/project-overview.md.bak +0 -67
- package/docs.bak.1774780058/prompt-class.md +0 -141
- package/docs.bak.1774780058/prompt-class.md.bak +0 -142
- package/docs.bak.1774780058/tools-syntax-validation.md +0 -121
- package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +0 -125
- package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +0 -125
- package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +0 -106
- package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +0 -106
- package/docs.bak.1774780058/toolset.md +0 -164
- package/docs.bak.1774780058/toolset.md.bak +0 -94
- package/docs.bak.1774780058/toolset.md.bak3 +0 -161
- package/docs.bak.1774780058/toolset.md.bak4 +0 -161
- package/docs.bak.1774780058/toolset.md.bak5 +0 -161
- package/docs.bak.1774780058/toolset.md.bak6 +0 -163
- package/docs.bak.1774780058/toolset.md.bak_path +0 -163
- package/docs.bak.1774780058/toolset.md.bak_syntax +0 -161
- package/docs.bak.1774780058/xai-responses.md +0 -111
- package/docs.bak.1774780058/xai-responses.md.bak +0 -107
- package/docs.bak.1774780058/xai-responses.md.bak2 +0 -107
- package/docs.bak.1774780058/xai_collections.md +0 -106
- package/examples.bak.1774780058/ask_agent.js +0 -114
- package/examples.bak.1774780058/code_agent.js +0 -149
- package/examples.bak.1774780058/coderev_agent.js +0 -72
- package/examples.bak.1774780058/codeserver.sh +0 -47
- package/examples.bak.1774780058/daisy_agent.js +0 -177
- package/examples.bak.1774780058/docs_agent.js +0 -119
- package/examples.bak.1774780058/gpt_agent.js +0 -109
- package/examples.bak.1774780058/grok_agent.js +0 -98
- package/examples.bak.1774780058/memory_agent.js +0 -112
- package/examples.bak.1774780058/npm_agent.js +0 -175
- package/examples.bak.1774780058/prompt_agent.js +0 -112
- package/examples.bak.1774780058/readme_agent.js +0 -144
- package/examples.bak.1774780058/spawn_agent.js +0 -263
- package/examples.bak.1774780058/test_agent.js +0 -162
- package/examples.bak.1774780058/todo_agent.js +0 -138
- package/scenarios.bak.1774780058/data/eval_node_message.json +0 -9
- package/scenarios.bak.1774780058/data/hist_oa.json +0 -66
- package/scenarios.bak.1774780058/data/o3_response1.json +0 -96
- package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +0 -112
- package/scenarios.bak.1774780058/data/tool_oa.json +0 -96
- package/scenarios.bak.1774780058/data/tool_xai.json +0 -59
- package/scenarios.bak.1774780058/data/tool_xai2.json +0 -40
- package/scenarios.bak.1774780058/data/xai-response-1.json +0 -59
- package/scenarios.bak.1774780058/data/xai-response-2.json +0 -10
- package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +0 -59
- package/scenarios.bak.1774780058/data/xai_search_response.json +0 -58
- package/scenarios.bak.1774780058/environment.js +0 -10
- package/scenarios.bak.1774780058/example.js +0 -17
- package/scenarios.bak.1774780058/genericToolset.test.js +0 -182
- package/scenarios.bak.1774780058/grok.js +0 -113
- package/scenarios.bak.1774780058/memory-tools.js +0 -51
- package/scenarios.bak.1774780058/openai-o3.js +0 -137
- package/scenarios.bak.1774780058/openai-prompt.js +0 -155
- package/scenarios.bak.1774780058/openai-session.js +0 -148
- package/scenarios.bak.1774780058/openai.js +0 -102
- package/scenarios.bak.1774780058/prompt.js +0 -118
- package/scenarios.bak.1774780058/promptFishbowl.js +0 -76
- package/scenarios.bak.1774780058/search.brave.com.js +0 -25
- package/scenarios.bak.1774780058/sh.js +0 -15
- package/scenarios.bak.1774780058/test-wsio.js +0 -26
- package/scenarios.bak.1774780058/testToolset.js +0 -42
- package/scenarios.bak.1774780058/toolset.js +0 -16
- package/scenarios.bak.1774780058/toolset.test.js +0 -141
- package/scenarios.bak.1774780058/write_file_syntax.test.js +0 -145
- package/scenarios.bak.1774780058/write_file_validation/README.md +0 -30
- package/scenarios.bak.1774780058/write_file_validation/bad.js +0 -3
- package/scenarios.bak.1774780058/write_file_validation/good.js +0 -4
- package/scenarios.bak.1774780058/write_file_validation/test.sh +0 -43
- package/scenarios.bak.1774780058/wsClient.js +0 -69
- package/scenarios.bak.1774780058/xai_responses.integration.test.js +0 -57
- package/scenarios.bak.1774780058/xai_responses.test.js +0 -154
- package/scenarios.bak.1774780058/xaicoll.js +0 -50
- package/scenarios.bak.1774780058/xaifiles.js +0 -48
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
# AgentManager (`lib/AgentManager.js`)
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
**AgentManager** is the central orchestrator class in the hello-dave framework. It manages agent lifecycle: setup (prompts, API, tools, sessions), execution modes (CLI, direct calls, WebSocket server/client), and tool integration. Designed for simplicity and extensibility, it abstracts LLM providers (`xai`, `gpt`, `claude`), `Prompt.js`, `ToolSet.js`, and `Session.js`.
|
|
5
|
-
|
|
6
|
-
**Uses named exports from `lib/index.js` - NO default export.**
|
|
7
|
-
|
|
8
|
-
Key Features:
|
|
9
|
-
- **Modes**: Interactive CLI, one-shot `directCall`, WS **server** (expose agent as tool), **client** (attach to remote server), hybrid (server + client).
|
|
10
|
-
- **Tool Handling**: Pre-configured (`toolsetMode: 'auto'`/`'required'`), generics (`addGenericToolcall`), custom `ToolSet`.
|
|
11
|
-
- **Persistence**: Sessions in `.cache/[name]/` (NDJSON logs).
|
|
12
|
-
- **Networking**: WS with optional `secret` auth (base64-encoded).
|
|
13
|
-
- **Validation**: Strict name regex `/^[a-z_0-9_]{2,}$/`.
|
|
14
|
-
- **Events**: Leverages `Prompt` events (e.g., `reset` → server resetAll).
|
|
15
|
-
|
|
16
|
-
Exports: `{ AgentManager }` (named).
|
|
17
|
-
|
|
18
|
-
## Agent Naming Rules ⚠️
|
|
19
|
-
**CRITICAL**: The `name` (constructor) and `toolName` (in `start()`) **MUST** match regex `/^[a-z_0-9_]{2,}$/`:
|
|
20
|
-
- Lowercase `a-z`, digits `0-9`, `_` **only**.
|
|
21
|
-
- **Minimum 2 characters**.
|
|
22
|
-
|
|
23
|
-
**Valid ✅**:
|
|
24
|
-
- `myagent`
|
|
25
|
-
- `chatbot`
|
|
26
|
-
- `weather_agent`
|
|
27
|
-
- `tool123`
|
|
28
|
-
- `ws_client`
|
|
29
|
-
|
|
30
|
-
**Invalid ❌ (throws `Error`)**:
|
|
31
|
-
- `MyAgent` (uppercase)
|
|
32
|
-
- `agent-v1` (hyphen)
|
|
33
|
-
- `a` (too short)
|
|
34
|
-
- `agent#tool` (`#` invalid)
|
|
35
|
-
- `Agent_` (uppercase)
|
|
36
|
-
|
|
37
|
-
**Why?** Safe for folders, tool names, filesystems (no specials/caps/spaces).
|
|
38
|
-
|
|
39
|
-
## Quick Usage
|
|
40
|
-
```javascript
|
|
41
|
-
import { AgentManager } from '@j-o-r/hello-dave';
|
|
42
|
-
|
|
43
|
-
const agent = new AgentManager({ name: 'myagent', secret: 'mysecret' });
|
|
44
|
-
agent.setup({
|
|
45
|
-
prompt: 'You are a helpful coding assistant.',
|
|
46
|
-
api: 'xai',
|
|
47
|
-
options: { model: 'grok-4-fast-reasoning' },
|
|
48
|
-
toolsetMode: 'auto',
|
|
49
|
-
contextWindow: 128000
|
|
50
|
-
});
|
|
51
|
-
agent.addGenericToolcall('execute_bash_script');
|
|
52
|
-
|
|
53
|
-
await agent.start(); // CLI mode
|
|
54
|
-
// Or: await agent.directCall('Write a Bash script'); // One-shot
|
|
55
|
-
// Or: await agent.start(8000); // WS server on port 8000
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
## Constructor Options
|
|
59
|
-
| Property | Type | Default | Description |
|
|
60
|
-
|----------|------|---------|-------------|
|
|
61
|
-
| `name` | string | `'agent'` | **Agent ID (session folder, tool name). MUST match `/^[a-z_0-9_]{2,}$/` (lowercase a-z0-9_; ≥2 chars).** |
|
|
62
|
-
| `secret` | string | `''` | WS auth (base64-encoded; optional, match server/client). |
|
|
63
|
-
| `cachePath` | string | `'.cache/hello-dave'` | Session storage root. |
|
|
64
|
-
|
|
65
|
-
## setup(setup) → `this` (chainable)
|
|
66
|
-
Configures the agent. Must call before `start()`/`directCall()`.
|
|
67
|
-
|
|
68
|
-
| Property | Type | Default | Description |
|
|
69
|
-
|----------|------|---------|-------------|
|
|
70
|
-
| `prompt` | string | - | **Required**: System prompt. |
|
|
71
|
-
| `api` | `'xai'|'gpt'|'claude'` | `'gpt'` | LLM provider (uses `lib/API/[provider]/text.js`). |
|
|
72
|
-
| `options` | `XAIOptions`/`OAOptions`/etc. | `{}` | Provider-specific (model, temperature, tools, reasoning). |
|
|
73
|
-
| `contextWindow` | number | `300000` | Token limit for `Prompt`. |
|
|
74
|
-
| `toolsetMode` | `'auto'|'required'` | `null` | `'auto'`: Generic tools; `'required'`: Empty `ToolSet` (add manually). |
|
|
75
|
-
| `debug` | boolean | `false` | Verbose logging. |
|
|
76
|
-
|
|
77
|
-
Internals: Creates `Prompt`, `Session`, sets `Prompt.setAdaptor(API.text[api], toolset, options)`.
|
|
78
|
-
|
|
79
|
-
## Key Methods
|
|
80
|
-
| Method | Args | Returns | Description |
|
|
81
|
-
|--------|------|---------|-------------|
|
|
82
|
-
| `directCall(input)` | `string` | `Promise<string>` | One-shot query (via `prompt.call()`). |
|
|
83
|
-
| `getPrompt()` | - | `Prompt` | Access internal `Prompt`. |
|
|
84
|
-
| `getToolset()` | - | `ToolSet\|void` | Access tools. |
|
|
85
|
-
| `environment()` | - | `Promise<EnvironmentInfo>` | System info (via `fafs.js/env()`). |
|
|
86
|
-
| `addGenericToolcall(name)` | string (e.g., `'read_file'`) | - | Copy from `genericToolset.js` pool. Post-setup only. |
|
|
87
|
-
| `start(servePort?, connectUrl?, cliIntro?, toolName?, toolDesc?)` | Mixed | `Promise<void>` | **Smart launcher**:<br>- `servePort` (num): WS **server** (**toolName** MUST match name regex or auto-gen).<br>- `connectUrl` (str, e.g. `'ws://127.0.0.1:8000/ws'`): WS **client** (toolName/desc for attachment).<br>- Neither: **CLI** mode.<br>- Both: Hybrid. |
|
|
88
|
-
|
|
89
|
-
## Workflow Diagram
|
|
90
|
-
```mermaid
|
|
91
|
-
graph TD
|
|
92
|
-
A[New AgentManager name, secret] --> B[setup prompt, api, options, toolsetMode]
|
|
93
|
-
B --> C{start args?}
|
|
94
|
-
C -->|servePort| D[enableServer port, name, desc<br/>+ optional attach client]
|
|
95
|
-
C -->|connectUrl| E[attach client url, name, desc]
|
|
96
|
-
C -->|none| F[startCli intro]
|
|
97
|
-
D --> G[Session Loop: Prompt → API/Tools → Response]
|
|
98
|
-
E --> G
|
|
99
|
-
F --> G
|
|
100
|
-
G --> H[directCall or persist]
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
**Per-Endpoint Options**:
|
|
104
|
-
- **CLI**: `start()` → `Cli` (interactive/piped). Options via `setup`.
|
|
105
|
-
- **WS Server**: `start(port)` → `AgentServer` (localhost only). Exposes agent as tool (name/desc). `secret` required for clients. `prompt.on('reset')` → `server.resetAll()`.
|
|
106
|
-
- **WS Client**: `start(undefined, url)` → `AgentClient`. Connects to remote server; agent callable as tool.
|
|
107
|
-
- **Direct**: `directCall()` bypasses networking/CLI.
|
|
108
|
-
|
|
109
|
-
## Examples
|
|
110
|
-
|
|
111
|
-
### 1. Interactive CLI Agent
|
|
112
|
-
```javascript
|
|
113
|
-
import { AgentManager } from '@j-o-r/hello-dave';
|
|
114
|
-
|
|
115
|
-
const agent = new AgentManager({ name: 'chatbot' });
|
|
116
|
-
agent.setup({
|
|
117
|
-
prompt: 'You are a friendly chatbot.',
|
|
118
|
-
api: 'xai',
|
|
119
|
-
toolsetMode: 'auto'
|
|
120
|
-
});
|
|
121
|
-
await agent.start('Chatbot ready!'); // Auto-generates intro
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
### 2. WS Server (Expose as Tool)
|
|
125
|
-
```javascript
|
|
126
|
-
import { AgentManager } from '@j-o-r/hello-dave';
|
|
127
|
-
|
|
128
|
-
agent.setup({ ... });
|
|
129
|
-
await agent.start(8000, undefined, undefined, 'weathertool', 'Get real-time weather');
|
|
130
|
-
```
|
|
131
|
-
- Clients: `npx @j-o-r/hello-dave dave --connect ws://localhost:8000/ws --secret mysecret`
|
|
132
|
-
|
|
133
|
-
### 3. Hybrid + Direct Call
|
|
134
|
-
```javascript
|
|
135
|
-
import { AgentManager } from '@j-o-r/hello-dave';
|
|
136
|
-
|
|
137
|
-
await agent.start(8001, 'ws://other:8000/ws'); // Server on 8001 + client to other
|
|
138
|
-
const resp = await agent.directCall('Hybrid query'); // Uses attached tools too
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### 4. Custom Tools + Generics
|
|
142
|
-
```javascript
|
|
143
|
-
import { AgentManager } from '@j-o-r/hello-dave';
|
|
144
|
-
|
|
145
|
-
agent.setup({ toolsetMode: 'required' });
|
|
146
|
-
const ts = agent.getToolset();
|
|
147
|
-
ts.add('custommath', 'Add numbers', {
|
|
148
|
-
type: 'object', properties: {a: {type: 'number'}, b: {type: 'number'}},
|
|
149
|
-
required: ['a', 'b']
|
|
150
|
-
}, async ({a, b}) => a + b);
|
|
151
|
-
agent.addGenericToolcall('javascript_interpreter');
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
## Advanced: Networking & Secrets
|
|
155
|
-
- **Server-Client Chain**: Server A attaches to Server B → A callable from B (and vice versa if mutual).
|
|
156
|
-
- **Cron/CLI Messaging**: Pipe to client: `echo 'query' | npx ... dave --connect ...`
|
|
157
|
-
- **Reset**: `Prompt` emits `'reset'` → propagates to attached servers/clients.
|
|
158
|
-
|
|
159
|
-
## Errors
|
|
160
|
-
- No `setup()`: Throws.
|
|
161
|
-
- **Invalid `name`/`toolName`: Regex `/^[a-z_0-9_]{2,}$/` fail → `Error`.**
|
|
162
|
-
- No `toolset` on server: Throws.
|
|
163
|
-
|
|
164
|
-
See source `lib/AgentManager.js` for full JSDoc/types. Cross-links:
|
|
165
|
-
- [Prompt](./prompt-class.md)
|
|
166
|
-
- [ToolSet](./toolset.md)
|
|
167
|
-
- [Generic Tools](../lib/genericToolset.js)
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
# AgentManager (`lib/AgentManager.js`)
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
**AgentManager** is the central orchestrator class in the hello-dave framework. It manages agent lifecycle: setup (prompts, API, tools, sessions), execution modes (CLI, direct calls, WebSocket server/client), and tool integration. Designed for simplicity and extensibility, it abstracts LLM providers (`xai`, `gpt`, `claude`), `Prompt.js`, `ToolSet.js`, and `Session.js`.
|
|
5
|
-
|
|
6
|
-
Key Features:
|
|
7
|
-
- **Modes**: Interactive CLI, one-shot `directCall`, WS **server** (expose agent as tool), **client** (attach to remote server), hybrid (server + client).
|
|
8
|
-
- **Tool Handling**: Pre-configured (`toolsetMode: 'auto'`/`'required'`), generics (`addGenericToolcall`), custom `ToolSet`.
|
|
9
|
-
- **Persistence**: Sessions in `.cache/[name]/` (NDJSON logs).
|
|
10
|
-
- **Networking**: WS with optional `secret` auth (base64-encoded).
|
|
11
|
-
- **Validation**: Strict name regex `/^[a-z_0-9]{2,}$/`.
|
|
12
|
-
- **Events**: Leverages `Prompt` events (e.g., `reset` → server resetAll).
|
|
13
|
-
|
|
14
|
-
Exports: `default AgentManager`.
|
|
15
|
-
|
|
16
|
-
## Quick Usage
|
|
17
|
-
```javascript
|
|
18
|
-
import AgentManager from '../lib/AgentManager.js'; // or '@j-o-r/hello-dave'
|
|
19
|
-
|
|
20
|
-
const agent = new AgentManager({ name: 'myagent', secret: 'mysecret' });
|
|
21
|
-
agent.setup({
|
|
22
|
-
prompt: 'You are a helpful coding assistant.',
|
|
23
|
-
api: 'xai',
|
|
24
|
-
options: { model: 'grok-4-fast-reasoning' },
|
|
25
|
-
toolsetMode: 'auto',
|
|
26
|
-
contextWindow: 128000
|
|
27
|
-
});
|
|
28
|
-
agent.addGenericToolcall('execute_bash_script');
|
|
29
|
-
|
|
30
|
-
await agent.start(); // CLI mode
|
|
31
|
-
// Or: await agent.directCall('Write a Bash script'); // One-shot
|
|
32
|
-
// Or: await agent.start(8000); // WS server on port 8000
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## Constructor Options
|
|
36
|
-
| Property | Type | Default | Description |
|
|
37
|
-
|----------|------|---------|-------------|
|
|
38
|
-
| `name` | string | `'agent'` | Agent ID (session folder, tool name). Regex: `/^[a-z_0-9]{2,}$/`. |
|
|
39
|
-
| `secret` | string | `''` | WS auth (base64-encoded; optional, match server/client). |
|
|
40
|
-
| `cachePath` | string | `'.cache/hello-dave'` | Session storage root. |
|
|
41
|
-
|
|
42
|
-
## setup(setup) → `this` (chainable)
|
|
43
|
-
Configures the agent. Must call before `start()`/`directCall()`.
|
|
44
|
-
|
|
45
|
-
| Property | Type | Default | Description |
|
|
46
|
-
|----------|------|---------|-------------|
|
|
47
|
-
| `prompt` | string | - | **Required**: System prompt. |
|
|
48
|
-
| `api` | `'xai'|'gpt'|'claude'` | `'gpt'` | LLM provider (uses `lib/API/[provider]/text.js`). |
|
|
49
|
-
| `options` | `XAIOptions`/`OAOptions`/etc. | `{}` | Provider-specific (model, temperature, tools, reasoning). |
|
|
50
|
-
| `contextWindow` | number | `300000` | Token limit for `Prompt`. |
|
|
51
|
-
| `toolsetMode` | `'auto'|'required'` | `null` | `'auto'`: Generic tools; `'required'`: Empty `ToolSet` (add manually). |
|
|
52
|
-
| `debug` | boolean | `false` | Verbose logging. |
|
|
53
|
-
|
|
54
|
-
Internals: Creates `Prompt`, `Session`, sets `Prompt.setAdaptor(API.text[api], toolset, options)`.
|
|
55
|
-
|
|
56
|
-
## Key Methods
|
|
57
|
-
| Method | Args | Returns | Description |
|
|
58
|
-
|--------|------|---------|-------------|
|
|
59
|
-
| `directCall(input)` | `string` | `Promise<string>` | One-shot query (via `prompt.call()`). |
|
|
60
|
-
| `getPrompt()` | - | `Prompt` | Access internal `Prompt`. |
|
|
61
|
-
| `getToolset()` | - | `ToolSet\|void` | Access tools. |
|
|
62
|
-
| `environment()` | - | `Promise<EnvironmentInfo>` | System info (via `fafs.js/env()`). |
|
|
63
|
-
| `addGenericToolcall(name)` | string (e.g., `'read_file'`) | - | Copy from `genericToolset.js` pool. Post-setup only. |
|
|
64
|
-
| `start(servePort?, connectUrl?, cliIntro?, toolName?, toolDesc?)` | Mixed | `Promise<void>` | **Smart launcher**:<br>- `servePort` (num): WS **server** (toolName/desc auto-gen).<br>- `connectUrl` (str, e.g. `'ws://127.0.0.1:8000/ws'`): WS **client** (attach as tool).<br>- Neither: **CLI** mode.<br>- Both: Hybrid server+client. |
|
|
65
|
-
|
|
66
|
-
## Workflow Diagram
|
|
67
|
-
```mermaid
|
|
68
|
-
graph TD
|
|
69
|
-
A[New AgentManager name, secret] --> B[setup prompt, api, options, toolsetMode]
|
|
70
|
-
B --> C{start args?}
|
|
71
|
-
C -->|servePort| D[enableServer port, name, desc<br/>+ optional attach client]
|
|
72
|
-
C -->|connectUrl| E[attach client url, name, desc]
|
|
73
|
-
C -->|none| F[startCli intro]
|
|
74
|
-
D --> G[Session Loop: Prompt → API/Tools → Response]
|
|
75
|
-
E --> G
|
|
76
|
-
F --> G
|
|
77
|
-
G --> H[directCall or persist]
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
**Per-Endpoint Options**:
|
|
81
|
-
- **CLI**: `start()` → `Cli` (interactive/piped). Options via `setup`.
|
|
82
|
-
- **WS Server**: `start(port)` → `AgentServer` (localhost only). Exposes agent as tool (name/desc). `secret` required for clients. `prompt.on('reset')` → `server.resetAll()`.
|
|
83
|
-
- **WS Client**: `start(undefined, url)` → `AgentClient`. Connects to remote server; agent callable as tool.
|
|
84
|
-
- **Direct**: `directCall()` bypasses networking/CLI.
|
|
85
|
-
|
|
86
|
-
## Examples
|
|
87
|
-
|
|
88
|
-
### 1. Interactive CLI Agent
|
|
89
|
-
```javascript
|
|
90
|
-
const agent = new AgentManager({ name: 'chatbot' });
|
|
91
|
-
agent.setup({
|
|
92
|
-
prompt: 'You are a friendly chatbot.',
|
|
93
|
-
api: 'xai',
|
|
94
|
-
toolsetMode: 'auto'
|
|
95
|
-
});
|
|
96
|
-
await agent.start('Chatbot ready!'); // Auto-generates intro
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### 2. WS Server (Expose as Tool)
|
|
100
|
-
```javascript
|
|
101
|
-
agent.setup({ ... });
|
|
102
|
-
await agent.start(8000, undefined, undefined, 'weatherTool', 'Get real-time weather');
|
|
103
|
-
```
|
|
104
|
-
- Clients: `npx @j-o-r/hello-dave dave --connect ws://localhost:8000/ws --secret mysecret`
|
|
105
|
-
|
|
106
|
-
### 3. Hybrid + Direct Call
|
|
107
|
-
```javascript
|
|
108
|
-
await agent.start(8001, 'ws://other:8000/ws'); // Server on 8001 + client to other
|
|
109
|
-
const resp = await agent.directCall('Hybrid query'); // Uses attached tools too
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
### 4. Custom Tools + Generics
|
|
113
|
-
```javascript
|
|
114
|
-
agent.setup({ toolsetMode: 'required' });
|
|
115
|
-
const ts = agent.getToolset();
|
|
116
|
-
ts.add('customMath', 'Add numbers', {
|
|
117
|
-
type: 'object', properties: {a: {type: 'number'}, b: {type: 'number'}},
|
|
118
|
-
required: ['a', 'b']
|
|
119
|
-
}, async ({a, b}) => a + b);
|
|
120
|
-
agent.addGenericToolcall('javascript_interpreter');
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
## Advanced: Networking & Secrets
|
|
124
|
-
- **Server-Client Chain**: Server A attaches to Server B → A callable from B (and vice versa if mutual).
|
|
125
|
-
- **Cron/CLI Messaging**: Pipe to client: `echo 'query' | npx ... dave --connect ...`
|
|
126
|
-
- **Reset**: `Prompt` emits `'reset'` → propagates to attached servers/clients.
|
|
127
|
-
|
|
128
|
-
## Errors
|
|
129
|
-
- No `setup()`: Throws.
|
|
130
|
-
- Invalid `name`/`toolName`: Regex fail.
|
|
131
|
-
- No `toolset` on server: Throws.
|
|
132
|
-
|
|
133
|
-
See source `lib/AgentManager.js` for full JSDoc/types. Cross-links:
|
|
134
|
-
- [Prompt](./prompt-class.md)
|
|
135
|
-
- [ToolSet](./toolset.md)
|
|
136
|
-
- [Generic Tools](../lib/genericToolset.js)
|
|
137
|
-
"
|
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
# AgentManager (`lib/AgentManager.js`)
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
**AgentManager** is the central orchestrator class in the hello-dave framework. It manages agent lifecycle: setup (prompts, API, tools, sessions), execution modes (CLI, direct calls, WebSocket server/client), and tool integration. Designed for simplicity and extensibility, it abstracts LLM providers (`xai`, `gpt`, `claude`), `Prompt.js`, `ToolSet.js`, and `Session.js`.
|
|
5
|
-
|
|
6
|
-
Key Features:
|
|
7
|
-
- **Modes**: Interactive CLI, one-shot `directCall`, WS **server** (expose agent as tool), **client** (attach to remote server), hybrid (server + client).
|
|
8
|
-
- **Tool Handling**: Pre-configured (`toolsetMode: 'auto'`/`'required'`), generics (`addGenericToolcall`), custom `ToolSet`.
|
|
9
|
-
- **Persistence**: Sessions in `.cache/[name]/` (NDJSON logs).
|
|
10
|
-
- **Networking**: WS with optional `secret` auth (base64-encoded).
|
|
11
|
-
- **Validation**: Strict name regex `/^[a-z_0-9_]{2,}$/`.
|
|
12
|
-
- **Events**: Leverages `Prompt` events (e.g., `reset` → server resetAll).
|
|
13
|
-
|
|
14
|
-
Exports: `default AgentManager`.
|
|
15
|
-
|
|
16
|
-
## Agent Naming Rules ⚠️
|
|
17
|
-
**CRITICAL**: The `name` (constructor) and `toolName` (in `start()`) **MUST** match regex `/^[a-z_0-9_]{2,}$/`:
|
|
18
|
-
- Lowercase `a-z`, digits `0-9`, `_` **only**.
|
|
19
|
-
- **Minimum 2 characters**.
|
|
20
|
-
|
|
21
|
-
**Valid ✅**:
|
|
22
|
-
- `myagent`
|
|
23
|
-
- `chatbot`
|
|
24
|
-
- `weather_agent`
|
|
25
|
-
- `tool123`
|
|
26
|
-
- `ws_client`
|
|
27
|
-
|
|
28
|
-
**Invalid ❌ (throws `Error`)**:
|
|
29
|
-
- `MyAgent` (uppercase)
|
|
30
|
-
- `agent-v1` (hyphen)
|
|
31
|
-
- `a` (too short)
|
|
32
|
-
- `agent#tool` (`#` invalid)
|
|
33
|
-
- `Agent_` (uppercase)
|
|
34
|
-
|
|
35
|
-
**Why?** Safe for folders, tool names, filesystems (no specials/caps/spaces).
|
|
36
|
-
|
|
37
|
-
## Quick Usage
|
|
38
|
-
```javascript
|
|
39
|
-
import AgentManager from '../lib/AgentManager.js'; // or '@j-o-r/hello-dave'
|
|
40
|
-
|
|
41
|
-
const agent = new AgentManager({ name: 'myagent', secret: 'mysecret' });
|
|
42
|
-
agent.setup({
|
|
43
|
-
prompt: 'You are a helpful coding assistant.',
|
|
44
|
-
api: 'xai',
|
|
45
|
-
options: { model: 'grok-4-fast-reasoning' },
|
|
46
|
-
toolsetMode: 'auto',
|
|
47
|
-
contextWindow: 128000
|
|
48
|
-
});
|
|
49
|
-
agent.addGenericToolcall('execute_bash_script');
|
|
50
|
-
|
|
51
|
-
await agent.start(); // CLI mode
|
|
52
|
-
// Or: await agent.directCall('Write a Bash script'); // One-shot
|
|
53
|
-
// Or: await agent.start(8000); // WS server on port 8000
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
## Constructor Options
|
|
57
|
-
| Property | Type | Default | Description |
|
|
58
|
-
|----------|------|---------|-------------|
|
|
59
|
-
| `name` | string | `'agent'` | **Agent ID (session folder, tool name). MUST match `/^[a-z_0-9_]{2,}$/` (lowercase a-z0-9_; ≥2 chars).** |
|
|
60
|
-
| `secret` | string | `''` | WS auth (base64-encoded; optional, match server/client). |
|
|
61
|
-
| `cachePath` | string | `'.cache/hello-dave'` | Session storage root. |
|
|
62
|
-
|
|
63
|
-
## setup(setup) → `this` (chainable)
|
|
64
|
-
Configures the agent. Must call before `start()`/`directCall()`.
|
|
65
|
-
|
|
66
|
-
| Property | Type | Default | Description |
|
|
67
|
-
|----------|------|---------|-------------|
|
|
68
|
-
| `prompt` | string | - | **Required**: System prompt. |
|
|
69
|
-
| `api` | `'xai'|'gpt'|'claude'` | `'gpt'` | LLM provider (uses `lib/API/[provider]/text.js`). |
|
|
70
|
-
| `options` | `XAIOptions`/`OAOptions`/etc. | `{}` | Provider-specific (model, temperature, tools, reasoning). |
|
|
71
|
-
| `contextWindow` | number | `300000` | Token limit for `Prompt`. |
|
|
72
|
-
| `toolsetMode` | `'auto'|'required'` | `null` | `'auto'`: Generic tools; `'required'`: Empty `ToolSet` (add manually). |
|
|
73
|
-
| `debug` | boolean | `false` | Verbose logging. |
|
|
74
|
-
|
|
75
|
-
Internals: Creates `Prompt`, `Session`, sets `Prompt.setAdaptor(API.text[api], toolset, options)`.
|
|
76
|
-
|
|
77
|
-
## Key Methods
|
|
78
|
-
| Method | Args | Returns | Description |
|
|
79
|
-
|--------|------|---------|-------------|
|
|
80
|
-
| `directCall(input)` | `string` | `Promise<string>` | One-shot query (via `prompt.call()`). |
|
|
81
|
-
| `getPrompt()` | - | `Prompt` | Access internal `Prompt`. |
|
|
82
|
-
| `getToolset()` | - | `ToolSet\|void` | Access tools. |
|
|
83
|
-
| `environment()` | - | `Promise<EnvironmentInfo>` | System info (via `fafs.js/env()`). |
|
|
84
|
-
| `addGenericToolcall(name)` | string (e.g., `'read_file'`) | - | Copy from `genericToolset.js` pool. Post-setup only. |
|
|
85
|
-
| `start(servePort?, connectUrl?, cliIntro?, toolName?, toolDesc?)` | Mixed | `Promise<void>` | **Smart launcher**:<br>- `servePort` (num): WS **server** (**toolName** MUST match name regex or auto-gen).<br>- `connectUrl` (str, e.g. `'ws://127.0.0.1:8000/ws'`): WS **client** (toolName/desc for attachment).<br>- Neither: **CLI** mode.<br>- Both: Hybrid. |
|
|
86
|
-
|
|
87
|
-
## Workflow Diagram
|
|
88
|
-
```mermaid
|
|
89
|
-
graph TD
|
|
90
|
-
A[New AgentManager name, secret] --> B[setup prompt, api, options, toolsetMode]
|
|
91
|
-
B --> C{start args?}
|
|
92
|
-
C -->|servePort| D[enableServer port, name, desc<br/>+ optional attach client]
|
|
93
|
-
C -->|connectUrl| E[attach client url, name, desc]
|
|
94
|
-
C -->|none| F[startCli intro]
|
|
95
|
-
D --> G[Session Loop: Prompt → API/Tools → Response]
|
|
96
|
-
E --> G
|
|
97
|
-
F --> G
|
|
98
|
-
G --> H[directCall or persist]
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
**Per-Endpoint Options**:
|
|
102
|
-
- **CLI**: `start()` → `Cli` (interactive/piped). Options via `setup`.
|
|
103
|
-
- **WS Server**: `start(port)` → `AgentServer` (localhost only). Exposes agent as tool (name/desc). `secret` required for clients. `prompt.on('reset')` → `server.resetAll()`.
|
|
104
|
-
- **WS Client**: `start(undefined, url)` → `AgentClient`. Connects to remote server; agent callable as tool.
|
|
105
|
-
- **Direct**: `directCall()` bypasses networking/CLI.
|
|
106
|
-
|
|
107
|
-
## Examples
|
|
108
|
-
|
|
109
|
-
### 1. Interactive CLI Agent
|
|
110
|
-
```javascript
|
|
111
|
-
const agent = new AgentManager({ name: 'chatbot' });
|
|
112
|
-
agent.setup({
|
|
113
|
-
prompt: 'You are a friendly chatbot.',
|
|
114
|
-
api: 'xai',
|
|
115
|
-
toolsetMode: 'auto'
|
|
116
|
-
});
|
|
117
|
-
await agent.start('Chatbot ready!'); // Auto-generates intro
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
### 2. WS Server (Expose as Tool)
|
|
121
|
-
```javascript
|
|
122
|
-
agent.setup({ ... });
|
|
123
|
-
await agent.start(8000, undefined, undefined, 'weathertool', 'Get real-time weather');
|
|
124
|
-
```
|
|
125
|
-
- Clients: `npx @j-o-r/hello-dave dave --connect ws://localhost:8000/ws --secret mysecret`
|
|
126
|
-
|
|
127
|
-
### 3. Hybrid + Direct Call
|
|
128
|
-
```javascript
|
|
129
|
-
await agent.start(8001, 'ws://other:8000/ws'); // Server on 8001 + client to other
|
|
130
|
-
const resp = await agent.directCall('Hybrid query'); // Uses attached tools too
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### 4. Custom Tools + Generics
|
|
134
|
-
```javascript
|
|
135
|
-
agent.setup({ toolsetMode: 'required' });
|
|
136
|
-
const ts = agent.getToolset();
|
|
137
|
-
ts.add('customMath', 'Add numbers', {
|
|
138
|
-
type: 'object', properties: {a: {type: 'number'}, b: {type: 'number'}},
|
|
139
|
-
required: ['a', 'b']
|
|
140
|
-
}, async ({a, b}) => a + b);
|
|
141
|
-
agent.addGenericToolcall('javascript_interpreter');
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
## Advanced: Networking & Secrets
|
|
145
|
-
- **Server-Client Chain**: Server A attaches to Server B → A callable from B (and vice versa if mutual).
|
|
146
|
-
- **Cron/CLI Messaging**: Pipe to client: `echo 'query' | npx ... dave --connect ...`
|
|
147
|
-
- **Reset**: `Prompt` emits `'reset'` → propagates to attached servers/clients.
|
|
148
|
-
|
|
149
|
-
## Errors
|
|
150
|
-
- No `setup()`: Throws.
|
|
151
|
-
- **Invalid `name`/`toolName`: Regex `/^[a-z_0-9_]{2,}$/` fail → `Error`.**
|
|
152
|
-
- No `toolset` on server: Throws.
|
|
153
|
-
|
|
154
|
-
See source `lib/AgentManager.js` for full JSDoc/types. Cross-links:
|
|
155
|
-
- [Prompt](./prompt-class.md)
|
|
156
|
-
- [ToolSet](./toolset.md)
|
|
157
|
-
- [Generic Tools](../lib/genericToolset.js)
|
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
# CodeServer Pattern
|
|
2
|
-
|
|
3
|
-
[](https://pm2.keymetrics.io/) [](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API)
|
|
4
|
-
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Introduction & Motivation](#introduction--motivation)
|
|
8
|
-
- [Architecture](#architecture)
|
|
9
|
-
- [Prerequisites](#prerequisites)
|
|
10
|
-
- [Step-by-Step Setup](#step-by-step-setup)
|
|
11
|
-
- [Interaction via \`bin/dave.js\`](#interaction-via-bindavejs)
|
|
12
|
-
- [Monitoring & Stopping with PM2](#monitoring--stopping-with-pm2)
|
|
13
|
-
- [Customization](#customization)
|
|
14
|
-
- [Benefits](#benefits)
|
|
15
|
-
- [Troubleshooting](#troubleshooting)
|
|
16
|
-
- [Integration with AgentManager](#integration-with-agentmanager)
|
|
17
|
-
- [References](#references)
|
|
18
|
-
|
|
19
|
-
## Introduction & Motivation
|
|
20
|
-
|
|
21
|
-
The **CodeServer pattern** demonstrates a production-ready setup for running a **persistent, always-on agent server** managed by [PM2](https://pm2.keymetrics.io/). It launches:
|
|
22
|
-
|
|
23
|
-
- **Main Server**: \`code_agent.js\` as a WebSocket server (code-focused agent with JavaScript tools).
|
|
24
|
-
- **Sub-Agents (Clients)**: Specialized agents (\`todo_agent.js\`, \`readme_agent.js\`, \`npm_agent.js\`, \`docs_agent.js\`) that **attach as tools** to the main server via WebSocket.
|
|
25
|
-
|
|
26
|
-
**Motivation**:
|
|
27
|
-
- **Persistence**: Long-running sessions without restarts (state in \`.cache/hello-dave/[agent]/\`).
|
|
28
|
-
- **Delegation**: Main agent delegates to specialists (e.g., "update docs" → \`docsDave\` tool).
|
|
29
|
-
- **No Heartbeats**: PM2 handles restarts, monitoring—no custom pings.
|
|
30
|
-
- **Scalability**: Easy to add sub-agents, deploy across machines.
|
|
31
|
-
- **CLI-Friendly**: Interact via \`bin/dave.js --connect\`.
|
|
32
|
-
|
|
33
|
-
Ideal for dev workflows: code execution, docs mgmt, npm inspection, todos—all in one persistent hub.
|
|
34
|
-
|
|
35
|
-
See live example: [examples/CodeServer](../examples/CodeServer)
|
|
36
|
-
|
|
37
|
-
## Architecture
|
|
38
|
-
|
|
39
|
-
```mermaid
|
|
40
|
-
graph TB
|
|
41
|
-
PM2[PM2 Process Manager] --> Main[Main: code_agent.js<br/>--serve PORT --secret SECRET<br/>WS Server on /ws]
|
|
42
|
-
PM2 --> Todo[todo_agent.js<br/>--connect ws://localhost:PORT/ws<br/>tool: todo_agent]
|
|
43
|
-
PM2 --> Readme[readme_agent.js<br/>--connect ...<br/>tool: readme_agent]
|
|
44
|
-
PM2 --> NPM[npm_agent.js<br/>--connect ...<br/>tool: npm_module_inspector]
|
|
45
|
-
PM2 --> Docs[docs_agent.js<br/>--connect ...<br/>tool: agent_docs]
|
|
46
|
-
|
|
47
|
-
User[bin/dave.js --connect] -.-> Main
|
|
48
|
-
Main -->|Delegates via tools| Todo & Readme & NPM & Docs
|
|
49
|
-
Todo -.->|File ops| ProjectFiles[(TODO.md, etc.)]
|
|
50
|
-
Docs -.->|Docs mgmt| DocsFolder[./docs/*.md]
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
**Key Flows**:
|
|
54
|
-
1. PM2 spawns all processes (named \`FOLDER_agent_PORT\`).
|
|
55
|
-
2. Clients connect to main server → auto-register as **tools** (e.g., \`todo_agent\`, \`readme_agent\`).
|
|
56
|
-
3. User queries main server → delegates (e.g., \`call todo_agent {add: "new task"}\`).
|
|
57
|
-
4. Sessions persist independently per agent.
|
|
58
|
-
|
|
59
|
-
## Prerequisites
|
|
60
|
-
|
|
61
|
-
| Requirement | Install Command | Notes |
|
|
62
|
-
|-------------|-----------------|-------|
|
|
63
|
-
| **Node.js** | `node --version` (≥18) | ESM support required. |
|
|
64
|
-
| **PM2** | `npm i -g pm2` | Process manager. Startup: `pm2 startup`. |
|
|
65
|
-
| **Project** | `git clone <repo> && cd hello-dave` | Examples in \`./examples/\`. |
|
|
66
|
-
|
|
67
|
-
Verify: `pm2 --version` & `node -e "import('@j-o-r/hello-dave')"`
|
|
68
|
-
|
|
69
|
-
## Step-by-Step Setup
|
|
70
|
-
|
|
71
|
-
1. **Navigate to project**:
|
|
72
|
-
```bash
|
|
73
|
-
cd /path/to/hello-dave
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
2. **Launch CodeServer** (pick PORT 1024-65535, SECRET ≥3 chars):
|
|
77
|
-
```bash
|
|
78
|
-
./examples/CodeServer 8080 mysecret123
|
|
79
|
-
```
|
|
80
|
-
Output:
|
|
81
|
-
```
|
|
82
|
-
Starting CodeServer on port 8080 in folder 'hello-dave' ... with SECRET 'mysecret123'
|
|
83
|
-
CodeServer processes spawned with prefix 'hello-dave_' and suffix _8080.
|
|
84
|
-
dave --connect ws://127.0.0.1:8080/ws --secret 'mysecret123'
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
3. **Verify PM2**:
|
|
88
|
-
```bash
|
|
89
|
-
pm2 list | grep 8080
|
|
90
|
-
```
|
|
91
|
-
| Name | Status | CPU | Memory |
|
|
92
|
-
|-----------------------|--------|-----|--------|
|
|
93
|
-
| hello-dave_code_agent_8080 | online | ... | ... |
|
|
94
|
-
| hello-dave_todo_agent_8080 | online | ... | ... |
|
|
95
|
-
| ... (4 total) | ... | ... | ... |
|
|
96
|
-
|
|
97
|
-
## Interaction via \`bin/dave.js\`
|
|
98
|
-
|
|
99
|
-
**Interactive**:
|
|
100
|
-
```bash
|
|
101
|
-
./bin/dave.js --connect 'ws://localhost:8080/ws' --secret 'mysecret123'
|
|
102
|
-
```
|
|
103
|
-
- Chat with **code_agent** (main agent).
|
|
104
|
-
- Delegates automatically: "Manage todos", "Inspect @j-o-r/cli", "Update docs/codeserver-pattern.md".
|
|
105
|
-
|
|
106
|
-
**Piped (one-shot)**:
|
|
107
|
-
```bash
|
|
108
|
-
echo "List pending todos" | ./bin/dave.js --connect 'ws://localhost:8080/ws' --secret 'mysecret123'
|
|
109
|
-
echo "user_reset" | ./bin/dave.js --connect ... # Reset session
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
**Delegation Examples**:
|
|
113
|
-
- \`code_agent\`: "Use todo_agent to add 'Review PRs'"
|
|
114
|
-
- \`code_agent\`: "Call agent_docs to create nodejs-guide.md"
|
|
115
|
-
|
|
116
|
-
## Monitoring & Stopping with PM2
|
|
117
|
-
|
|
118
|
-
**Monitor**:
|
|
119
|
-
- `pm2 list` / `pm2 monit` (dashboard)
|
|
120
|
-
- `pm2 logs hello-dave_code_agent_8080` (agent logs)
|
|
121
|
-
- `pm2 logs *8080 --lines 50`
|
|
122
|
-
|
|
123
|
-
**Stop**:
|
|
124
|
-
```bash
|
|
125
|
-
pm2 stop hello-dave_*_8080 # All related
|
|
126
|
-
# Or delete:
|
|
127
|
-
pm2 delete hello-dave_code_agent_8080 hello-dave_todo_agent_8080 ...
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
**Startup** (auto-restart on boot): `pm2 save && pm2 startup`
|
|
131
|
-
|
|
132
|
-
## Customization
|
|
133
|
-
|
|
134
|
-
### Adding Sub-Agents
|
|
135
|
-
Edit [examples/CodeServer](../examples/CodeServer):
|
|
136
|
-
```bash
|
|
137
|
-
# Add new agent
|
|
138
|
-
pm2 start "${SCRIPT_DIR}/newAgent.js" --name "${FOLDER}_new_agent_${PORT}" -- --connect "ws://127.0.0.1:${PORT}/ws" --secret "${SECRET}"
|
|
139
|
-
```
|
|
140
|
-
- Create \`newAgent.js\` like [examples/todo_agent.js](../examples/todo_agent.js): Set \`tool_call_name\`, prompt.
|
|
141
|
-
|
|
142
|
-
### Changing Tools
|
|
143
|
-
- Main server: Edit \`code_agent.js\`: \`--tools javascript,bash,ssh\`
|
|
144
|
-
- Sub-agents: \`agent.addGenericToolcall('read_file')\` etc. See [toolset.md](../toolset.md).
|
|
145
|
-
|
|
146
|
-
### Prompts/Models
|
|
147
|
-
- Per-agent: Edit JS files (e.g., \`options.model = 'grok-4-1-fast-reasoning'\`).
|
|
148
|
-
|
|
149
|
-
## Benefits
|
|
150
|
-
|
|
151
|
-
| Feature | Advantage |
|
|
152
|
-
|---------|-----------|
|
|
153
|
-
| **Persistent Sessions** | State in \`.cache/hello-dave/[name]/sessions/\`—no re-explaining. |
|
|
154
|
-
| **Delegation** | Main agent uses sub-agents as tools (parallel, specialized). |
|
|
155
|
-
| **No Heartbeat** | PM2 restarts on crash; no custom logic. |
|
|
156
|
-
| **Resource Efficient** | Shared context; subs only active on call. |
|
|
157
|
-
| **Portable** | Script auto-prefixes PM2 names by folder/port. |
|
|
158
|
-
|
|
159
|
-
## Troubleshooting
|
|
160
|
-
|
|
161
|
-
| Issue | Solution |
|
|
162
|
-
|-------|----------|
|
|
163
|
-
| **Port in use** | Change PORT; `lsof -i :8080` & `kill`. |
|
|
164
|
-
| **Secret mismatch** | Ensure exact match (no extra spaces). |
|
|
165
|
-
| **PM2 not found** | `npm i -g pm2`. |
|
|
166
|
-
| **Connection refused** | Wait 5s for server startup; check `pm2 logs`. |
|
|
167
|
-
| **No delegation** | Verify client tool names in JS (e.g., \`todo_agent\`). |
|
|
168
|
-
| **High memory** | `pm2 del *` or tweak \`contextWindow\`. |
|
|
169
|
-
|
|
170
|
-
Logs: `.cache/hello-dave/[agent]/sessions/*.ndjson` (use \`bin/dave.js --inspect log.ndjson\`).
|
|
171
|
-
|
|
172
|
-
## Integration with AgentManager
|
|
173
|
-
|
|
174
|
-
Built on [AgentManager](../docs/agent-manager.md):
|
|
175
|
-
|
|
176
|
-
- **Server**: `agent.start(PORT)` → WS server exposing \`code_agent\`.
|
|
177
|
-
- **Clients**: `agent.start(undefined, 'ws://...', undefined, 'todo_agent', 'desc')` → Attaches as tool.
|
|
178
|
-
|
|
179
|
-
**Tools**: Generic from [toolset.md](../docs/toolset.md) (e.g., \`execute_bash_script\`, \`javascript_interpreter\`).
|
|
180
|
-
|
|
181
|
-
Cross-links:
|
|
182
|
-
- [Prompt Class](../docs/prompt-class.md)
|
|
183
|
-
- [Generic Tools](../lib/genericToolset.js)
|
|
184
|
-
|
|
185
|
-
## References
|
|
186
|
-
|
|
187
|
-
- [PM2 Docs](https://pm2.keymetrics.io/docs/usage/quick-start/)
|
|
188
|
-
- Examples: [CodeServer](../examples/CodeServer), [code_agent.js](../examples/code_agent.js), [todo_agent.js](../examples/todo_agent.js), etc.
|
|
189
|
-
- Sessions: \`bin/dave.js --list\`
|
|
190
|
-
|
|
191
|
-
**Updated**: March 24, 2026
|