@fractal-solutions/qflow 1.0.62 → 1.0.63

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 (109) hide show
  1. package/package.json +1 -1
  2. package/dist/agent/agent.d.ts +0 -23
  3. package/dist/agent/agent.js +0 -365
  4. package/dist/agent/base_agent.d.ts +0 -21
  5. package/dist/agent/base_agent.js +0 -206
  6. package/dist/agent/logger.d.ts +0 -9
  7. package/dist/agent/logger.js +0 -45
  8. package/dist/agent/lpavrl_agent.d.ts +0 -5
  9. package/dist/agent/lpavrl_agent.js +0 -178
  10. package/dist/agent/ooda_agent.d.ts +0 -5
  11. package/dist/agent/ooda_agent.js +0 -167
  12. package/dist/agent/pema_agent.d.ts +0 -5
  13. package/dist/agent/pema_agent.js +0 -171
  14. package/dist/agent/raor_agent.d.ts +0 -5
  15. package/dist/agent/raor_agent.js +0 -164
  16. package/dist/agent/tools.d.ts +0 -5378
  17. package/dist/agent/tools.js +0 -1174
  18. package/dist/logger.d.ts +0 -9
  19. package/dist/logger.js +0 -107
  20. package/dist/nodes/agent_llm.d.ts +0 -31
  21. package/dist/nodes/agent_llm.js +0 -302
  22. package/dist/nodes/browser_control.d.ts +0 -4
  23. package/dist/nodes/browser_control.js +0 -73
  24. package/dist/nodes/code_interpreter.d.ts +0 -9
  25. package/dist/nodes/code_interpreter.js +0 -121
  26. package/dist/nodes/data_extractor.d.ts +0 -5
  27. package/dist/nodes/data_extractor.js +0 -81
  28. package/dist/nodes/data_validation.d.ts +0 -9
  29. package/dist/nodes/data_validation.js +0 -48
  30. package/dist/nodes/database.d.ts +0 -6
  31. package/dist/nodes/database.js +0 -89
  32. package/dist/nodes/display_image.d.ts +0 -4
  33. package/dist/nodes/display_image.js +0 -47
  34. package/dist/nodes/embedding.d.ts +0 -7
  35. package/dist/nodes/embedding.js +0 -45
  36. package/dist/nodes/filesystem.d.ts +0 -41
  37. package/dist/nodes/filesystem.js +0 -88
  38. package/dist/nodes/gis.d.ts +0 -37
  39. package/dist/nodes/gis.js +0 -106
  40. package/dist/nodes/git.d.ts +0 -4
  41. package/dist/nodes/git.js +0 -55
  42. package/dist/nodes/github.d.ts +0 -27
  43. package/dist/nodes/github.js +0 -75
  44. package/dist/nodes/hackernews.d.ts +0 -19
  45. package/dist/nodes/hackernews.js +0 -47
  46. package/dist/nodes/hardware_interaction.d.ts +0 -8
  47. package/dist/nodes/hardware_interaction.js +0 -98
  48. package/dist/nodes/http.d.ts +0 -26
  49. package/dist/nodes/http.js +0 -67
  50. package/dist/nodes/http_server.d.ts +0 -17
  51. package/dist/nodes/http_server.js +0 -190
  52. package/dist/nodes/image_gallery.d.ts +0 -8
  53. package/dist/nodes/image_gallery.js +0 -100
  54. package/dist/nodes/index.d.ts +0 -48
  55. package/dist/nodes/index.js +0 -48
  56. package/dist/nodes/interactive_input.d.ts +0 -4
  57. package/dist/nodes/interactive_input.js +0 -71
  58. package/dist/nodes/interactive_webview.d.ts +0 -19
  59. package/dist/nodes/interactive_webview.js +0 -310
  60. package/dist/nodes/iterator.d.ts +0 -5
  61. package/dist/nodes/iterator.js +0 -23
  62. package/dist/nodes/llm.d.ts +0 -18
  63. package/dist/nodes/llm.js +0 -215
  64. package/dist/nodes/memory.d.ts +0 -12
  65. package/dist/nodes/memory.js +0 -48
  66. package/dist/nodes/multimedia_processing.d.ts +0 -10
  67. package/dist/nodes/multimedia_processing.js +0 -80
  68. package/dist/nodes/openrouter_llm.d.ts +0 -8
  69. package/dist/nodes/openrouter_llm.js +0 -124
  70. package/dist/nodes/pdf_processor.d.ts +0 -4
  71. package/dist/nodes/pdf_processor.js +0 -75
  72. package/dist/nodes/remote_execution.d.ts +0 -4
  73. package/dist/nodes/remote_execution.js +0 -83
  74. package/dist/nodes/s3.d.ts +0 -6
  75. package/dist/nodes/s3.js +0 -38
  76. package/dist/nodes/scheduler.d.ts +0 -20
  77. package/dist/nodes/scheduler.js +0 -98
  78. package/dist/nodes/search.d.ts +0 -25
  79. package/dist/nodes/search.js +0 -78
  80. package/dist/nodes/semantic_memory.d.ts +0 -17
  81. package/dist/nodes/semantic_memory.js +0 -111
  82. package/dist/nodes/shell.d.ts +0 -11
  83. package/dist/nodes/shell.js +0 -29
  84. package/dist/nodes/speech_synthesis.d.ts +0 -45
  85. package/dist/nodes/speech_synthesis.js +0 -142
  86. package/dist/nodes/spreadsheet.d.ts +0 -10
  87. package/dist/nodes/spreadsheet.js +0 -241
  88. package/dist/nodes/stripe.d.ts +0 -23
  89. package/dist/nodes/stripe.js +0 -69
  90. package/dist/nodes/subflow.d.ts +0 -5
  91. package/dist/nodes/subflow.js +0 -16
  92. package/dist/nodes/summarize.d.ts +0 -12
  93. package/dist/nodes/summarize.js +0 -31
  94. package/dist/nodes/system_notification.d.ts +0 -4
  95. package/dist/nodes/system_notification.js +0 -50
  96. package/dist/nodes/transform.d.ts +0 -5
  97. package/dist/nodes/transform.js +0 -32
  98. package/dist/nodes/user.d.ts +0 -11
  99. package/dist/nodes/user.js +0 -32
  100. package/dist/nodes/webhook.d.ts +0 -15
  101. package/dist/nodes/webhook.js +0 -125
  102. package/dist/nodes/webscraper.d.ts +0 -11
  103. package/dist/nodes/webscraper.js +0 -33
  104. package/dist/nodes/websockets.d.ts +0 -4
  105. package/dist/nodes/websockets.js +0 -73
  106. package/dist/nodes/webview.d.ts +0 -12
  107. package/dist/nodes/webview.js +0 -27
  108. package/dist/qflow.d.ts +0 -69
  109. package/dist/qflow.js +0 -320
