@j-o-r/hello-dave 0.0.5 → 0.0.7

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 (127) hide show
  1. package/CHANGELOG.md +13 -26
  2. package/README.md +161 -522
  3. package/README.md.bak +144 -449
  4. package/{examples → agents}/ask_agent.js +5 -5
  5. package/{examples → agents}/codeserver.sh +14 -14
  6. package/{examples → agents}/daisy_agent.js +5 -5
  7. package/{examples → agents}/docs_agent.js +5 -5
  8. package/{examples → agents}/gpt_agent.js +5 -5
  9. package/{examples → agents}/grok_agent.js +5 -5
  10. package/agents/memory_agent.js +263 -0
  11. package/{examples → agents}/npm_agent.js +5 -5
  12. package/{examples → agents}/prompt_agent.js +5 -5
  13. package/agents/spawn_agent.js +137 -0
  14. package/{examples → agents}/test_agent.js +6 -8
  15. package/{examples → agents}/todo_agent.js +5 -5
  16. package/bin/codeDave +58 -0
  17. package/bin/dave.js +114 -96
  18. package/lib/AgentClient.js +111 -67
  19. package/lib/AgentManager.js +111 -80
  20. package/lib/AgentServer.js +144 -104
  21. package/lib/Cli.js +126 -93
  22. package/lib/Prompt.js +38 -5
  23. package/lib/Session.js +102 -79
  24. package/lib/ToolSet.js +79 -60
  25. package/lib/fafs.js +54 -19
  26. package/lib/genericToolset.js +109 -213
  27. package/lib/wsCli.js +50 -19
  28. package/lib/wsIO.js +11 -17
  29. package/package.json +2 -2
  30. package/types/AgentClient.d.ts +69 -35
  31. package/types/AgentManager.d.ts +50 -56
  32. package/types/AgentServer.d.ts +63 -16
  33. package/types/Cli.d.ts +56 -10
  34. package/types/Prompt.d.ts +36 -4
  35. package/types/Session.d.ts +23 -9
  36. package/types/ToolSet.d.ts +49 -32
  37. package/types/fafs.d.ts +68 -25
  38. package/types/wsCli.d.ts +14 -0
  39. package/types/wsIO.d.ts +9 -5
  40. package/utils/search_sessions.sh +100 -53
  41. package/README.md.backup +0 -269
  42. package/README.md.bak.1774780058 +0 -338
  43. package/README.md.bak2 +0 -531
  44. package/bin/spawn_agent.js +0 -293
  45. package/docs.bak.1774780058/agent-manager.md +0 -167
  46. package/docs.bak.1774780058/agent-manager.md.bak +0 -137
  47. package/docs.bak.1774780058/agent-manager.md.bak2 +0 -157
  48. package/docs.bak.1774780058/codeserver-pattern.md +0 -191
  49. package/docs.bak.1774780058/path-resolution-best-practices.md +0 -104
  50. package/docs.bak.1774780058/project-overview.md +0 -67
  51. package/docs.bak.1774780058/project-overview.md.bak +0 -67
  52. package/docs.bak.1774780058/prompt-class.md +0 -141
  53. package/docs.bak.1774780058/prompt-class.md.bak +0 -142
  54. package/docs.bak.1774780058/tools-syntax-validation.md +0 -121
  55. package/docs.bak.1774780058/tools-syntax-validation.md.bak2 +0 -125
  56. package/docs.bak.1774780058/tools-syntax-validation.md.bak3 +0 -125
  57. package/docs.bak.1774780058/tools-syntax-validation.md.bak4 +0 -106
  58. package/docs.bak.1774780058/tools-syntax-validation.md.bak_path +0 -106
  59. package/docs.bak.1774780058/toolset.md +0 -164
  60. package/docs.bak.1774780058/toolset.md.bak +0 -94
  61. package/docs.bak.1774780058/toolset.md.bak3 +0 -161
  62. package/docs.bak.1774780058/toolset.md.bak4 +0 -161
  63. package/docs.bak.1774780058/toolset.md.bak5 +0 -161
  64. package/docs.bak.1774780058/toolset.md.bak6 +0 -163
  65. package/docs.bak.1774780058/toolset.md.bak_path +0 -163
  66. package/docs.bak.1774780058/toolset.md.bak_syntax +0 -161
  67. package/docs.bak.1774780058/xai-responses.md +0 -111
  68. package/docs.bak.1774780058/xai-responses.md.bak +0 -107
  69. package/docs.bak.1774780058/xai-responses.md.bak2 +0 -107
  70. package/docs.bak.1774780058/xai_collections.md +0 -106
  71. package/examples/memory_agent.js +0 -152
  72. package/examples.bak.1774780058/ask_agent.js +0 -114
  73. package/examples.bak.1774780058/code_agent.js +0 -149
  74. package/examples.bak.1774780058/coderev_agent.js +0 -72
  75. package/examples.bak.1774780058/codeserver.sh +0 -47
  76. package/examples.bak.1774780058/daisy_agent.js +0 -177
  77. package/examples.bak.1774780058/docs_agent.js +0 -119
  78. package/examples.bak.1774780058/gpt_agent.js +0 -109
  79. package/examples.bak.1774780058/grok_agent.js +0 -98
  80. package/examples.bak.1774780058/memory_agent.js +0 -112
  81. package/examples.bak.1774780058/npm_agent.js +0 -175
  82. package/examples.bak.1774780058/prompt_agent.js +0 -112
  83. package/examples.bak.1774780058/readme_agent.js +0 -144
  84. package/examples.bak.1774780058/spawn_agent.js +0 -263
  85. package/examples.bak.1774780058/test_agent.js +0 -162
  86. package/examples.bak.1774780058/todo_agent.js +0 -138
  87. package/lib/genericToolset.js.bak_syntax +0 -402
  88. package/scenarios.bak.1774780058/data/eval_node_message.json +0 -9
  89. package/scenarios.bak.1774780058/data/hist_oa.json +0 -66
  90. package/scenarios.bak.1774780058/data/o3_response1.json +0 -96
  91. package/scenarios.bak.1774780058/data/oa_reasoning_parse.json +0 -112
  92. package/scenarios.bak.1774780058/data/tool_oa.json +0 -96
  93. package/scenarios.bak.1774780058/data/tool_xai.json +0 -59
  94. package/scenarios.bak.1774780058/data/tool_xai2.json +0 -40
  95. package/scenarios.bak.1774780058/data/xai-response-1.json +0 -59
  96. package/scenarios.bak.1774780058/data/xai-response-2.json +0 -10
  97. package/scenarios.bak.1774780058/data/xai_reasoning_tools_resp.json +0 -59
  98. package/scenarios.bak.1774780058/data/xai_search_response.json +0 -58
  99. package/scenarios.bak.1774780058/environment.js +0 -10
  100. package/scenarios.bak.1774780058/example.js +0 -17
  101. package/scenarios.bak.1774780058/genericToolset.test.js +0 -182
  102. package/scenarios.bak.1774780058/grok.js +0 -113
  103. package/scenarios.bak.1774780058/memory-tools.js +0 -51
  104. package/scenarios.bak.1774780058/openai-o3.js +0 -137
  105. package/scenarios.bak.1774780058/openai-prompt.js +0 -155
  106. package/scenarios.bak.1774780058/openai-session.js +0 -148
  107. package/scenarios.bak.1774780058/openai.js +0 -102
  108. package/scenarios.bak.1774780058/prompt.js +0 -118
  109. package/scenarios.bak.1774780058/promptFishbowl.js +0 -76
  110. package/scenarios.bak.1774780058/search.brave.com.js +0 -25
  111. package/scenarios.bak.1774780058/sh.js +0 -15
  112. package/scenarios.bak.1774780058/test-wsio.js +0 -26
  113. package/scenarios.bak.1774780058/testToolset.js +0 -42
  114. package/scenarios.bak.1774780058/toolset.js +0 -16
  115. package/scenarios.bak.1774780058/toolset.test.js +0 -141
  116. package/scenarios.bak.1774780058/write_file_syntax.test.js +0 -145
  117. package/scenarios.bak.1774780058/write_file_validation/README.md +0 -30
  118. package/scenarios.bak.1774780058/write_file_validation/bad.js +0 -3
  119. package/scenarios.bak.1774780058/write_file_validation/good.js +0 -4
  120. package/scenarios.bak.1774780058/write_file_validation/test.sh +0 -43
  121. package/scenarios.bak.1774780058/wsClient.js +0 -69
  122. package/scenarios.bak.1774780058/xai_responses.integration.test.js +0 -57
  123. package/scenarios.bak.1774780058/xai_responses.test.js +0 -154
  124. package/scenarios.bak.1774780058/xaicoll.js +0 -50
  125. package/scenarios.bak.1774780058/xaifiles.js +0 -48
  126. /package/{examples → agents}/code_agent.js +0 -0
  127. /package/{examples → agents}/readme_agent.js +0 -0
