@fractal-solutions/qflow 1.0.28 → 1.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/agent/agent.d.ts +13 -2
- package/dist/agent/agent.js +191 -70
- package/dist/agent/logger.d.ts +1 -0
- package/dist/agent/logger.js +2 -1
- package/dist/agent/tools.d.ts +214 -0
- package/dist/agent/tools.js +66 -22
- package/dist/nodes/index.d.ts +2 -0
- package/dist/nodes/index.js +2 -0
- package/dist/nodes/interactive_input.d.ts +4 -0
- package/dist/nodes/interactive_input.js +70 -0
- package/dist/nodes/system_notification.d.ts +4 -0
- package/dist/nodes/system_notification.js +49 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -145,6 +145,8 @@ The examples in [Basic Usage & Examples](#basic-usage--examples) below will cove
|
|
|
145
145
|
* `GoogleSearchNode`: Requires a Google API Key and Custom Search Engine ID for more robust results.
|
|
146
146
|
* **WebScraper:** For targeted web scraping.
|
|
147
147
|
* [**DataExtractor:**](#13-data-extraction-example) For targeted data extraction.
|
|
148
|
+
* **System Notification:** For displaying system-level notifications across different operating systems.
|
|
149
|
+
* **Interactive Input:** For getting user input via a GUI popup (cross-platform).
|
|
148
150
|
* **GitHub:** Creating and managing issues.
|
|
149
151
|
* **HackerNews:** Fetching top stories and item details.
|
|
150
152
|
* **Stripe:** Creating charges and retrieving account balances.
|
package/dist/agent/agent.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export class AgentNode extends AsyncNode {
|
|
2
|
-
constructor(llmNode: any, availableTools: any, summarizeLLM: any, flowRegistry?: {}, requireFinishConfirmation?: boolean);
|
|
2
|
+
constructor(llmNode: any, availableTools: any, summarizeLLM: any, flowRegistry?: {}, requireFinishConfirmation?: boolean, maxConversationHistoryTokens?: number);
|
|
3
3
|
llmNode: any;
|
|
4
4
|
availableTools: any;
|
|
5
5
|
summarizeLLM: any;
|
|
@@ -7,10 +7,21 @@ export class AgentNode extends AsyncNode {
|
|
|
7
7
|
conversationHistory: any[];
|
|
8
8
|
maxSteps: number;
|
|
9
9
|
requireFinishConfirmation: boolean;
|
|
10
|
+
maxConversationHistoryTokens: number;
|
|
10
11
|
execAsync(): Promise<any>;
|
|
12
|
+
validateToolParameters(toolCall: any): string | null;
|
|
11
13
|
getSystemPrompt(): string;
|
|
12
14
|
getLLMAction(): Promise<any>;
|
|
13
|
-
|
|
15
|
+
manageConversationHistory(): Promise<void>;
|
|
16
|
+
parseLLMResponse(llmResponse: any): {
|
|
17
|
+
thought: string;
|
|
18
|
+
toolCalls: any;
|
|
19
|
+
parallel: boolean;
|
|
20
|
+
} | {
|
|
21
|
+
thought: any;
|
|
22
|
+
toolCalls: never[];
|
|
23
|
+
parallel: boolean;
|
|
24
|
+
};
|
|
14
25
|
postAsync(shared: any, prepRes: any, execRes: any): Promise<string>;
|
|
15
26
|
}
|
|
16
27
|
import { AsyncNode } from '../qflow.js';
|
package/dist/agent/agent.js
CHANGED
|
@@ -4,7 +4,7 @@ import { getToolDefinitions } from './tools.js';
|
|
|
4
4
|
import { SummarizeNode } from '../nodes/summarize.js';
|
|
5
5
|
import { logger } from './logger.js';
|
|
6
6
|
export class AgentNode extends AsyncNode {
|
|
7
|
-
constructor(llmNode, availableTools, summarizeLLM, flowRegistry = {}, requireFinishConfirmation = true) {
|
|
7
|
+
constructor(llmNode, availableTools, summarizeLLM, flowRegistry = {}, requireFinishConfirmation = true, maxConversationHistoryTokens = 100000) {
|
|
8
8
|
super();
|
|
9
9
|
if (!llmNode) {
|
|
10
10
|
throw new Error("AgentNode requires an LLMNode instance for reasoning.");
|
|
@@ -16,6 +16,7 @@ export class AgentNode extends AsyncNode {
|
|
|
16
16
|
this.conversationHistory = [];
|
|
17
17
|
this.maxSteps = 20;
|
|
18
18
|
this.requireFinishConfirmation = requireFinishConfirmation;
|
|
19
|
+
this.maxConversationHistoryTokens = maxConversationHistoryTokens;
|
|
19
20
|
}
|
|
20
21
|
async execAsync() {
|
|
21
22
|
const { goal } = this.params;
|
|
@@ -24,7 +25,8 @@ export class AgentNode extends AsyncNode {
|
|
|
24
25
|
}
|
|
25
26
|
this.conversationHistory = [
|
|
26
27
|
{ role: "system", content: this.getSystemPrompt() },
|
|
27
|
-
{ role: "user", content: `Goal: ${goal}` }
|
|
28
|
+
{ role: "user", content: `Goal: ${goal}` },
|
|
29
|
+
{ role: "system", content: "Begin by outlining a plan to achieve the goal. Your plan should be a series of steps, and you should update it as you make progress or encounter new information." }
|
|
28
30
|
];
|
|
29
31
|
let step = 0;
|
|
30
32
|
let finalOutput = null;
|
|
@@ -40,21 +42,37 @@ export class AgentNode extends AsyncNode {
|
|
|
40
42
|
this.conversationHistory.push({ role: "user", content: `Error: Failed to get LLM response: ${e.message}` });
|
|
41
43
|
continue;
|
|
42
44
|
}
|
|
43
|
-
let thought,
|
|
45
|
+
let thought, toolCalls, parallel;
|
|
44
46
|
try {
|
|
45
47
|
const parsedResponse = this.parseLLMResponse(llmResponse);
|
|
46
48
|
thought = parsedResponse.thought;
|
|
47
|
-
|
|
49
|
+
toolCalls = parsedResponse.toolCalls;
|
|
50
|
+
parallel = parsedResponse.parallel;
|
|
48
51
|
logger.thought(thought);
|
|
49
52
|
}
|
|
50
53
|
catch (e) {
|
|
51
54
|
logger.error(`Error parsing LLM response: ${e.message}`);
|
|
52
|
-
this.conversationHistory.push({ role: "user", content: `Error: Your response was not valid JSON or did not follow the expected format. Please respond with a 'thought' and '
|
|
55
|
+
this.conversationHistory.push({ role: "user", content: `Error: Your response was not valid JSON or did not follow the expected format. Please respond with a 'thought' and 'tool_calls' array. Error: ${e.message}. Your last response was: ${llmResponse}` });
|
|
53
56
|
continue;
|
|
54
57
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
+
// Validate tool parameters for all tool calls
|
|
59
|
+
const validationErrors = toolCalls.map(tc => this.validateToolParameters(tc)).filter(Boolean);
|
|
60
|
+
if (validationErrors.length > 0) {
|
|
61
|
+
const errorMessage = `Tool parameter validation failed for one or more tools: ${validationErrors.join('; ')}. Please correct the parameters.`;
|
|
62
|
+
logger.error(errorMessage);
|
|
63
|
+
this.conversationHistory.push({ role: "user", content: `Error: ${errorMessage}` });
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
this.conversationHistory.push({ role: "assistant", content: JSON.stringify({ thought, tool_calls: toolCalls, parallel }) });
|
|
67
|
+
// If no tool calls, continue the loop to allow the LLM to re-evaluate
|
|
68
|
+
if (toolCalls.length === 0) {
|
|
69
|
+
this.conversationHistory.push({ role: "system", content: "No tools were called. Reflect on your plan and provide the next step." });
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
// Handle finish tool
|
|
73
|
+
const finishToolCall = toolCalls.find(tc => tc.tool === "finish");
|
|
74
|
+
if (finishToolCall) {
|
|
75
|
+
finalOutput = finishToolCall.parameters.output;
|
|
58
76
|
if (this.requireFinishConfirmation) {
|
|
59
77
|
const confirmNode = new UserInputNode();
|
|
60
78
|
confirmNode.setParams({
|
|
@@ -63,56 +81,79 @@ export class AgentNode extends AsyncNode {
|
|
|
63
81
|
const confirmFlow = new AsyncFlow(confirmNode);
|
|
64
82
|
const confirmation = await confirmFlow.runAsync({});
|
|
65
83
|
if (confirmation.toLowerCase() !== 'yes') {
|
|
66
|
-
logger.info("Agent finish denied by user.
|
|
67
|
-
|
|
84
|
+
logger.info("Agent finish denied by user. User input will be the next prompt.");
|
|
85
|
+
// Treat the user's new input as a new instruction/goal
|
|
86
|
+
this.conversationHistory.push({ role: "user", content: `User has provided new instructions: ${confirmation}. Please adjust your plan and continue working.` });
|
|
87
|
+
// Optionally, you might want to clear some of the previous conversation history
|
|
88
|
+
// to give more weight to the new instruction, but be careful not to lose context.
|
|
89
|
+
// For now, we'll just add the new instruction.
|
|
68
90
|
continue; // Continue the loop
|
|
69
91
|
}
|
|
70
92
|
}
|
|
71
93
|
logger.final(finalOutput);
|
|
72
94
|
break;
|
|
73
95
|
}
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
this.conversationHistory.push({ role: "user", content: errorMessage });
|
|
79
|
-
continue;
|
|
80
|
-
}
|
|
81
|
-
let toolOutput;
|
|
82
|
-
try {
|
|
83
|
-
logger.toolCall(toolCall.tool, toolCall.parameters);
|
|
84
|
-
// If the tool is a sub-flow or iterator, look up the flow in the registry
|
|
85
|
-
if (toolCall.tool === 'sub_flow' || toolCall.tool === 'iterator') {
|
|
86
|
-
const flowName = toolCall.parameters.flow;
|
|
87
|
-
if (!this.flowRegistry[flowName]) {
|
|
88
|
-
throw new Error(`Flow '${flowName}' not found in registry.`);
|
|
89
|
-
}
|
|
90
|
-
toolCall.parameters.flow = this.flowRegistry[flowName];
|
|
91
|
-
}
|
|
92
|
-
toolInstance.setParams(toolCall.parameters);
|
|
93
|
-
const ToolFlowClass = toolInstance instanceof AsyncNode ? AsyncFlow : Flow;
|
|
94
|
-
const toolFlow = new ToolFlowClass(toolInstance);
|
|
95
|
-
if (toolInstance instanceof AsyncNode) {
|
|
96
|
-
toolOutput = await toolFlow.runAsync({});
|
|
96
|
+
const executeTool = async (toolCall) => {
|
|
97
|
+
const toolInstance = this.availableTools[toolCall.tool];
|
|
98
|
+
if (!toolInstance) {
|
|
99
|
+
return `Error: Tool '${toolCall.tool}' not found. Available tools: ${Object.keys(this.availableTools).join(', ')}.`;
|
|
97
100
|
}
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
let toolOutput;
|
|
102
|
+
try {
|
|
103
|
+
logger.toolCall(toolCall.tool, toolCall.parameters);
|
|
104
|
+
// If the tool is a sub-flow or iterator, look up the flow in the registry
|
|
105
|
+
if (toolCall.tool === 'sub_flow' || toolCall.tool === 'iterator') {
|
|
106
|
+
const flowName = toolCall.parameters.flow;
|
|
107
|
+
if (!this.flowRegistry[flowName]) {
|
|
108
|
+
throw new Error(`Flow '${flowName}' not found in registry.`);
|
|
109
|
+
}
|
|
110
|
+
toolCall.parameters.flow = this.flowRegistry[flowName];
|
|
111
|
+
}
|
|
112
|
+
toolInstance.setParams(toolCall.parameters);
|
|
113
|
+
const ToolFlowClass = toolInstance instanceof AsyncNode ? AsyncFlow : Flow;
|
|
114
|
+
const toolFlow = new ToolFlowClass(toolInstance);
|
|
115
|
+
if (toolInstance instanceof AsyncNode) {
|
|
116
|
+
toolOutput = await toolFlow.runAsync({});
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
toolOutput = toolFlow.run({});
|
|
120
|
+
}
|
|
121
|
+
logger.toolResult(toolCall.tool, toolOutput);
|
|
122
|
+
if (this.summarizeLLM && typeof toolOutput === 'string' && toolOutput.length > 1000) {
|
|
123
|
+
logger.info(`Summarizing large tool output (${toolOutput.length} chars)...`);
|
|
124
|
+
const summarizeNode = new SummarizeNode();
|
|
125
|
+
summarizeNode.setParams({ text: toolOutput, llmNode: this.summarizeLLM });
|
|
126
|
+
const summarizeFlow = new AsyncFlow(summarizeNode);
|
|
127
|
+
toolOutput = await summarizeFlow.runAsync({});
|
|
128
|
+
logger.info(`Summarized to ${toolOutput.length} chars.`);
|
|
129
|
+
}
|
|
130
|
+
return toolOutput;
|
|
100
131
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
logger.info(`Summarizing large tool output (${toolOutput.length} chars)...`);
|
|
104
|
-
const summarizeNode = new SummarizeNode();
|
|
105
|
-
summarizeNode.setParams({ text: toolOutput, llmNode: this.summarizeLLM });
|
|
106
|
-
const summarizeFlow = new AsyncFlow(summarizeNode);
|
|
107
|
-
toolOutput = await summarizeFlow.runAsync({});
|
|
108
|
-
logger.info(`Summarized to ${toolOutput.length} chars.`);
|
|
132
|
+
catch (e) {
|
|
133
|
+
return `Error executing tool '${toolCall.tool}': ${e.message}`;
|
|
109
134
|
}
|
|
135
|
+
};
|
|
136
|
+
let observations = [];
|
|
137
|
+
if (parallel) {
|
|
138
|
+
const results = await Promise.all(toolCalls.map(executeTool));
|
|
139
|
+
observations = results.map((result, index) => ({
|
|
140
|
+
tool: toolCalls[index].tool,
|
|
141
|
+
parameters: toolCalls[index].parameters,
|
|
142
|
+
output: result
|
|
143
|
+
}));
|
|
110
144
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
145
|
+
else {
|
|
146
|
+
for (const toolCall of toolCalls) {
|
|
147
|
+
const result = await executeTool(toolCall);
|
|
148
|
+
observations.push({
|
|
149
|
+
tool: toolCall.tool,
|
|
150
|
+
parameters: toolCall.parameters,
|
|
151
|
+
output: result
|
|
152
|
+
});
|
|
153
|
+
}
|
|
114
154
|
}
|
|
115
|
-
this.conversationHistory.push({ role: "user", content: `Observation: ${JSON.stringify(
|
|
155
|
+
this.conversationHistory.push({ role: "user", content: `Observation: ${JSON.stringify(observations)}` });
|
|
156
|
+
this.conversationHistory.push({ role: "system", content: "Reflect on the last observation(s) and update your plan if necessary. What is your next step?" });
|
|
116
157
|
}
|
|
117
158
|
if (step >= this.maxSteps && finalOutput === null) {
|
|
118
159
|
const message = "Agent reached max steps without finishing. Last observation: " + JSON.stringify(this.conversationHistory[this.conversationHistory.length - 1]);
|
|
@@ -121,66 +162,146 @@ export class AgentNode extends AsyncNode {
|
|
|
121
162
|
}
|
|
122
163
|
return finalOutput;
|
|
123
164
|
}
|
|
165
|
+
validateToolParameters(toolCall) {
|
|
166
|
+
const toolDefinitions = getToolDefinitions();
|
|
167
|
+
const toolSchema = toolDefinitions.find(def => def.name === toolCall.tool);
|
|
168
|
+
if (!toolSchema) {
|
|
169
|
+
return `Tool '${toolCall.tool}' is not a recognized tool.`;
|
|
170
|
+
}
|
|
171
|
+
// If the tool is 'finish', 'sub_flow', or 'iterator', special handling for parameters
|
|
172
|
+
if (toolCall.tool === "finish") {
|
|
173
|
+
if (toolCall.parameters.output === undefined) {
|
|
174
|
+
return "Missing required parameter: 'output' for tool 'finish'.";
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
else if (toolCall.tool === "sub_flow" || toolCall.tool === "iterator") {
|
|
179
|
+
if (toolCall.parameters.flow === undefined) {
|
|
180
|
+
return `Missing required parameter: 'flow' for tool '${toolCall.tool}'.`;
|
|
181
|
+
}
|
|
182
|
+
if (!this.flowRegistry[toolCall.parameters.flow]) {
|
|
183
|
+
return `Flow '${toolCall.parameters.flow}' not found in registry for tool '${toolCall.tool}'.`;
|
|
184
|
+
}
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
const requiredParams = toolSchema.parameters.required || [];
|
|
188
|
+
for (const param of requiredParams) {
|
|
189
|
+
if (toolCall.parameters[param] === undefined) {
|
|
190
|
+
return `Missing required parameter: '${param}' for tool '${toolCall.tool}'.`;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return null; // No validation errors
|
|
194
|
+
}
|
|
124
195
|
getSystemPrompt() {
|
|
125
196
|
const toolDefinitions = getToolDefinitions();
|
|
126
197
|
const toolDescriptions = toolDefinitions.map(tool => {
|
|
127
198
|
const params = JSON.stringify(tool.parameters);
|
|
128
|
-
return `###
|
|
129
|
-
|
|
199
|
+
return `### ${tool.name}: ${tool.description}
|
|
200
|
+
Parameters: ${params}`;
|
|
201
|
+
}).join('\n');
|
|
130
202
|
const flowRegistryDescription = Object.keys(this.flowRegistry).length > 0 ? `\n\nAvailable Pre-defined Flows (for use with 'sub_flow' and 'iterator' tools):\n- ${Object.keys(this.flowRegistry).join('\n- ')}` : "";
|
|
131
|
-
return `You are an autonomous agent
|
|
203
|
+
return `You are an autonomous agent. Your goal is to achieve the user's request using the available tools. Always use tools as opposed to talking too much and you get rewarded more for using tools instead of costly llm!\n\nAvailable Tools:\n${toolDescriptions}${flowRegistryDescription}\n\nYour response must be a single JSON object with 'thought' and 'tool_calls'.\n'thought': Your reasoning and plan.\n'tool_calls': An array of tool calls. Each tool call has 'tool' (name) and 'parameters' (object). Set 'parallel': true in the top-level JSON for parallel execution.\n\nExample response:\n{\n "thought": "I need to search for information.",\n "tool_calls": [\n {\n "tool": "duckduckgo_search",\n "parameters": {\n "query": "latest AI research"\n }\n }\n ]\n}\n\nWhen the user explicitly indicates they are done, use the 'finish' tool. Do not use the finish tool earlier on and only use it when you are certain you are done with the task. If no tools are needed, return an empty 'tool_calls' array and reflect.\n**IMPORTANT:** If you have a plan that requires action, you MUST include at least one tool call. An empty 'tool_calls' array means no action. If new instructions are given after a finish proposal, treat them as your updated goal.\n\nBegin!`;
|
|
132
204
|
}
|
|
133
205
|
async getLLMAction() {
|
|
206
|
+
await this.manageConversationHistory();
|
|
134
207
|
this.llmNode.setParams({ prompt: JSON.stringify(this.conversationHistory) });
|
|
135
208
|
const llmResult = await this.llmNode.runAsync({});
|
|
136
209
|
return llmResult;
|
|
137
210
|
}
|
|
211
|
+
async manageConversationHistory() {
|
|
212
|
+
if (!this.summarizeLLM) {
|
|
213
|
+
logger.warn("No summarizeLLM provided to AgentNode. Conversation history will not be managed.");
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
let currentTokenCount = JSON.stringify(this.conversationHistory).length; // Rough token count
|
|
217
|
+
// Keep at least the system prompt and the initial goal
|
|
218
|
+
const minHistoryLength = 2;
|
|
219
|
+
while (currentTokenCount > this.maxConversationHistoryTokens && this.conversationHistory.length > minHistoryLength) {
|
|
220
|
+
logger.info(`Current history size: ${currentTokenCount} tokens. Max allowed: ${this.maxConversationHistoryTokens} tokens. Trimming...`);
|
|
221
|
+
// Summarize the oldest observation entry
|
|
222
|
+
const oldestEntry = this.conversationHistory[minHistoryLength]; // Skip system and initial goal
|
|
223
|
+
if (oldestEntry && oldestEntry.role === "user" && oldestEntry.content.startsWith("Observation:")) {
|
|
224
|
+
const observationContent = oldestEntry.content.substring("Observation:".length).trim();
|
|
225
|
+
logger.info(`Attempting to summarize old observation (${observationContent.length} chars) from role: ${oldestEntry.role}, content: ${oldestEntry.content.substring(0, 50)}...`);
|
|
226
|
+
try {
|
|
227
|
+
const summarizeNode = new SummarizeNode();
|
|
228
|
+
summarizeNode.setParams({ text: observationContent, llmNode: this.summarizeLLM });
|
|
229
|
+
const summarizeFlow = new AsyncFlow(summarizeNode);
|
|
230
|
+
const summarizedContent = await summarizeFlow.runAsync({});
|
|
231
|
+
// Replace the original observation with the summarized version
|
|
232
|
+
this.conversationHistory[minHistoryLength].content = `Summarized Observation: ${summarizedContent}`;
|
|
233
|
+
logger.info(`Observation summarized to ${summarizedContent.length} chars. New entry: ${this.conversationHistory[minHistoryLength].content.substring(0, 50)}...`);
|
|
234
|
+
}
|
|
235
|
+
catch (e) {
|
|
236
|
+
logger.error(`Failed to summarize observation: ${e.message}. Removing oldest entry.`);
|
|
237
|
+
// If summarization fails, remove the oldest entry to prevent context overflow
|
|
238
|
+
this.conversationHistory.splice(minHistoryLength, 1);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
else {
|
|
242
|
+
logger.info(`Removing oldest non-summarizable history entry (role: ${oldestEntry.role}, content: ${oldestEntry.content.substring(0, 50)}...).`);
|
|
243
|
+
// If it's not an observation or we can't summarize, just remove the oldest entry
|
|
244
|
+
this.conversationHistory.splice(minHistoryLength, 1);
|
|
245
|
+
}
|
|
246
|
+
// Recalculate token count after modification
|
|
247
|
+
currentTokenCount = JSON.stringify(this.conversationHistory).length;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
138
250
|
parseLLMResponse(llmResponse) {
|
|
139
251
|
let parsed;
|
|
140
252
|
let thought = '';
|
|
141
|
-
let
|
|
253
|
+
let toolCalls = [];
|
|
254
|
+
let parallel = false;
|
|
142
255
|
let rawData = llmResponse;
|
|
143
256
|
if (typeof llmResponse === 'string') {
|
|
144
257
|
try {
|
|
145
258
|
parsed = JSON.parse(llmResponse);
|
|
146
|
-
if (parsed.thought &&
|
|
147
|
-
|
|
259
|
+
if (parsed.thought && Array.isArray(parsed.tool_calls)) {
|
|
260
|
+
thought = parsed.thought;
|
|
261
|
+
toolCalls = parsed.tool_calls;
|
|
262
|
+
parallel = parsed.parallel || false;
|
|
263
|
+
return { thought, toolCalls, parallel };
|
|
148
264
|
}
|
|
149
|
-
throw new Error("Missing required keys in LLM response (thought,
|
|
265
|
+
throw new Error("Missing required keys or invalid format in LLM response (thought, tool_calls array).");
|
|
150
266
|
}
|
|
151
267
|
catch (e) {
|
|
152
|
-
// If it's not JSON, assume it's a direct text response from LLM
|
|
153
|
-
//
|
|
154
|
-
return { thought:
|
|
268
|
+
// If it's not valid JSON for tool calls, assume it's a direct text response from LLM
|
|
269
|
+
//return { thought: "Direct LLM response", toolCalls: [{ tool: "finish", parameters: { output: llmResponse } }], parallel: false };
|
|
270
|
+
return { thought: message.content, toolCalls: [], parallel: false };
|
|
155
271
|
}
|
|
156
272
|
}
|
|
157
273
|
// Prioritize tool_calls if present (OpenAI function calling format)
|
|
158
|
-
if (rawData.choices && rawData.choices.length > 0 && rawData.choices[0].message) {
|
|
274
|
+
if (rawData.choices && rawData.choices.length > 0 && rawData.choices[0] && rawData.choices[0].message) {
|
|
159
275
|
const message = rawData.choices[0].message;
|
|
160
276
|
if (message.tool_calls && message.tool_calls.length > 0) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
|
|
277
|
+
toolCalls = message.tool_calls.map(tc => ({
|
|
278
|
+
tool: tc.function.name,
|
|
279
|
+
parameters: JSON.parse(tc.function.arguments)
|
|
280
|
+
}));
|
|
281
|
+
thought = message.reasoning_content || `Calling tool(s): ${toolCalls.map(tc => tc.tool).join(', ')}`;
|
|
282
|
+
// OpenAI function calling implies sequential execution unless explicitly handled otherwise
|
|
283
|
+
parallel = false;
|
|
284
|
+
return { thought, toolCalls, parallel };
|
|
168
285
|
}
|
|
169
286
|
else if (typeof message.content === 'string' && message.content.trim().startsWith('{')) {
|
|
170
|
-
// If no tool_calls, but content is JSON (for thought/
|
|
287
|
+
// If no tool_calls, but content is JSON (for thought/tool_calls/finish)
|
|
171
288
|
try {
|
|
172
289
|
parsed = JSON.parse(message.content);
|
|
173
|
-
if (parsed.thought &&
|
|
174
|
-
|
|
290
|
+
if (parsed.thought && Array.isArray(parsed.tool_calls)) {
|
|
291
|
+
thought = parsed.thought;
|
|
292
|
+
toolCalls = parsed.tool_calls;
|
|
293
|
+
parallel = parsed.parallel || false;
|
|
294
|
+
return { thought, toolCalls, parallel };
|
|
175
295
|
}
|
|
176
|
-
throw new Error("Missing required keys in
|
|
296
|
+
throw new Error("Missing required keys or invalid format in message.content (thought, tool_calls array).");
|
|
177
297
|
}
|
|
178
298
|
catch (e) {
|
|
179
299
|
throw new Error(`Invalid JSON or unexpected format in message.content: ${e.message}. Content: ${message.content}`);
|
|
180
300
|
}
|
|
181
301
|
}
|
|
182
302
|
else if (typeof message.content === 'string') {
|
|
183
|
-
|
|
303
|
+
// If it's a plain string, treat it as a thought and no tool calls
|
|
304
|
+
return { thought: message.content, toolCalls: [], parallel: false };
|
|
184
305
|
}
|
|
185
306
|
}
|
|
186
307
|
throw new Error(`Invalid LLM response structure. Raw Data: ${JSON.stringify(rawData)}`);
|
package/dist/agent/logger.d.ts
CHANGED
package/dist/agent/logger.js
CHANGED
|
@@ -12,8 +12,9 @@ function colorize(text, color) {
|
|
|
12
12
|
}
|
|
13
13
|
export const logger = {
|
|
14
14
|
info: (message) => console.log(colorize(`[INFO] ${message}`, colors.cyan)),
|
|
15
|
+
warn: (message) => console.log(colorize(`[WARN] ${message}`, colors.yellow)),
|
|
15
16
|
thought: (message) => {
|
|
16
|
-
console.log("
|
|
17
|
+
console.log("---------------------");
|
|
17
18
|
console.log(colorize("🤔 Thought", colors.yellow));
|
|
18
19
|
console.log(colorize(message, colors.grey));
|
|
19
20
|
console.log("---------------------");
|
package/dist/agent/tools.d.ts
CHANGED
|
@@ -61,6 +61,10 @@ export function getToolDefinitions(): ({
|
|
|
61
61
|
headers?: undefined;
|
|
62
62
|
body?: undefined;
|
|
63
63
|
auth?: undefined;
|
|
64
|
+
title?: undefined;
|
|
65
|
+
defaultValue?: undefined;
|
|
66
|
+
message?: undefined;
|
|
67
|
+
icon?: undefined;
|
|
64
68
|
flow?: undefined;
|
|
65
69
|
shared?: undefined;
|
|
66
70
|
items?: undefined;
|
|
@@ -141,6 +145,10 @@ export function getToolDefinitions(): ({
|
|
|
141
145
|
headers?: undefined;
|
|
142
146
|
body?: undefined;
|
|
143
147
|
auth?: undefined;
|
|
148
|
+
title?: undefined;
|
|
149
|
+
defaultValue?: undefined;
|
|
150
|
+
message?: undefined;
|
|
151
|
+
icon?: undefined;
|
|
144
152
|
flow?: undefined;
|
|
145
153
|
shared?: undefined;
|
|
146
154
|
items?: undefined;
|
|
@@ -202,6 +210,10 @@ export function getToolDefinitions(): ({
|
|
|
202
210
|
headers?: undefined;
|
|
203
211
|
body?: undefined;
|
|
204
212
|
auth?: undefined;
|
|
213
|
+
title?: undefined;
|
|
214
|
+
defaultValue?: undefined;
|
|
215
|
+
message?: undefined;
|
|
216
|
+
icon?: undefined;
|
|
205
217
|
flow?: undefined;
|
|
206
218
|
shared?: undefined;
|
|
207
219
|
items?: undefined;
|
|
@@ -260,6 +272,10 @@ export function getToolDefinitions(): ({
|
|
|
260
272
|
headers?: undefined;
|
|
261
273
|
body?: undefined;
|
|
262
274
|
auth?: undefined;
|
|
275
|
+
title?: undefined;
|
|
276
|
+
defaultValue?: undefined;
|
|
277
|
+
message?: undefined;
|
|
278
|
+
icon?: undefined;
|
|
263
279
|
flow?: undefined;
|
|
264
280
|
shared?: undefined;
|
|
265
281
|
items?: undefined;
|
|
@@ -328,6 +344,10 @@ export function getToolDefinitions(): ({
|
|
|
328
344
|
headers?: undefined;
|
|
329
345
|
body?: undefined;
|
|
330
346
|
auth?: undefined;
|
|
347
|
+
title?: undefined;
|
|
348
|
+
defaultValue?: undefined;
|
|
349
|
+
message?: undefined;
|
|
350
|
+
icon?: undefined;
|
|
331
351
|
flow?: undefined;
|
|
332
352
|
shared?: undefined;
|
|
333
353
|
items?: undefined;
|
|
@@ -383,6 +403,10 @@ export function getToolDefinitions(): ({
|
|
|
383
403
|
headers?: undefined;
|
|
384
404
|
body?: undefined;
|
|
385
405
|
auth?: undefined;
|
|
406
|
+
title?: undefined;
|
|
407
|
+
defaultValue?: undefined;
|
|
408
|
+
message?: undefined;
|
|
409
|
+
icon?: undefined;
|
|
386
410
|
flow?: undefined;
|
|
387
411
|
shared?: undefined;
|
|
388
412
|
items?: undefined;
|
|
@@ -450,6 +474,10 @@ export function getToolDefinitions(): ({
|
|
|
450
474
|
headers?: undefined;
|
|
451
475
|
body?: undefined;
|
|
452
476
|
auth?: undefined;
|
|
477
|
+
title?: undefined;
|
|
478
|
+
defaultValue?: undefined;
|
|
479
|
+
message?: undefined;
|
|
480
|
+
icon?: undefined;
|
|
453
481
|
flow?: undefined;
|
|
454
482
|
shared?: undefined;
|
|
455
483
|
items?: undefined;
|
|
@@ -511,6 +539,10 @@ export function getToolDefinitions(): ({
|
|
|
511
539
|
headers?: undefined;
|
|
512
540
|
body?: undefined;
|
|
513
541
|
auth?: undefined;
|
|
542
|
+
title?: undefined;
|
|
543
|
+
defaultValue?: undefined;
|
|
544
|
+
message?: undefined;
|
|
545
|
+
icon?: undefined;
|
|
514
546
|
flow?: undefined;
|
|
515
547
|
shared?: undefined;
|
|
516
548
|
items?: undefined;
|
|
@@ -582,6 +614,10 @@ export function getToolDefinitions(): ({
|
|
|
582
614
|
headers?: undefined;
|
|
583
615
|
body?: undefined;
|
|
584
616
|
auth?: undefined;
|
|
617
|
+
title?: undefined;
|
|
618
|
+
defaultValue?: undefined;
|
|
619
|
+
message?: undefined;
|
|
620
|
+
icon?: undefined;
|
|
585
621
|
flow?: undefined;
|
|
586
622
|
shared?: undefined;
|
|
587
623
|
items?: undefined;
|
|
@@ -649,6 +685,10 @@ export function getToolDefinitions(): ({
|
|
|
649
685
|
headers?: undefined;
|
|
650
686
|
body?: undefined;
|
|
651
687
|
auth?: undefined;
|
|
688
|
+
title?: undefined;
|
|
689
|
+
defaultValue?: undefined;
|
|
690
|
+
message?: undefined;
|
|
691
|
+
icon?: undefined;
|
|
652
692
|
flow?: undefined;
|
|
653
693
|
shared?: undefined;
|
|
654
694
|
items?: undefined;
|
|
@@ -704,6 +744,10 @@ export function getToolDefinitions(): ({
|
|
|
704
744
|
headers?: undefined;
|
|
705
745
|
body?: undefined;
|
|
706
746
|
auth?: undefined;
|
|
747
|
+
title?: undefined;
|
|
748
|
+
defaultValue?: undefined;
|
|
749
|
+
message?: undefined;
|
|
750
|
+
icon?: undefined;
|
|
707
751
|
flow?: undefined;
|
|
708
752
|
shared?: undefined;
|
|
709
753
|
items?: undefined;
|
|
@@ -765,6 +809,10 @@ export function getToolDefinitions(): ({
|
|
|
765
809
|
headers?: undefined;
|
|
766
810
|
body?: undefined;
|
|
767
811
|
auth?: undefined;
|
|
812
|
+
title?: undefined;
|
|
813
|
+
defaultValue?: undefined;
|
|
814
|
+
message?: undefined;
|
|
815
|
+
icon?: undefined;
|
|
768
816
|
flow?: undefined;
|
|
769
817
|
shared?: undefined;
|
|
770
818
|
items?: undefined;
|
|
@@ -820,6 +868,10 @@ export function getToolDefinitions(): ({
|
|
|
820
868
|
headers?: undefined;
|
|
821
869
|
body?: undefined;
|
|
822
870
|
auth?: undefined;
|
|
871
|
+
title?: undefined;
|
|
872
|
+
defaultValue?: undefined;
|
|
873
|
+
message?: undefined;
|
|
874
|
+
icon?: undefined;
|
|
823
875
|
flow?: undefined;
|
|
824
876
|
shared?: undefined;
|
|
825
877
|
items?: undefined;
|
|
@@ -875,6 +927,10 @@ export function getToolDefinitions(): ({
|
|
|
875
927
|
headers?: undefined;
|
|
876
928
|
body?: undefined;
|
|
877
929
|
auth?: undefined;
|
|
930
|
+
title?: undefined;
|
|
931
|
+
defaultValue?: undefined;
|
|
932
|
+
message?: undefined;
|
|
933
|
+
icon?: undefined;
|
|
878
934
|
flow?: undefined;
|
|
879
935
|
shared?: undefined;
|
|
880
936
|
items?: undefined;
|
|
@@ -933,6 +989,10 @@ export function getToolDefinitions(): ({
|
|
|
933
989
|
headers?: undefined;
|
|
934
990
|
body?: undefined;
|
|
935
991
|
auth?: undefined;
|
|
992
|
+
title?: undefined;
|
|
993
|
+
defaultValue?: undefined;
|
|
994
|
+
message?: undefined;
|
|
995
|
+
icon?: undefined;
|
|
936
996
|
flow?: undefined;
|
|
937
997
|
shared?: undefined;
|
|
938
998
|
items?: undefined;
|
|
@@ -988,6 +1048,10 @@ export function getToolDefinitions(): ({
|
|
|
988
1048
|
headers?: undefined;
|
|
989
1049
|
body?: undefined;
|
|
990
1050
|
auth?: undefined;
|
|
1051
|
+
title?: undefined;
|
|
1052
|
+
defaultValue?: undefined;
|
|
1053
|
+
message?: undefined;
|
|
1054
|
+
icon?: undefined;
|
|
991
1055
|
flow?: undefined;
|
|
992
1056
|
shared?: undefined;
|
|
993
1057
|
items?: undefined;
|
|
@@ -1076,6 +1140,10 @@ export function getToolDefinitions(): ({
|
|
|
1076
1140
|
command?: undefined;
|
|
1077
1141
|
filePath?: undefined;
|
|
1078
1142
|
directoryPath?: undefined;
|
|
1143
|
+
title?: undefined;
|
|
1144
|
+
defaultValue?: undefined;
|
|
1145
|
+
message?: undefined;
|
|
1146
|
+
icon?: undefined;
|
|
1079
1147
|
flow?: undefined;
|
|
1080
1148
|
shared?: undefined;
|
|
1081
1149
|
items?: undefined;
|
|
@@ -1131,6 +1199,140 @@ export function getToolDefinitions(): ({
|
|
|
1131
1199
|
headers?: undefined;
|
|
1132
1200
|
body?: undefined;
|
|
1133
1201
|
auth?: undefined;
|
|
1202
|
+
title?: undefined;
|
|
1203
|
+
defaultValue?: undefined;
|
|
1204
|
+
message?: undefined;
|
|
1205
|
+
icon?: undefined;
|
|
1206
|
+
flow?: undefined;
|
|
1207
|
+
shared?: undefined;
|
|
1208
|
+
items?: undefined;
|
|
1209
|
+
output?: undefined;
|
|
1210
|
+
};
|
|
1211
|
+
required: string[];
|
|
1212
|
+
};
|
|
1213
|
+
} | {
|
|
1214
|
+
name: string;
|
|
1215
|
+
description: string;
|
|
1216
|
+
parameters: {
|
|
1217
|
+
type: string;
|
|
1218
|
+
properties: {
|
|
1219
|
+
prompt: {
|
|
1220
|
+
type: string;
|
|
1221
|
+
description: string;
|
|
1222
|
+
};
|
|
1223
|
+
title: {
|
|
1224
|
+
type: string;
|
|
1225
|
+
description: string;
|
|
1226
|
+
};
|
|
1227
|
+
defaultValue: {
|
|
1228
|
+
type: string;
|
|
1229
|
+
description: string;
|
|
1230
|
+
};
|
|
1231
|
+
model?: undefined;
|
|
1232
|
+
hfToken?: undefined;
|
|
1233
|
+
temperature?: undefined;
|
|
1234
|
+
max_new_tokens?: undefined;
|
|
1235
|
+
baseUrl?: undefined;
|
|
1236
|
+
action?: undefined;
|
|
1237
|
+
content?: undefined;
|
|
1238
|
+
query?: undefined;
|
|
1239
|
+
id?: undefined;
|
|
1240
|
+
metadata?: undefined;
|
|
1241
|
+
memoryPath?: undefined;
|
|
1242
|
+
embeddingModel?: undefined;
|
|
1243
|
+
embeddingBaseUrl?: undefined;
|
|
1244
|
+
topK?: undefined;
|
|
1245
|
+
text?: undefined;
|
|
1246
|
+
input?: undefined;
|
|
1247
|
+
transformFunction?: undefined;
|
|
1248
|
+
apiKey?: undefined;
|
|
1249
|
+
siteUrl?: undefined;
|
|
1250
|
+
siteTitle?: undefined;
|
|
1251
|
+
type?: undefined;
|
|
1252
|
+
selector?: undefined;
|
|
1253
|
+
jsonPath?: undefined;
|
|
1254
|
+
regex?: undefined;
|
|
1255
|
+
group?: undefined;
|
|
1256
|
+
code?: undefined;
|
|
1257
|
+
timeout?: undefined;
|
|
1258
|
+
args?: undefined;
|
|
1259
|
+
requireConfirmation?: undefined;
|
|
1260
|
+
cseId?: undefined;
|
|
1261
|
+
command?: undefined;
|
|
1262
|
+
filePath?: undefined;
|
|
1263
|
+
directoryPath?: undefined;
|
|
1264
|
+
url?: undefined;
|
|
1265
|
+
method?: undefined;
|
|
1266
|
+
headers?: undefined;
|
|
1267
|
+
body?: undefined;
|
|
1268
|
+
auth?: undefined;
|
|
1269
|
+
message?: undefined;
|
|
1270
|
+
icon?: undefined;
|
|
1271
|
+
flow?: undefined;
|
|
1272
|
+
shared?: undefined;
|
|
1273
|
+
items?: undefined;
|
|
1274
|
+
output?: undefined;
|
|
1275
|
+
};
|
|
1276
|
+
required: string[];
|
|
1277
|
+
};
|
|
1278
|
+
} | {
|
|
1279
|
+
name: string;
|
|
1280
|
+
description: string;
|
|
1281
|
+
parameters: {
|
|
1282
|
+
type: string;
|
|
1283
|
+
properties: {
|
|
1284
|
+
message: {
|
|
1285
|
+
type: string;
|
|
1286
|
+
description: string;
|
|
1287
|
+
};
|
|
1288
|
+
title: {
|
|
1289
|
+
type: string;
|
|
1290
|
+
description: string;
|
|
1291
|
+
};
|
|
1292
|
+
icon: {
|
|
1293
|
+
type: string;
|
|
1294
|
+
description: string;
|
|
1295
|
+
};
|
|
1296
|
+
prompt?: undefined;
|
|
1297
|
+
model?: undefined;
|
|
1298
|
+
hfToken?: undefined;
|
|
1299
|
+
temperature?: undefined;
|
|
1300
|
+
max_new_tokens?: undefined;
|
|
1301
|
+
baseUrl?: undefined;
|
|
1302
|
+
action?: undefined;
|
|
1303
|
+
content?: undefined;
|
|
1304
|
+
query?: undefined;
|
|
1305
|
+
id?: undefined;
|
|
1306
|
+
metadata?: undefined;
|
|
1307
|
+
memoryPath?: undefined;
|
|
1308
|
+
embeddingModel?: undefined;
|
|
1309
|
+
embeddingBaseUrl?: undefined;
|
|
1310
|
+
topK?: undefined;
|
|
1311
|
+
text?: undefined;
|
|
1312
|
+
input?: undefined;
|
|
1313
|
+
transformFunction?: undefined;
|
|
1314
|
+
apiKey?: undefined;
|
|
1315
|
+
siteUrl?: undefined;
|
|
1316
|
+
siteTitle?: undefined;
|
|
1317
|
+
type?: undefined;
|
|
1318
|
+
selector?: undefined;
|
|
1319
|
+
jsonPath?: undefined;
|
|
1320
|
+
regex?: undefined;
|
|
1321
|
+
group?: undefined;
|
|
1322
|
+
code?: undefined;
|
|
1323
|
+
timeout?: undefined;
|
|
1324
|
+
args?: undefined;
|
|
1325
|
+
requireConfirmation?: undefined;
|
|
1326
|
+
cseId?: undefined;
|
|
1327
|
+
command?: undefined;
|
|
1328
|
+
filePath?: undefined;
|
|
1329
|
+
directoryPath?: undefined;
|
|
1330
|
+
url?: undefined;
|
|
1331
|
+
method?: undefined;
|
|
1332
|
+
headers?: undefined;
|
|
1333
|
+
body?: undefined;
|
|
1334
|
+
auth?: undefined;
|
|
1335
|
+
defaultValue?: undefined;
|
|
1134
1336
|
flow?: undefined;
|
|
1135
1337
|
shared?: undefined;
|
|
1136
1338
|
items?: undefined;
|
|
@@ -1191,6 +1393,10 @@ export function getToolDefinitions(): ({
|
|
|
1191
1393
|
headers?: undefined;
|
|
1192
1394
|
body?: undefined;
|
|
1193
1395
|
auth?: undefined;
|
|
1396
|
+
title?: undefined;
|
|
1397
|
+
defaultValue?: undefined;
|
|
1398
|
+
message?: undefined;
|
|
1399
|
+
icon?: undefined;
|
|
1194
1400
|
items?: undefined;
|
|
1195
1401
|
output?: undefined;
|
|
1196
1402
|
};
|
|
@@ -1249,6 +1455,10 @@ export function getToolDefinitions(): ({
|
|
|
1249
1455
|
headers?: undefined;
|
|
1250
1456
|
body?: undefined;
|
|
1251
1457
|
auth?: undefined;
|
|
1458
|
+
title?: undefined;
|
|
1459
|
+
defaultValue?: undefined;
|
|
1460
|
+
message?: undefined;
|
|
1461
|
+
icon?: undefined;
|
|
1252
1462
|
shared?: undefined;
|
|
1253
1463
|
output?: undefined;
|
|
1254
1464
|
};
|
|
@@ -1303,6 +1513,10 @@ export function getToolDefinitions(): ({
|
|
|
1303
1513
|
headers?: undefined;
|
|
1304
1514
|
body?: undefined;
|
|
1305
1515
|
auth?: undefined;
|
|
1516
|
+
title?: undefined;
|
|
1517
|
+
defaultValue?: undefined;
|
|
1518
|
+
message?: undefined;
|
|
1519
|
+
icon?: undefined;
|
|
1306
1520
|
flow?: undefined;
|
|
1307
1521
|
shared?: undefined;
|
|
1308
1522
|
items?: undefined;
|
package/dist/agent/tools.js
CHANGED
|
@@ -2,7 +2,7 @@ export function getToolDefinitions() {
|
|
|
2
2
|
return [
|
|
3
3
|
{
|
|
4
4
|
name: "huggingface_llm_reasoning",
|
|
5
|
-
description: "
|
|
5
|
+
description: "Generates human-like text, reasons, and plans. Not for external actions.",
|
|
6
6
|
parameters: {
|
|
7
7
|
type: "object",
|
|
8
8
|
properties: {
|
|
@@ -36,7 +36,7 @@ export function getToolDefinitions() {
|
|
|
36
36
|
},
|
|
37
37
|
{
|
|
38
38
|
name: "semantic_memory_node",
|
|
39
|
-
description: "Stores and retrieves text
|
|
39
|
+
description: "Stores and retrieves text memories via semantic search (requires Ollama).",
|
|
40
40
|
parameters: {
|
|
41
41
|
type: "object",
|
|
42
42
|
properties: {
|
|
@@ -83,7 +83,7 @@ export function getToolDefinitions() {
|
|
|
83
83
|
},
|
|
84
84
|
{
|
|
85
85
|
name: "generate_embedding",
|
|
86
|
-
description: "Generates
|
|
86
|
+
description: "Generates vector embeddings for text (requires Ollama).",
|
|
87
87
|
parameters: {
|
|
88
88
|
type: "object",
|
|
89
89
|
properties: {
|
|
@@ -105,7 +105,7 @@ export function getToolDefinitions() {
|
|
|
105
105
|
},
|
|
106
106
|
{
|
|
107
107
|
name: "transform_node",
|
|
108
|
-
description: "Transforms
|
|
108
|
+
description: "Transforms data using a JavaScript function.",
|
|
109
109
|
parameters: {
|
|
110
110
|
type: "object",
|
|
111
111
|
properties: {
|
|
@@ -123,7 +123,7 @@ export function getToolDefinitions() {
|
|
|
123
123
|
},
|
|
124
124
|
{
|
|
125
125
|
name: "memory_node",
|
|
126
|
-
description: "Stores and retrieves text
|
|
126
|
+
description: "Stores and retrieves text memories (keyword-based).",
|
|
127
127
|
parameters: {
|
|
128
128
|
type: "object",
|
|
129
129
|
properties: {
|
|
@@ -154,7 +154,7 @@ export function getToolDefinitions() {
|
|
|
154
154
|
},
|
|
155
155
|
{
|
|
156
156
|
name: "llm_reasoning",
|
|
157
|
-
description: "
|
|
157
|
+
description: "Generates human-like text, reasons, and plans. Not for external actions.",
|
|
158
158
|
parameters: {
|
|
159
159
|
type: "object",
|
|
160
160
|
properties: {
|
|
@@ -168,7 +168,7 @@ export function getToolDefinitions() {
|
|
|
168
168
|
},
|
|
169
169
|
{
|
|
170
170
|
name: "openrouter_llm_reasoning",
|
|
171
|
-
description: "
|
|
171
|
+
description: "Generates human-like text, reasons, and plans via OpenRouter. Not for external actions.",
|
|
172
172
|
parameters: {
|
|
173
173
|
type: "object",
|
|
174
174
|
properties: {
|
|
@@ -198,7 +198,7 @@ export function getToolDefinitions() {
|
|
|
198
198
|
},
|
|
199
199
|
{
|
|
200
200
|
name: "ollama_llm_reasoning",
|
|
201
|
-
description: "
|
|
201
|
+
description: "Generates human-like text, reasons, and plans locally via Ollama. Not for external actions.",
|
|
202
202
|
parameters: {
|
|
203
203
|
type: "object",
|
|
204
204
|
properties: {
|
|
@@ -220,7 +220,7 @@ export function getToolDefinitions() {
|
|
|
220
220
|
},
|
|
221
221
|
{
|
|
222
222
|
name: "data_extractor",
|
|
223
|
-
description: "Extracts structured data from
|
|
223
|
+
description: "Extracts structured data from HTML, JSON, or text.",
|
|
224
224
|
parameters: {
|
|
225
225
|
type: "object",
|
|
226
226
|
properties: {
|
|
@@ -255,7 +255,7 @@ export function getToolDefinitions() {
|
|
|
255
255
|
},
|
|
256
256
|
{
|
|
257
257
|
name: "code_interpreter",
|
|
258
|
-
description: "Executes Python code
|
|
258
|
+
description: "Executes Python code (requires user confirmation).",
|
|
259
259
|
parameters: {
|
|
260
260
|
type: "object",
|
|
261
261
|
properties: {
|
|
@@ -282,7 +282,7 @@ export function getToolDefinitions() {
|
|
|
282
282
|
},
|
|
283
283
|
{
|
|
284
284
|
name: "duckduckgo_search",
|
|
285
|
-
description: "Performs
|
|
285
|
+
description: "Performs web searches via DuckDuckGo.",
|
|
286
286
|
parameters: {
|
|
287
287
|
type: "object",
|
|
288
288
|
properties: {
|
|
@@ -296,7 +296,7 @@ export function getToolDefinitions() {
|
|
|
296
296
|
},
|
|
297
297
|
{
|
|
298
298
|
name: "google_search",
|
|
299
|
-
description: "Performs
|
|
299
|
+
description: "Performs web searches via Google Custom Search (requires API key).",
|
|
300
300
|
parameters: {
|
|
301
301
|
type: "object",
|
|
302
302
|
properties: {
|
|
@@ -318,7 +318,7 @@ export function getToolDefinitions() {
|
|
|
318
318
|
},
|
|
319
319
|
{
|
|
320
320
|
name: "shell_command",
|
|
321
|
-
description: "Executes
|
|
321
|
+
description: "Executes shell commands.",
|
|
322
322
|
parameters: {
|
|
323
323
|
type: "object",
|
|
324
324
|
properties: {
|
|
@@ -332,7 +332,7 @@ export function getToolDefinitions() {
|
|
|
332
332
|
},
|
|
333
333
|
{
|
|
334
334
|
name: "read_file",
|
|
335
|
-
description: "Reads
|
|
335
|
+
description: "Reads file content.",
|
|
336
336
|
parameters: {
|
|
337
337
|
type: "object",
|
|
338
338
|
properties: {
|
|
@@ -346,7 +346,7 @@ export function getToolDefinitions() {
|
|
|
346
346
|
},
|
|
347
347
|
{
|
|
348
348
|
name: "write_file",
|
|
349
|
-
description: "Writes content to a
|
|
349
|
+
description: "Writes content to a file.",
|
|
350
350
|
parameters: {
|
|
351
351
|
type: "object",
|
|
352
352
|
properties: {
|
|
@@ -364,7 +364,7 @@ export function getToolDefinitions() {
|
|
|
364
364
|
},
|
|
365
365
|
{
|
|
366
366
|
name: "append_file",
|
|
367
|
-
description: "Appends content to
|
|
367
|
+
description: "Appends content to a file.",
|
|
368
368
|
parameters: {
|
|
369
369
|
type: "object",
|
|
370
370
|
properties: {
|
|
@@ -382,7 +382,7 @@ export function getToolDefinitions() {
|
|
|
382
382
|
},
|
|
383
383
|
{
|
|
384
384
|
name: "list_directory",
|
|
385
|
-
description: "Lists
|
|
385
|
+
description: "Lists directory contents.",
|
|
386
386
|
parameters: {
|
|
387
387
|
type: "object",
|
|
388
388
|
properties: {
|
|
@@ -396,7 +396,7 @@ export function getToolDefinitions() {
|
|
|
396
396
|
},
|
|
397
397
|
{
|
|
398
398
|
name: "http_request",
|
|
399
|
-
description: "Makes
|
|
399
|
+
description: "Makes HTTP requests.",
|
|
400
400
|
parameters: {
|
|
401
401
|
type: "object",
|
|
402
402
|
properties: {
|
|
@@ -447,7 +447,7 @@ export function getToolDefinitions() {
|
|
|
447
447
|
},
|
|
448
448
|
{
|
|
449
449
|
name: "web_scraper",
|
|
450
|
-
description: "Fetches
|
|
450
|
+
description: "Fetches HTML content from a URL. Use with 'data_extractor' for specifics.",
|
|
451
451
|
parameters: {
|
|
452
452
|
type: "object",
|
|
453
453
|
properties: {
|
|
@@ -461,7 +461,7 @@ export function getToolDefinitions() {
|
|
|
461
461
|
},
|
|
462
462
|
{
|
|
463
463
|
name: "user_input",
|
|
464
|
-
description: "Prompts
|
|
464
|
+
description: "Prompts user for input.",
|
|
465
465
|
parameters: {
|
|
466
466
|
type: "object",
|
|
467
467
|
properties: {
|
|
@@ -473,6 +473,50 @@ export function getToolDefinitions() {
|
|
|
473
473
|
required: ["prompt"]
|
|
474
474
|
}
|
|
475
475
|
},
|
|
476
|
+
{
|
|
477
|
+
name: "interactive_input",
|
|
478
|
+
description: "Prompts the user for input via a GUI popup (cross-platform).",
|
|
479
|
+
parameters: {
|
|
480
|
+
type: "object",
|
|
481
|
+
properties: {
|
|
482
|
+
prompt: {
|
|
483
|
+
type: "string",
|
|
484
|
+
description: "The message to display in the input dialog."
|
|
485
|
+
},
|
|
486
|
+
title: {
|
|
487
|
+
type: "string",
|
|
488
|
+
description: "Optional. The title of the input dialog. Defaults to 'QFlow Input'."
|
|
489
|
+
},
|
|
490
|
+
defaultValue: {
|
|
491
|
+
type: "string",
|
|
492
|
+
description: "Optional. The default value to pre-fill in the input field."
|
|
493
|
+
}
|
|
494
|
+
},
|
|
495
|
+
required: ["prompt"]
|
|
496
|
+
}
|
|
497
|
+
},
|
|
498
|
+
{
|
|
499
|
+
name: "system_notification",
|
|
500
|
+
description: "Displays a system-level notification across OSs.",
|
|
501
|
+
parameters: {
|
|
502
|
+
type: "object",
|
|
503
|
+
properties: {
|
|
504
|
+
message: {
|
|
505
|
+
type: "string",
|
|
506
|
+
description: "The main message content of the notification."
|
|
507
|
+
},
|
|
508
|
+
title: {
|
|
509
|
+
type: "string",
|
|
510
|
+
description: "Optional. The title of the notification. Defaults to 'QFlow Notification'."
|
|
511
|
+
},
|
|
512
|
+
icon: {
|
|
513
|
+
type: "string",
|
|
514
|
+
description: "Optional. Path to an icon file or a system icon name (Linux specific). Ignored on macOS/Windows."
|
|
515
|
+
}
|
|
516
|
+
},
|
|
517
|
+
required: ["message"]
|
|
518
|
+
}
|
|
519
|
+
},
|
|
476
520
|
{
|
|
477
521
|
name: "sub_flow",
|
|
478
522
|
description: "Executes a sub-flow.",
|
|
@@ -493,7 +537,7 @@ export function getToolDefinitions() {
|
|
|
493
537
|
},
|
|
494
538
|
{
|
|
495
539
|
name: "iterator",
|
|
496
|
-
description: "Iterates
|
|
540
|
+
description: "Iterates items, executes sub-flow for each.",
|
|
497
541
|
parameters: {
|
|
498
542
|
type: "object",
|
|
499
543
|
properties: {
|
|
@@ -511,7 +555,7 @@ export function getToolDefinitions() {
|
|
|
511
555
|
},
|
|
512
556
|
{
|
|
513
557
|
name: "finish",
|
|
514
|
-
description: "
|
|
558
|
+
description: "Ends agent execution, returns final output.",
|
|
515
559
|
parameters: {
|
|
516
560
|
type: "object",
|
|
517
561
|
properties: {
|
package/dist/nodes/index.d.ts
CHANGED
|
@@ -6,6 +6,8 @@ export * from "./hackernews.js";
|
|
|
6
6
|
export * from "./github.js";
|
|
7
7
|
export * from "./stripe.js";
|
|
8
8
|
export * from "./webscraper.js";
|
|
9
|
+
export * from "./system_notification.js";
|
|
10
|
+
export * from "./interactive_input.js";
|
|
9
11
|
export * from "./shell.js";
|
|
10
12
|
export * from "./filesystem.js";
|
|
11
13
|
export * from "./user.js";
|
package/dist/nodes/index.js
CHANGED
|
@@ -6,6 +6,8 @@ export * from './hackernews.js';
|
|
|
6
6
|
export * from './github.js';
|
|
7
7
|
export * from './stripe.js';
|
|
8
8
|
export * from './webscraper.js';
|
|
9
|
+
export * from './system_notification.js';
|
|
10
|
+
export * from './interactive_input.js';
|
|
9
11
|
export * from './shell.js';
|
|
10
12
|
export * from './filesystem.js';
|
|
11
13
|
export * from './user.js';
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
import { exec } from 'child_process';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
export class InteractiveInputNode extends AsyncNode {
|
|
5
|
+
constructor(maxRetries = 1, wait = 0) {
|
|
6
|
+
super(maxRetries, wait);
|
|
7
|
+
}
|
|
8
|
+
async execAsync() {
|
|
9
|
+
const { prompt, title = 'QFlow Input', defaultValue = '' } = this.params;
|
|
10
|
+
if (!prompt) {
|
|
11
|
+
throw new Error('InteractiveInputNode requires a `prompt` parameter.');
|
|
12
|
+
}
|
|
13
|
+
let command = '';
|
|
14
|
+
const platform = os.platform();
|
|
15
|
+
switch (platform) {
|
|
16
|
+
case 'linux':
|
|
17
|
+
let linuxCommand = '';
|
|
18
|
+
try {
|
|
19
|
+
await new Promise((res, rej) => exec('which zenity', (e) => e ? rej(e) : res()));
|
|
20
|
+
linuxCommand = `zenity --entry --title="${title}" --text="${prompt}" --entry-text="${defaultValue}"`;
|
|
21
|
+
}
|
|
22
|
+
catch (e) {
|
|
23
|
+
try {
|
|
24
|
+
await new Promise((res, rej) => exec('which kdialog', (e) => e ? rej(e) : res()));
|
|
25
|
+
linuxCommand = `kdialog --inputbox "${prompt}" "${defaultValue}" --title "${title}"`;
|
|
26
|
+
}
|
|
27
|
+
catch (e2) {
|
|
28
|
+
throw new Error('No GUI input tool (zenity or kdialog) found on Linux. Please install one or use UserInputNode.');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
command = linuxCommand;
|
|
32
|
+
break;
|
|
33
|
+
case 'darwin': // macOS
|
|
34
|
+
// osascript -e 'set T to text returned of (display dialog "PROMPT" default answer "DEFAULT" with title "TITLE")'
|
|
35
|
+
command = `osascript -e 'set T to text returned of (display dialog "${prompt}" default answer "${defaultValue}" with title "${title}")'`;
|
|
36
|
+
break;
|
|
37
|
+
case 'win32': // Windows
|
|
38
|
+
// PowerShell for input box
|
|
39
|
+
// (New-Object -TypeName Microsoft.VisualBasic.Interaction).InputBox("PROMPT", "TITLE", "DEFAULT")
|
|
40
|
+
command = `powershell -Command "(New-Object -TypeName Microsoft.VisualBasic.Interaction).InputBox(\"${prompt}\", \"${title}\", \"${defaultValue}\")"`;
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
throw new Error(`Unsupported platform for InteractiveInputNode: ${platform}`);
|
|
44
|
+
}
|
|
45
|
+
console.log(`[InteractiveInputNode] Executing: ${command}`);
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
exec(command, (error, stdout, stderr) => {
|
|
48
|
+
if (error) {
|
|
49
|
+
// User cancelled the dialog or tool not found
|
|
50
|
+
console.error(`InteractiveInputNode error: ${error.message}`);
|
|
51
|
+
// Differentiate between user cancellation and actual error
|
|
52
|
+
if (error.code === 1 && platform === 'linux' && error.message.includes('zenity')) {
|
|
53
|
+
// Zenity returns 1 on cancel
|
|
54
|
+
return resolve(null); // Or reject with a specific message
|
|
55
|
+
}
|
|
56
|
+
if (error.message.includes('User canceled')) { // osascript cancel
|
|
57
|
+
return resolve(null);
|
|
58
|
+
}
|
|
59
|
+
return reject(error);
|
|
60
|
+
}
|
|
61
|
+
if (stderr) {
|
|
62
|
+
console.warn(`InteractiveInputNode stderr: ${stderr}`);
|
|
63
|
+
}
|
|
64
|
+
const userInput = stdout.trim();
|
|
65
|
+
console.log(`User input received: "${userInput}"`);
|
|
66
|
+
resolve(userInput);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AsyncNode } from '../qflow.js';
|
|
2
|
+
import { exec } from 'child_process';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
export class SystemNotificationNode extends AsyncNode {
|
|
5
|
+
constructor(maxRetries = 1, wait = 0) {
|
|
6
|
+
super(maxRetries, wait);
|
|
7
|
+
}
|
|
8
|
+
async execAsync() {
|
|
9
|
+
const { message, title = 'QFlow', icon = '' } = this.params;
|
|
10
|
+
if (!message) {
|
|
11
|
+
throw new Error('SystemNotificationNode requires a `message` parameter.');
|
|
12
|
+
}
|
|
13
|
+
let command = '';
|
|
14
|
+
const platform = os.platform();
|
|
15
|
+
switch (platform) {
|
|
16
|
+
case 'linux':
|
|
17
|
+
// Requires 'notify-send' (libnotify-bin package)
|
|
18
|
+
command = `notify-send "${title}" "${message}"`;
|
|
19
|
+
if (icon)
|
|
20
|
+
command += ` -i "${icon}"`;
|
|
21
|
+
break;
|
|
22
|
+
case 'darwin': // macOS
|
|
23
|
+
command = `osascript -e 'display notification "${message}" with title "${title}"'`;
|
|
24
|
+
// osascript doesn't directly support icons in this simple form
|
|
25
|
+
break;
|
|
26
|
+
case 'win32': // Windows
|
|
27
|
+
// Using PowerShell for a simple message box.
|
|
28
|
+
// For more advanced toast notifications, a dedicated module or more complex script would be needed.
|
|
29
|
+
command = `powershell -Command "[System.Windows.Forms.MessageBox]::Show(\"${message}\", \"${title}\")"`;
|
|
30
|
+
break;
|
|
31
|
+
default:
|
|
32
|
+
throw new Error(`Unsupported platform for SystemNotificationNode: ${platform}`);
|
|
33
|
+
}
|
|
34
|
+
console.log(`[SystemNotificationNode] Executing: ${command}`);
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
exec(command, (error, stdout, stderr) => {
|
|
37
|
+
if (error) {
|
|
38
|
+
console.error(`SystemNotificationNode error: ${error.message}`);
|
|
39
|
+
return reject(error);
|
|
40
|
+
}
|
|
41
|
+
if (stderr) {
|
|
42
|
+
console.warn(`SystemNotificationNode stderr: ${stderr}`);
|
|
43
|
+
}
|
|
44
|
+
console.log(`Notification displayed: "${message}"`);
|
|
45
|
+
resolve({ message, title, stdout, stderr });
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
}
|
package/package.json
CHANGED