@@ -1,164 +0,0 @@
1
- import { BaseAgent } from './base_agent.js';
2
- import { logger } from './logger.js';
3
- import { AsyncNode, AsyncFlow, Flow } from '../qflow.js';
4
- import { UserInputNode } from '../nodes/index.js';
5
- export class RAORAgent extends BaseAgent {
6
- async execAsync() {
7
- const { goal } = this.params;
8
- if (!goal) {
9
- throw new Error("RAORAgent requires a 'goal' parameter.");
10
- }
11
- this.conversationHistory = [
12
- { role: "system", content: this.getSystemPrompt() },
13
- { role: "user", content: `Goal: ${goal}` },
14
- ];
15
- let step = 0;
16
- let finalOutput = null;
17
- while (step < this.maxSteps) {
18
- step++;
19
- logger.info(`Agent Step ${step}`);
20
- // Reason
21
- this.conversationHistory.push({ role: "user", content: "Current Phase: REASON. Analyze the user's request and formulate a plan." });
22
- const reasonResponse = await this.getLLMAction();
23
- let parsedReasonResponse;
24
- try {
25
- parsedReasonResponse = this.parseLLMResponse(reasonResponse);
26
- }
27
- catch (e) {
28
- logger.error(`Error parsing LLM response in Reason phase: ${e.message}`);
29
- this.conversationHistory.push({ role: "user", content: `
30
- CRITICAL ERROR: Your last response was NOT valid JSON or did not follow the expected format.
31
- Error details: ${e.message}
32
- Your invalid response was:
33
- '''${reasonResponse}'''
34
- You MUST respond with a single JSON object containing 'thought' and 'tool_calls'. Do NOT generate any other text or code outside of this JSON structure. Re-evaluate your plan and provide a valid JSON response.
35
- ` });
36
- continue; // Re-run the loop to allow the LLM to correct itself
37
- }
38
- const { thought, toolCalls, parallel } = parsedReasonResponse;
39
- logger.thought(thought);
40
- this.conversationHistory.push({ role: "assistant", content: JSON.stringify({ thought, tool_calls: toolCalls, parallel }) });
41
- // Validate tool parameters for all tool calls
42
- const validationErrors = toolCalls.map(tc => this.validateToolParameters(tc)).filter(Boolean);
43
- if (validationErrors.length > 0) {
44
- const errorMessage = `Tool parameter validation failed for one or more tools: ${validationErrors.join('; ')}. Please correct the parameters.`;
45
- logger.error(errorMessage);
46
- this.conversationHistory.push({ role: "user", content: `Error: ${errorMessage}` });
47
- continue; // Re-run the loop to allow the LLM to correct itself
48
- }
49
- // Handle finish tool (check here before acting)
50
- const finishToolCall = toolCalls.find(tc => tc.tool === "finish");
51
- if (finishToolCall) {
52
- finalOutput = finishToolCall.parameters.output;
53
- if (this.requireFinishConfirmation) {
54
- const confirmNode = new UserInputNode();
55
- confirmNode.setParams({
56
- prompt: `Agent proposes to finish with output: "${finalOutput}". Do you approve? (yes/no): `
57
- });
58
- const confirmFlow = new AsyncFlow(confirmNode);
59
- const confirmation = await confirmFlow.runAsync({});
60
- if (confirmation.toLowerCase() !== 'yes') {
61
- logger.info("Agent finish denied by user. User input will be the next prompt.");
62
- this.conversationHistory.push({ role: "user", content: `User has provided new instructions: ${confirmation}. Please adjust your plan and continue working.` });
63
- continue; // Continue the loop
64
- }
65
- }
66
- logger.final(finalOutput);
67
- break; // Exit the main loop as agent is finished
68
- }
69
- // If no tool calls and not trying to finish, prompt LLM to generate tool calls
70
- if (toolCalls.length === 0) {
71
- this.conversationHistory.push({ role: "user", content: "Current Phase: REASON. Your previous response did not include any tool calls. If you intend to take action, you MUST include at least one tool call in your JSON response. Re-evaluate your plan and provide tool calls." });
72
- continue; // Re-run the loop to force tool call generation
73
- }
74
- // Act
75
- const observations = await this.executeToolCalls(toolCalls, parallel);
76
- this.conversationHistory.push({ role: "user", content: `Observation: ${JSON.stringify(observations)}` });
77
- // Check for tool errors and add specific instructions for reflection
78
- const toolErrors = observations.filter(obs => obs.success === false);
79
- if (toolErrors.length > 0) {
80
- const errorMessages = toolErrors.map(err => `Tool: ${err.tool}, Parameters: ${JSON.stringify(err.parameters)}, Error: ${err.error}`).join('\n');
81
- this.conversationHistory.push({ role: "system", content: `
82
- IMPORTANT: One or more tool calls failed. Analyze the following errors carefully:
83
- ${errorMessages}
84
-
85
- Explain *why* these tools failed. Propose an alternative tool or a revised plan to achieve the goal without these tools, or suggest how to fix the underlying issue. Do NOT generate irrelevant code, random thoughts, or go off-topic. Focus solely on addressing these errors and getting back on track to achieve the user's goal. If you are stuck, consider using the 'user_input' or 'interactive_input' tool to ask the user for clarification.
86
- ` });
87
- }
88
- else {
89
- this.conversationHistory.push({ role: "user", content: "Current Phase: REFLECT. Evaluate if the result moves toward the goal and adjust plan if needed." });
90
- }
91
- const reflectResponse = await this.getLLMAction();
92
- const { thought: reflectThought } = this.parseLLMResponse(reflectResponse);
93
- logger.thought(reflectThought);
94
- this.conversationHistory.push({ role: "assistant", content: JSON.stringify({ thought: reflectThought }) });
95
- }
96
- if (step >= this.maxSteps && finalOutput === null) {
97
- const message = "Agent reached max steps without finishing. Last observation: " + JSON.stringify(this.conversationHistory[this.conversationHistory.length - 1]);
98
- logger.error(message);
99
- finalOutput = message;
100
- }
101
- return finalOutput;
102
- }
103
- async executeToolCalls(toolCalls, parallel) {
104
- const executeTool = async (toolCall) => {
105
- const toolInstance = this.availableTools[toolCall.tool];
106
- if (!toolInstance) {
107
- return `Error: Tool '${toolCall.tool}' not found. Available tools: ${Object.keys(this.availableTools).join(', ')}.`;
108
- }
109
- let toolOutput;
110
- try {
111
- logger.toolCall(toolCall.tool, toolCall.parameters);
112
- if (toolCall.tool === 'sub_flow' || toolCall.tool === 'iterator' || toolCall.tool === 'scheduler') {
113
- const flowName = toolCall.parameters.flow;
114
- if (!this.flowRegistry[flowName]) {
115
- throw new Error(`Flow '${flowName}' not found in registry.`);
116
- }
117
- toolCall.parameters.flow = this.flowRegistry[flowName];
118
- }
119
- toolInstance.setParams(toolCall.parameters);
120
- const ToolFlowClass = toolInstance instanceof AsyncNode ? AsyncFlow : Flow;
121
- const toolFlow = new ToolFlowClass(toolInstance);
122
- if (toolInstance instanceof AsyncNode) {
123
- toolOutput = await toolFlow.runAsync({});
124
- }
125
- else {
126
- toolOutput = toolFlow.run({});
127
- }
128
- logger.toolResult(toolCall.tool, toolOutput);
129
- if (this.summarizeLLM && typeof toolOutput === 'string' && toolOutput.length > 1000) {
130
- logger.info(`Summarizing large tool output (${toolOutput.length} chars)...`);
131
- const summarizeNode = new SummarizeNode();
132
- summarizeNode.setParams({ text: toolOutput, llmNode: this.summarizeLLM });
133
- const summarizeFlow = new AsyncFlow(summarizeNode);
134
- toolOutput = await summarizeFlow.runAsync({});
135
- logger.info(`Summarized to ${toolOutput.length} chars.`);
136
- }
137
- return { success: true, output: toolOutput };
138
- }
139
- catch (e) {
140
- return { success: false, error: `Error executing tool '${toolCall.tool}': ${e.message}` };
141
- }
142
- };
143
- let observations = [];
144
- if (parallel) {
145
- const results = await Promise.all(toolCalls.map(executeTool));
146
- observations = results.map((result, index) => ({
147
- tool: toolCalls[index].tool,
148
- parameters: toolCalls[index].parameters,
149
- ...result // Spread success/error and output/error
150
- }));
151
- }
152
- else {
153
- for (const toolCall of toolCalls) {
154
- const result = await executeTool(toolCall);
155
- observations.push({
156
- tool: toolCall.tool,
157
- parameters: toolCall.parameters,
158
- ...result // Spread success/error and output/error
159
- });
160
- }
161
- }
162
- return observations;
163
- }
164
- }