@@ -1,161 +0,0 @@
1
- # ToolSet (\`lib/ToolSet.js\`)
2
-
3
- ## Overview
4
- **ToolSet** manages LLM function calls (tools): registration, execution, listing. Integrates with \`Prompt.js\` (via \`execute(prompt)\`) and \`AgentManager.js\` (pre-configured modes, generics). Supports JSON Schema params, async methods. Exports from \`lib/genericToolset.js\`: \`toolsPool\` (11 pre-built tools).
5
-
6
- **Uses named exports from \`lib/index.js\` - NO default export.**
7
-
8
- Key Features:
9
- - **Modes**: \`toolChoice: 'auto'|'none'|'required'\` (default \`'auto'\`).
10
- - **Validation**: Name regex \`/^\[#![a-z_0-9]{2,}$/\`.
11
- - **Events** (via \`Prompt\`): \`tool_request\`, \`tool_error\`, \`tool_response\`.
12
- - **Execution**: \`execute(prompt)\` processes \`function_request\`s from last message → calls → adds \`function_response\`s.
13
-
14
- ## Constructor
15
- \`\`\`javascript
16
- import { ToolSet } from '@j-o-r/hello-dave';
17
-
18
- new ToolSet(choice = 'auto'); // 'auto'|'none'|'required'
19
- \`\`\`
20
-
21
- ## Methods
22
- | Method | Args | Returns | Description |
23
- |--------|------|---------|-------------|
24
- | \`add(name, desc, params, method)\` | \`string\`, \`string\`, \`TSSchema\`, \`async (params) => *\` | \`void\` | Register tool. Overwrites if exists. |
25
- | \`get(name)\` | \`string\` | \`TSTool\` | Get tool details. |
26
- | \`delete(name)\` | \`string\` | \`void\` | Remove tool. |
27
- | \`has(name)\` | \`string\` | \`boolean\` | Exists? |
28
- | \`list()\` | - | \`TSToolListItem[]\` (sorted) | All tools (name/desc/params). |
29
- | \`call(name, params)\` | \`string\`, \`object\` | \`Promise<*\>\` | Execute tool. |
30
- | \`execute(prompt)\` | \`Prompt\` | \`Promise<void>\` | Process last message \`function_request\`s → execute → add \`function_response\`s to \`tool\` role. |
31
- | \`length\` | - | \`number\` | Tool count. |
32
- | \`toolChoice\` | - | \`string\` | Getter for mode. |
33
-
34
- **TSTool**: \`{description: string, parameters: TSSchema, method: async (params) => *}\`
35
- **TSSchema**: OpenAI-style JSON Schema (\`{type: 'object', properties: {...}, required: [...]}\`).
36
-
37
- ## Generic Tools (\`lib/genericToolset.js\` → \`toolsPool\`)
38
- Pre-built \`ToolSet('auto')\` with **11 tools**. Copied via \`AgentManager.addGenericToolcall(name)\` or \`toolsetMode: 'auto'\`.
39
-
40
- | Tool Name | Description |
41
- |----------------------------|-------------|
42
- | \`javascript_interpreter\` | Execute ESM ES6 JavaScript on \`node\`. \`console.log\` captures output. cwd: \`~/devpri/js/hello-dave\`. |
43
- | \`get_user_env\` | Get user environment (name, system, city/region/country/timezone, external IP). |
44
- | \`execute_bash_script\` | Execute raw Bash script/command (no escaping; verbatim \`$\| < > & " ' \\\\` newlines \`$(())\` \`[[ ]]\`. Heredoc-safe). Ubuntu 25.10. |
45
- | \`send_email\` | Send email via \`msmtp\` (to, subject, body). |
46
- | \`open_link\` | Open URL/file with \`xdg-open\`. |
47
- | \`execute_remote_script\` | Execute raw Bash on remote via SSH (\`ssh://user@host[:port]\`). |
48
- | \`history_search\` | Search chat sessions: \`"(todo\\|task)"\` or \`"package.json"\`. Regex in \`.cache/[app]/[prompt]/sessions/*.ndjson\`. |
49
- | \`read_file\` | Read raw file in CWD (relative path, no \`/\` \`..\` \`\\\\\`). |
50
- | \`write_file\` | Write raw content to file in CWD (relative, as-is; no escaping). Returns bytes written. |
51
- | \`memory_recall\` | Recall persistent memory entries from agent-specific storage (\`.cache/[agent]/memory.ndjson\`). |
52
- | \`memory_write\` | Write/update persistent memory entries for long-term state (\`.cache/[agent]/memory.ndjson\`). |
53
-
54
- ## Memory Tools (New)
55
- These tools provide persistent, agent-specific memory storage in NDJSON format (\`.cache/[agent-name]/memory.ndjson\`). Append-only; latest value per key. Ideal for token efficiency by offloading state/decisions from context.
56
-
57
- ### \`memory_recall\`
58
- **Description**: Retrieve the latest values for specified keys from memory file. Returns JSON: \`{key: value, ...}\` or \`{}\` if missing.
59
-
60
- **Parameters**:
61
- \`\`\`json
62
- {
63
- "type": "object",
64
- "properties": {
65
- "keys": {
66
- "type": "array",
67
- "items": { "type": "string" },
68
- "description": "List of memory keys to recall, e.g., ['current_task', 'last_decision']"
69
- }
70
- },
71
- "required": ["keys"]
72
- }
73
- \`\`\`
74
-
75
- **Example Usage in Agent Prompt**:
76
- \`\`\`
77
- Before proceeding, recall your current task and previous decision:
78
- - Call memory_recall with keys: ["current_task", "last_decision"]
79
- Then, use the recalled info to avoid repetition.
80
- \`\`\`
81
-
82
- **Token Efficiency**: Stores tasks/decisions externally. Recall only needed state (e.g., 100 tokens) vs. full history (10k+ tokens), preventing loops/re-reasoning.
83
-
84
- ### \`memory_write\`
85
- **Description**: Append/update key-value pairs to memory (overwrites prior same-key entries). Returns confirmation with stored entries.
86
-
87
- **Parameters**:
88
- \`\`\`json
89
- {
90
- "type": "object",
91
- "properties": {
92
- "entries": {
93
- "type": "array",
94
- "items": {
95
- "type": "object",
96
- "properties": {
97
- "key": { "type": "string", "description": "Unique key (e.g., 'current_task')" },
98
- "value": { "type": "string", "description": "JSON-stringifiable value" }
99
- },
100
- "required": ["key", "value"]
101
- },
102
- "description": "List of {key, value} pairs to store"
103
- }
104
- },
105
- "required": ["entries"]
106
- }
107
- \`\`\`
108
-
109
- **Example Usage in Agent Prompt**:
110
- \`\`\`
111
- After analyzing, store the plan:
112
- - Call memory_write with entries: [{"key": "current_task", "value": "Implement login feature"}, {"key": "step", "value": "1/5"}]
113
- \`\`\`
114
-
115
- **Token Efficiency**: Persist intermediate results across calls/sessions. Avoids context explosion/loops by recalling compact state instead of regenerating.
116
-
117
- ## Integration with AgentManager
118
- In \`setup()\`:
119
- \`\`\`javascript
120
- agent.setup({
121
- toolsetMode: 'auto', // Loads all 11 generic tools
122
- // or 'required': Empty ToolSet (add manually)
123
- });
124
- agent.addGenericToolcall('memory_recall'); // Selective copy post-setup
125
- \`\`\`
126
-
127
- **Custom Tools**:
128
- \`\`\`javascript
129
- import { AgentManager } from '@j-o-r/hello-dave';
130
-
131
- agent.setup({ toolsetMode: 'required' });
132
- const ts = agent.getToolset();
133
- ts.add('math', 'Add numbers', {
134
- type: 'object',
135
- properties: {a: {type: 'number'}, b: {type: 'number'}},
136
- required: ['a', 'b']
137
- }, async ({a, b}) => a + b);
138
- \`\`\`
139
-
140
- **Workflow** (in \`Prompt.call()\` / API adapters):
141
- 1. LLM → \`function_request\`s (assistant message).
142
- 2. \`ToolSet.execute(prompt)\` → parallel \`call()\` → \`function_response\`s (tool message).
143
- 3. Recurse until text response.
144
-
145
- ## Examples
146
- ### Standalone ToolSet
147
- \`\`\`javascript
148
- import { ToolSet } from '@j-o-r/hello-dave';
149
-
150
- const ts = new ToolSet('required');
151
- ts.add('hello', 'Say hello', {type: 'object', properties: {name: {type: 'string'}}, required: ['name']},
152
- async ({name}) => \`Hello, \${name}!\`);
153
- console.log(await ts.call('hello', {name: 'World'})); // "Hello, World!"
154
- \`\`\`
155
-
156
- ### With Prompt/AgentManager
157
- See [AgentManager](./agent-manager.md#custom-tools--generics), [Prompt](./prompt-class.md).
158
-
159
- **Updated:** March 26, 2026 (11 generics from \`lib/genericToolset.js\`).
160
-
161
- See also: [GenericToolset Source](./generic-toolset.md).
@@ -1,111 +0,0 @@
1
- # xAI Responses API Integration (`lib/API/x.ai/responses.js`)
2
-
3
- ## Overview
4
- This module provides a seamless wrapper for the [xAI Responses API](https://docs.x.ai/docs/api-reference#create-new-response) (formerly Grok API), adapted for the hello-dave framework. It integrates directly with `Prompt.js` and `ToolSet.js`, enabling tool-using agents via `AgentManager`.
5
-
6
- **Uses named exports from `lib/index.js` - NO default export.**
7
-
8
- Key adaptations:
9
- - **Unified Interface**: Uses `Prompt` messages/history for input; parses `output` into assistant/tool responses.
10
- - **Recursive Tool Calls**: Automatically handles `function_call` → execute tools → `function_call_output` loops (up to `GLOBAL.max_recursive_requests`).
11
- - **Tool Support**: Converts `ToolSet` to xAI `function` tools; supports native xAI tools like `web_search`, `x_search`.
12
- - **Reasoning & Search**: Configurable `reasoning.effort` (`low`/`medium`/`high`), `search_parameters`.
13
- - **Streaming**: Not yet implemented (future).
14
- - **Auth**: Requires `XAIKEY` env var.
15
-
16
- Default model: `grok-4-fast-reasoning`. Supports: `grok-4-fast-reasoning`, `grok-4-fast-non-reasoning`, etc.
17
-
18
- ## Usage in AgentManager
19
- ```javascript
20
- import { AgentManager } from '@j-o-r/hello-dave';
21
-
22
- const agent = new AgentManager({ name: 'weatheragent', secret: 'optional-ws-secret' });
23
- agent.setup({
24
- prompt: 'You are a precise weather expert. Use tools for real-time data.',
25
- api: 'xai',
26
- options: { model: 'grok-4-fast-reasoning', reasoning: { effort: 'high' } },
27
- toolsetMode: 'auto', // Adds generic tools like web_search
28
- contextWindow: 128000
29
- });
30
- agent.addGenericToolcall('web_search'); // Optional: Add extras
31
-
32
- // CLI mode
33
- agent.start(); // Interactive chat
34
-
35
- // Or direct call
36
- const response = await agent.directCall('Weather in Amsterdam today?');
37
- console.log(response); // Handles search/tools automatically
38
- ```
39
-
40
- Under the hood:
41
- 1. `Prompt.setAdaptor(API.text['xai'], toolset, options)` → uses `responses.request()`.
42
- 2. Converts history to xAI `input[]` (system/user/assistant/tool).
43
- 3. POST to `https://api.x.ai/v1/responses`.
44
- 4. Parses `output` → adds text/reasoning/tools to `Prompt`.
45
- 5. If tools needed, `ToolSet.execute()` → recurse until complete.
46
-
47
- ## Options (XAIOptions)
48
- | Property | Type | Default | Description |
49
- |----------|------|---------|-------------|
50
- | `model` | string | `'grok-4-fast-non-reasoning'` | e.g., `'grok-4-fast-reasoning'` |
51
- | `input` | `XAIInput[]` | `[{role: 'system', content: 'Be precise'}]` | Messages/history |
52
- | `reasoning.effort` | `'low'\|'medium'\|'high'` | `'medium'` | Reasoning depth |
53
- | `reasoning.summary` | `'auto'\|'concise'\|'detailed'` | `'auto'` | Reasoning output style |
54
- | `temperature` | number | `1` (0-2) | Sampling |
55
- | `parallel_tool_calls` | boolean | `true` | Parallel functions |
56
- | `tool_choice` | `'auto'` | `'auto'` | Tool selection |
57
- | `tools` | `XAIFunctionTool[]` | `[]` | From `ToolSet` |
58
- | `store` | boolean | `false` | Persist response (still bills tokens) |
59
- | `max_output_tokens` | number | `4000` | Limit |
60
- | `search_parameters` | object | - | `{max_search_results: 4, mode: 'auto', return_citations: true}` |
61
-
62
- **Tool Types**:
63
- - `function`: From `ToolSet` (name, description, parameters JSONSchema).
64
- - Native: `web_search`, `x_search` (filters: dates, domains, etc.).
65
-
66
- ## Example Request (Generated Internally)
67
- ```json
68
- {
69
- "model": "grok-4-fast-reasoning",
70
- "input": [
71
- {"role": "system", "content": "You are a precise weather expert."},
72
- {"role": "user", "content": "Weather in Amsterdam today?"}
73
- ],
74
- "parallel_tool_calls": true,
75
- "reasoning": {"effort": "high"},
76
- "search_parameters": {"mode": "auto", "return_citations": true},
77
- "tools": [{"type": "function", "name": "web_search", ...}]
78
- }
79
- ```
80
-
81
- ## Example Response (Parsed to Prompt)
82
- - **Text + Citations**: Added as `assistant` text + `log` annotations (URLs).
83
- - **Function Calls**: `assistant` with `function_request` → `ToolSet.execute()`.
84
- - **Reasoning**: Prepended as `reasoning` multimodal text.
85
-
86
- Sample parsed:
87
- ```
88
- Today is [date]. Weather: Cloudy, 5°C... [citations]
89
- ```
90
- Tokens: `input_tokens`, `output_tokens` (incl. `reasoning_tokens`) logged in `Prompt.records`.
91
-
92
- ## Advanced: Custom Tools
93
- Extend `ToolSet` before `setup()`:
94
- ```javascript
95
- import { ToolSet } from '@j-o-r/hello-dave';
96
-
97
- const ts = new ToolSet('required');
98
- ts.add('get_weather', 'Get weather for a location', {
99
- type: 'object',
100
- properties: { location: {type: 'string'} },
101
- required: ['location']
102
- }, async (params) => `Weather: ${params.location} - 20°C`); // Handler
103
- agent.setup({ ..., toolsetMode: ts });
104
- ```
105
-
106
- ## Errors & Limits
107
- - `Max recursive calls`: `GLOBAL.max_recursive_requests`.
108
- - Missing `XAIKEY`: Throws.
109
- - Invalid last message: Must end in `user`/`tool`.
110
-
111
- See `lib/API/x.ai/responses.js` source for full JSDoc/types. Cross-links: [Prompt](../prompt-class.md), [ToolSet](../toolset.md), [AgentManager](agent-manager.md).
@@ -1,107 +0,0 @@
1
- # xAI Responses API Integration (`lib/API/x.ai/responses.js`)
2
-
3
- ## Overview
4
- This module provides a seamless wrapper for the [xAI Responses API](https://docs.x.ai/docs/api-reference#create-new-response) (formerly Grok API), adapted for the hello-dave framework. It integrates directly with `Prompt.js` and `ToolSet.js`, enabling tool-using agents via `AgentManager`.
5
-
6
- Key adaptations:
7
- - **Unified Interface**: Uses `Prompt` messages/history for input; parses `output` into assistant/tool responses.
8
- - **Recursive Tool Calls**: Automatically handles `function_call` → execute tools → `function_call_output` loops (up to `GLOBAL.max_recursive_requests`).
9
- - **Tool Support**: Converts `ToolSet` to xAI `function` tools; supports native xAI tools like `web_search`, `x_search`.
10
- - **Reasoning & Search**: Configurable `reasoning.effort` (`low`/`medium`/`high`), `search_parameters`.
11
- - **Streaming**: Not yet implemented (future).
12
- - **Auth**: Requires `XAIKEY` env var.
13
-
14
- Default model: `grok-4-fast-reasoning`. Supports: `grok-4-fast-reasoning`, `grok-4-fast-non-reasoning`, etc.
15
-
16
- ## Usage in AgentManager
17
- ```javascript
18
- import AgentManager from '../lib/AgentManager.js';
19
-
20
- const agent = new AgentManager({ name: 'weather-agent', secret: 'optional-ws-secret' });
21
- agent.setup({
22
- prompt: 'You are a precise weather expert. Use tools for real-time data.',
23
- api: 'xai',
24
- options: { model: 'grok-4-fast-reasoning', reasoning: { effort: 'high' } },
25
- toolsetMode: 'auto', // Adds generic tools like web_search
26
- contextWindow: 128000
27
- });
28
- agent.addGenericToolcall('web_search'); // Optional: Add extras
29
-
30
- // CLI mode
31
- agent.start(); // Interactive chat
32
-
33
- // Or direct call
34
- const response = await agent.directCall('Weather in Amsterdam today?');
35
- console.log(response); // Handles search/tools automatically
36
- ```
37
-
38
- Under the hood:
39
- 1. `Prompt.setAdaptor(API.text['xai'], toolset, options)` → uses `responses.request()`.
40
- 2. Converts history to xAI `input[]` (system/user/assistant/tool).
41
- 3. POST to `https://api.x.ai/v1/responses`.
42
- 4. Parses `output` → adds text/reasoning/tools to `Prompt`.
43
- 5. If tools needed, `ToolSet.execute()` → recurse until complete.
44
-
45
- ## Options (XAIOptions)
46
- | Property | Type | Default | Description |
47
- |----------|------|---------|-------------|
48
- | `model` | string | `'grok-4-fast-non-reasoning'` | e.g., `'grok-4-fast-reasoning'` |
49
- | `input` | `XAIInput[]` | `[{role: 'system', content: 'Be precise'}]` | Messages/history |
50
- | `reasoning.effort` | `'low'\|'medium'\|'high'` | `'medium'` | Reasoning depth |
51
- | `reasoning.summary` | `'auto'\|'concise'\|'detailed'` | `'auto'` | Reasoning output style |
52
- | `temperature` | number | `1` (0-2) | Sampling |
53
- | `parallel_tool_calls` | boolean | `true` | Parallel functions |
54
- | `tool_choice` | `'auto'` | `'auto'` | Tool selection |
55
- | `tools` | `XAIFunctionTool[]` | `[]` | From `ToolSet` |
56
- | `store` | boolean | `false` | Persist response (still bills tokens) |
57
- | `max_output_tokens` | number | `4000` | Limit |
58
- | `search_parameters` | object | - | `{max_search_results: 4, mode: 'auto', return_citations: true}` |
59
-
60
- **Tool Types**:
61
- - `function`: From `ToolSet` (name, description, parameters JSONSchema).
62
- - Native: `web_search`, `x_search` (filters: dates, domains, etc.).
63
-
64
- ## Example Request (Generated Internally)
65
- ```json
66
- {
67
- \"model\": \"grok-4-fast-reasoning\",
68
- \"input\": [
69
- {\"role\": \"system\", \"content\": \"You are a precise weather expert.\"},
70
- {\"role\": \"user\", \"content\": \"Weather in Amsterdam today?\"}
71
- ],
72
- \"parallel_tool_calls\": true,
73
- \"reasoning\": {\"effort\": \"high\"},
74
- \"search_parameters\": {\"mode\": \"auto\", \"return_citations\": true},
75
- \"tools\": [{"type\": "function", "name": "web_search", ...}]
76
- }
77
- ```
78
-
79
- ## Example Response (Parsed to Prompt)
80
- - **Text + Citations**: Added as `assistant` text + `log` annotations (URLs).
81
- - **Function Calls**: `assistant` with `function_request` → `ToolSet.execute()`.
82
- - **Reasoning**: Prepended as `reasoning` multimodal text.
83
-
84
- Sample parsed:
85
- ```
86
- Today is [date]. Weather: Cloudy, 5°C... [citations]
87
- ```
88
- Tokens: `input_tokens`, `output_tokens` (incl. `reasoning_tokens`) logged in `Prompt.records`.
89
-
90
- ## Advanced: Custom Tools
91
- Extend `ToolSet` before `setup()`:
92
- ```javascript
93
- const ts = new ToolSet('required');
94
- ts.add('get_weather', 'Get weather for a location', {
95
- type: 'object',
96
- properties: { location: {type: 'string'} },
97
- required: ['location']
98
- }, async (params) => `Weather: ${params.location} - 20°C`); // Handler
99
- agent.setup({ ..., toolsetMode: ts });
100
- ```
101
-
102
- ## Errors & Limits
103
- - `Max recursive calls`: `GLOBAL.max_recursive_requests`.
104
- - Missing `XAIKEY`: Throws.
105
- - Invalid last message: Must end in `user`/`tool`.
106
-
107
- See `lib/API/x.ai/responses.js` source for full JSDoc/types. Cross-links: [Prompt](../prompt-class.md), [ToolSet](../toolset.md), [AgentManager](agent-manager.md) (TBD)."
@@ -1,107 +0,0 @@
1
- # xAI Responses API Integration (`lib/API/x.ai/responses.js`)
2
-
3
- ## Overview
4
- This module provides a seamless wrapper for the [xAI Responses API](https://docs.x.ai/docs/api-reference#create-new-response) (formerly Grok API), adapted for the hello-dave framework. It integrates directly with `Prompt.js` and `ToolSet.js`, enabling tool-using agents via `AgentManager`.
5
-
6
- Key adaptations:
7
- - **Unified Interface**: Uses `Prompt` messages/history for input; parses `output` into assistant/tool responses.
8
- - **Recursive Tool Calls**: Automatically handles `function_call` → execute tools → `function_call_output` loops (up to `GLOBAL.max_recursive_requests`).
9
- - **Tool Support**: Converts `ToolSet` to xAI `function` tools; supports native xAI tools like `web_search`, `x_search`.
10
- - **Reasoning & Search**: Configurable `reasoning.effort` (`low`/`medium`/`high`), `search_parameters`.
11
- - **Streaming**: Not yet implemented (future).
12
- - **Auth**: Requires `XAIKEY` env var.
13
-
14
- Default model: `grok-4-fast-reasoning`. Supports: `grok-4-fast-reasoning`, `grok-4-fast-non-reasoning`, etc.
15
-
16
- ## Usage in AgentManager
17
- ```javascript
18
- import AgentManager from '../lib/AgentManager.js';
19
-
20
- const agent = new AgentManager({ name: 'weatheragent', secret: 'optional-ws-secret' });
21
- agent.setup({
22
- prompt: 'You are a precise weather expert. Use tools for real-time data.',
23
- api: 'xai',
24
- options: { model: 'grok-4-fast-reasoning', reasoning: { effort: 'high' } },
25
- toolsetMode: 'auto', // Adds generic tools like web_search
26
- contextWindow: 128000
27
- });
28
- agent.addGenericToolcall('web_search'); // Optional: Add extras
29
-
30
- // CLI mode
31
- agent.start(); // Interactive chat
32
-
33
- // Or direct call
34
- const response = await agent.directCall('Weather in Amsterdam today?');
35
- console.log(response); // Handles search/tools automatically
36
- ```
37
-
38
- Under the hood:
39
- 1. `Prompt.setAdaptor(API.text['xai'], toolset, options)` → uses `responses.request()`.
40
- 2. Converts history to xAI `input[]` (system/user/assistant/tool).
41
- 3. POST to `https://api.x.ai/v1/responses`.
42
- 4. Parses `output` → adds text/reasoning/tools to `Prompt`.
43
- 5. If tools needed, `ToolSet.execute()` → recurse until complete.
44
-
45
- ## Options (XAIOptions)
46
- | Property | Type | Default | Description |
47
- |----------|------|---------|-------------|
48
- | `model` | string | `'grok-4-fast-non-reasoning'` | e.g., `'grok-4-fast-reasoning'` |
49
- | `input` | `XAIInput[]` | `[{role: 'system', content: 'Be precise'}]` | Messages/history |
50
- | `reasoning.effort` | `'low'\|'medium'\|'high'` | `'medium'` | Reasoning depth |
51
- | `reasoning.summary` | `'auto'\|'concise'\|'detailed'` | `'auto'` | Reasoning output style |
52
- | `temperature` | number | `1` (0-2) | Sampling |
53
- | `parallel_tool_calls` | boolean | `true` | Parallel functions |
54
- | `tool_choice` | `'auto'` | `'auto'` | Tool selection |
55
- | `tools` | `XAIFunctionTool[]` | `[]` | From `ToolSet` |
56
- | `store` | boolean | `false` | Persist response (still bills tokens) |
57
- | `max_output_tokens` | number | `4000` | Limit |
58
- | `search_parameters` | object | - | `{max_search_results: 4, mode: 'auto', return_citations: true}` |
59
-
60
- **Tool Types**:
61
- - `function`: From `ToolSet` (name, description, parameters JSONSchema).
62
- - Native: `web_search`, `x_search` (filters: dates, domains, etc.).
63
-
64
- ## Example Request (Generated Internally)
65
- ```json
66
- {
67
- "model": "grok-4-fast-reasoning",
68
- "input": [
69
- {"role": "system", "content": "You are a precise weather expert."},
70
- {"role": "user", "content": "Weather in Amsterdam today?"}
71
- ],
72
- "parallel_tool_calls": true,
73
- "reasoning": {"effort": "high"},
74
- "search_parameters": {"mode": "auto", "return_citations": true},
75
- "tools": [{"type": "function", "name": "web_search", ...}]
76
- }
77
- ```
78
-
79
- ## Example Response (Parsed to Prompt)
80
- - **Text + Citations**: Added as `assistant` text + `log` annotations (URLs).
81
- - **Function Calls**: `assistant` with `function_request` → `ToolSet.execute()`.
82
- - **Reasoning**: Prepended as `reasoning` multimodal text.
83
-
84
- Sample parsed:
85
- ```
86
- Today is [date]. Weather: Cloudy, 5°C... [citations]
87
- ```
88
- Tokens: `input_tokens`, `output_tokens` (incl. `reasoning_tokens`) logged in `Prompt.records`.
89
-
90
- ## Advanced: Custom Tools
91
- Extend `ToolSet` before `setup()`:
92
- ```javascript
93
- const ts = new ToolSet('required');
94
- ts.add('get_weather', 'Get weather for a location', {
95
- type: 'object',
96
- properties: { location: {type: 'string'} },
97
- required: ['location']
98
- }, async (params) => `Weather: ${params.location} - 20°C`); // Handler
99
- agent.setup({ ..., toolsetMode: ts });
100
- ```
101
-
102
- ## Errors & Limits
103
- - `Max recursive calls`: `GLOBAL.max_recursive_requests`.
104
- - Missing `XAIKEY`: Throws.
105
- - Invalid last message: Must end in `user`/`tool`.
106
-
107
- See `lib/API/x.ai/responses.js` source for full JSDoc/types. Cross-links: [Prompt](../prompt-class.md), [ToolSet](../toolset.md), [AgentManager](agent-manager.md) (TBD).
@@ -1,106 +0,0 @@
1
- [x.ai collections](https://docs.x.ai/docs/guides/using-collections/api)
2
-
3
-
4
- Creating a collection:
5
-
6
- ```bash
7
- curl https://management-api.x.ai/v1/collections \
8
- -X POST \
9
- -H "Content-Type: application/json" \
10
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY" \
11
- -d '{"collection_name": "SEC Filings"}'
12
- ```
13
-
14
- Listing collections:
15
- ```bash
16
- curl https://management-api.x.ai/v1/collections \
17
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"
18
- ```
19
-
20
- Viewing collection configuration:
21
- ```bash
22
- 'curl https://management-api.x.ai/v1/collections/collection_dbc087b1-6c99-493d-86c6-b401fee34a9d \
23
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"
24
- ```
25
-
26
- Updating collection configuration
27
- ```bash
28
- curl https://management-api.x.ai/v1/collections/collection_dbc087b1-6c99-493d-86c6-b401fee34a9d \
29
- -X PUT \
30
- -H "Content-Type: application/json" \
31
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY" \
32
- -d '{"collection_name": "SEC Filings (New)"}'
33
- ```
34
-
35
- Uploading documents:
36
-
37
- ```bash
38
- # Step 1: Upload file
39
- curl https://api.x.ai/v1/files \
40
- -H "Authorization: Bearer $XAI_API_KEY" \
41
- -F file=@tesla-20241231.html
42
-
43
- # Step 2: Add file to collection (use file_id from step 1)
44
- curl -X POST https://management-api.x.ai/v1/collections/$COLLECTION_ID/documents/$FILE_ID \
45
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"
46
-
47
- ```
48
-
49
- Uploading with metadata fields
50
-
51
- ```bash
52
- curl https://management-api.x.ai/v1/collections/collection_dbc087b1-6c99-493d-86c6-b401fee34a9d/documents \
53
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY" \
54
- -F "name=paper.pdf" \
55
- -F "data=@paper.pdf" \
56
- -F "content_type=application/pdf" \
57
- -F 'fields={"author": "Sandra Kim", "year": "2024", "title": "Q3 Revenue Analysis"}'
58
-
59
- ```
60
-
61
- Searching documents
62
-
63
- ```bash
64
- curl https://api.x.ai/v1/documents/search \
65
- -H "Content-Type: application/json" \
66
- -H "Authorization: Bearer $XAI_API_KEY" \
67
- -d '{
68
- "query": "What were the key revenue drivers based on the SEC filings?",
69
- "source": {
70
- "collection_ids": ["collection_dbc087b1-6c99-493d-86c6-b401fee34a9d"]
71
- }
72
- }'
73
- ```
74
-
75
- ```bash
76
- curl https://api.x.ai/v1/documents/search \
77
- -H "Content-Type: application/json" \
78
- -H "Authorization: Bearer $XAI_API_KEY" \
79
- -d '{
80
- "query": "What were the key revenue drivers based on the SEC filings?",
81
- "source": {
82
- "collection_ids": [
83
- "collection_dbc087b1-6c99-493d-86c6-b401fee34a9d"
84
- ]
85
- },
86
- "retrieval_mode": {"type": "hybrid"}
87
- }'
88
- ```
89
-
90
-
91
- Deleting a document:
92
-
93
- ```bash
94
- curl https://management-api.x.ai/v1/collections/collection_dbc087b1-6c99-493d-86c6-b401fee34a9d/documents/file_55a709d4-8edc-4f83-84d9-9f04fe49f832 \
95
- -X DELETE \
96
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"
97
-
98
- ```
99
-
100
- Deleting a collection
101
-
102
- ```bash
103
- curl https://management-api.x.ai/v1/collections/collection_dbc087b1-6c99-493d-86c6-b401fee34a9d \
104
- -X DELETE \
105
- -H "Authorization: Bearer $XAI_MANAGEMENT_API_KEY"
106
- ```