@fractal-solutions/qflow 1.0.8 → 1.0.10
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 +157 -6
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -470,23 +470,174 @@ const flow = new AsyncFlow(writeFile);
|
|
|
470
470
|
await flow.runAsync({});
|
|
471
471
|
```
|
|
472
472
|
|
|
473
|
+
### 10. Generic HTTP Request Example
|
|
474
|
+
|
|
475
|
+
Making a GET request to a public API and printing the response.
|
|
476
|
+
|
|
477
|
+
```javascript
|
|
478
|
+
import { AsyncFlow } from '@fractal-solutions/qflow';
|
|
479
|
+
import { HttpRequestNode } from '@fractal-solutions/qflow/nodes';
|
|
480
|
+
|
|
481
|
+
const getPost = new HttpRequestNode();
|
|
482
|
+
getPost.setParams({
|
|
483
|
+
url: 'https://jsonplaceholder.typicode.com/posts/1',
|
|
484
|
+
method: 'GET'
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
getPost.postAsync = async (shared, prepRes, execRes) => {
|
|
488
|
+
console.log('--- API Response ---');
|
|
489
|
+
console.log('Status:', execRes.status);
|
|
490
|
+
console.log('Body:', execRes.body);
|
|
491
|
+
return 'default';
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
const flow = new AsyncFlow(getPost);
|
|
495
|
+
await flow.runAsync({});
|
|
496
|
+
```
|
|
497
|
+
|
|
498
|
+
### 11. Web Search Example
|
|
499
|
+
|
|
500
|
+
Performing web searches using both a free metasearch engine and a commercial API.
|
|
501
|
+
|
|
502
|
+
```javascript
|
|
503
|
+
import { AsyncFlow } from '@fractal-solutions/qflow';
|
|
504
|
+
import { DuckDuckGoSearchNode, GoogleSearchNode } from '@fractal-solutions/qflow/nodes';
|
|
505
|
+
|
|
506
|
+
// Example 1: Using DuckDuckGo (no API key needed)
|
|
507
|
+
const ddgSearch = new DuckDuckGoSearchNode();
|
|
508
|
+
ddgSearch.setParams({ query: 'qflow library github' });
|
|
509
|
+
ddgSearch.postAsync = async (shared, prepRes, execRes) => {
|
|
510
|
+
console.log('\n--- DuckDuckGo Search Results ---');
|
|
511
|
+
execRes.slice(0, 5).forEach(r => console.log(`- ${r.title}: ${r.link}`));
|
|
512
|
+
return 'default';
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
// Example 2: Using Google Custom Search (requires API key and CSE ID)
|
|
516
|
+
const googleSearch = new GoogleSearchNode();
|
|
517
|
+
googleSearch.setParams({
|
|
518
|
+
query: 'qflow framework benefits',
|
|
519
|
+
apiKey: process.env.GOOGLE_API_KEY, // Set this env var
|
|
520
|
+
cseId: process.env.GOOGLE_CSE_ID // Set this env var
|
|
521
|
+
});
|
|
522
|
+
googleSearch.postAsync = async (shared, prepRes, execRes) => {
|
|
523
|
+
console.log('\n--- Google Search Results ---');
|
|
524
|
+
execRes.slice(0, 5).forEach(r => console.log(`- ${r.title}: ${r.link}`));
|
|
525
|
+
return 'default';
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
// Chain them or run independently
|
|
529
|
+
const flow1 = new AsyncFlow(ddgSearch);
|
|
530
|
+
await flow1.runAsync({});
|
|
531
|
+
|
|
532
|
+
// Uncomment the following lines to run the Google Search example
|
|
533
|
+
// const flow2 = new AsyncFlow(googleSearch);
|
|
534
|
+
// await flow2.runAsync({});
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
### 12. Interactive Agent Example
|
|
538
|
+
|
|
539
|
+
An agent that takes a goal from user input and uses its tools to achieve it.
|
|
540
|
+
|
|
541
|
+
```javascript
|
|
542
|
+
import { AsyncFlow } from '@fractal-solutions/qflow';
|
|
543
|
+
import {
|
|
544
|
+
AgentDeepSeekLLMNode,
|
|
545
|
+
DuckDuckGoSearchNode,
|
|
546
|
+
ShellCommandNode,
|
|
547
|
+
ReadFileNode,
|
|
548
|
+
WriteFileNode,
|
|
549
|
+
HttpRequestNode,
|
|
550
|
+
ScrapeURLNode,
|
|
551
|
+
UserInputNode,
|
|
552
|
+
AgentNode
|
|
553
|
+
} from '@fractal-solutions/qflow/nodes';
|
|
554
|
+
|
|
555
|
+
// Ensure your DeepSeek API Key is set as an environment variable
|
|
556
|
+
const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
|
|
557
|
+
|
|
558
|
+
(async () => {
|
|
559
|
+
if (!DEEPSEEK_API_KEY) {
|
|
560
|
+
console.warn("WARNING: DEEPSEEK_API_KEY is not set. Please set it to run the Interactive Agent example.");
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
console.log('--- Running Interactive Agent Test Workflow ---');
|
|
565
|
+
|
|
566
|
+
// 1. Node to get the goal from the user
|
|
567
|
+
const getGoalNode = new UserInputNode();
|
|
568
|
+
getGoalNode.setParams({ prompt: 'Please enter the agent\'s goal: ' });
|
|
569
|
+
|
|
570
|
+
// 2. Instantiate the LLM for the agent's reasoning
|
|
571
|
+
const agentLLM = new AgentDeepSeekLLMNode();
|
|
572
|
+
agentLLM.setParams({ apiKey: DEEPSEEK_API_KEY });
|
|
573
|
+
|
|
574
|
+
// 3. Instantiate the tools the agent can use
|
|
575
|
+
const duckduckgoSearch = new DuckDuckGoSearchNode();
|
|
576
|
+
const shellCommand = new ShellCommandNode();
|
|
577
|
+
const readFile = new ReadFileNode();
|
|
578
|
+
const writeFile = new WriteFileNode();
|
|
579
|
+
const httpRequest = new HttpRequestNode();
|
|
580
|
+
const webScraper = new ScrapeURLNode();
|
|
581
|
+
const userInput = new UserInputNode(); // Agent can also ask for user input
|
|
582
|
+
|
|
583
|
+
// Map tool names to their instances
|
|
584
|
+
const availableTools = {
|
|
585
|
+
duckduckgo_search: duckduckgoSearch,
|
|
586
|
+
shell_command: shellCommand,
|
|
587
|
+
read_file: readFile,
|
|
588
|
+
write_file: writeFile,
|
|
589
|
+
http_request: httpRequest,
|
|
590
|
+
web_scraper: webScraper,
|
|
591
|
+
user_input: userInput,
|
|
592
|
+
// Add other tools as needed
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
// 4. Instantiate the AgentNode
|
|
596
|
+
const agent = new AgentNode(agentLLM, availableTools);
|
|
597
|
+
// The goal will be set dynamically from the UserInputNode's output
|
|
598
|
+
agent.prepAsync = async (shared) => {
|
|
599
|
+
agent.setParams({ goal: shared.userInput });
|
|
600
|
+
};
|
|
601
|
+
|
|
602
|
+
// 5. Chain the nodes: Get Goal -> Agent
|
|
603
|
+
getGoalNode.next(agent);
|
|
604
|
+
|
|
605
|
+
// 6. Create and run the flow
|
|
606
|
+
const interactiveAgentFlow = new AsyncFlow(getGoalNode);
|
|
607
|
+
|
|
608
|
+
try {
|
|
609
|
+
const finalResult = await interactiveAgentFlow.runAsync({});
|
|
610
|
+
console.log('\n--- Interactive Agent Test Workflow Finished ---');
|
|
611
|
+
console.log('Final Agent Output:', finalResult);
|
|
612
|
+
} catch (error) {
|
|
613
|
+
console.error('\n--- Interactive Agent Test Workflow Failed ---', error);
|
|
614
|
+
}
|
|
615
|
+
})();
|
|
473
616
|
```
|
|
474
617
|
|
|
618
|
+
|
|
475
619
|
## Exploring More Examples
|
|
476
620
|
|
|
477
621
|
The examples above cover the core functionalities of `qflow`. For more advanced and specific use cases involving the built-in integrations, please explore the [`examples/` folder](https://github.com/fractal-solutions/qflow/tree/main/examples) in the project's GitHub repository. There you will find detailed scripts demonstrating how to use nodes for:
|
|
478
622
|
|
|
623
|
+
* **LLMs (DeepSeek, OpenAI, Gemini):** The core of agentic behavior.
|
|
624
|
+
* **Agent:** Orchestrating tools and LLM reasoning to achieve complex goals.
|
|
625
|
+
* **Interactive Agent:** An agent that takes a goal from user input and uses its tools to achieve it.
|
|
626
|
+
* **Shell:** For system-level interaction and execution.
|
|
627
|
+
* **HTTP:** For universal API access.
|
|
628
|
+
* **FileSystem:** For reading and writing local data.
|
|
629
|
+
* **User Input:** For human-in-the-loop control.
|
|
630
|
+
* **Web Search:** Discovering information on the web using either:
|
|
631
|
+
* `DuckDuckGoSearchNode`: API-key-free, using DuckDuckGo's HTML interface.
|
|
632
|
+
* `GoogleSearchNode`: Requires a Google API Key and Custom Search Engine ID for more robust results.
|
|
633
|
+
* **WebScraper:** For targeted data extraction.
|
|
479
634
|
* **GitHub:** Creating and managing issues.
|
|
480
635
|
* **HackerNews:** Fetching top stories and item details.
|
|
481
636
|
* **Stripe:** Creating charges and retrieving account balances.
|
|
482
|
-
* **WebScraper:** Fetching and processing web content.
|
|
483
|
-
* **LLMs (DeepSeek, OpenAI, Gemini):** Building powerful AI-driven workflows.
|
|
484
|
-
* **Shell:** Executing shell commands.
|
|
485
|
-
* **FileSystem:** Reading, writing, and appending files, and listing directories.
|
|
486
|
-
* **User Input:** Pausing a flow to request user feedback or approval.
|
|
487
637
|
|
|
488
638
|
These examples are a great resource for understanding how to leverage `qflow` to its full potential.
|
|
489
639
|
|
|
640
|
+
|
|
490
641
|
## Error Handling
|
|
491
642
|
|
|
492
643
|
|
|
@@ -595,4 +746,4 @@ test("Node should handle parameters via setParams", () => {
|
|
|
595
746
|
|
|
596
747
|
We welcome contributions! Please see our GitHub repository for more details on how to contribute.
|
|
597
748
|
|
|
598
|
-
---
|
|
749
|
+
---
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fractal-solutions/qflow",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "A lightweight and flexible JavaScript library for creating and managing workflows and agents.",
|
|
5
5
|
"main": "dist/qflow.js",
|
|
6
6
|
"types": "dist/qflow.d.ts",
|
|
@@ -41,6 +41,9 @@
|
|
|
41
41
|
"url": "https://github.com/fractal-solutions/qflow/issues"
|
|
42
42
|
},
|
|
43
43
|
"homepage": "https://github.com/fractal-solutions/qflow#readme",
|
|
44
|
+
"dependencies": {
|
|
45
|
+
"cheerio": "^1.0.0-rc.12"
|
|
46
|
+
},
|
|
44
47
|
"devDependencies": {
|
|
45
48
|
"@types/bun": "latest"
|
|
46
49
|
},
|