@fractal-solutions/qflow 1.0.12 → 1.0.13
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 +187 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -84,6 +84,44 @@ A helper class used in conjunction with `Node.transition()` to define conditiona
|
|
|
84
84
|
|
|
85
85
|
* `to(targetNode)`: Specifies the target node for the transition based on the action returned by the preceding node.
|
|
86
86
|
|
|
87
|
+
|
|
88
|
+
## What Can We Do Now That We Have Agents?
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
The introduction of the `AgentNode` is a game-changer for qflow. It shifts the paradigm from
|
|
92
|
+
pre-defined, static workflows to dynamic, intelligent, and autonomous task execution.
|
|
93
|
+
|
|
94
|
+
Here are some key capabilities and applications unlocked by having agents:
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
1. **Autonomous Goal Achievement:** Agents can now take high-level, open-ended goals (e.g.,
|
|
98
|
+
"Research the best AI frameworks for 2025") and dynamically break them down into
|
|
99
|
+
sub-tasks, selecting and executing the appropriate tools (web search, web scraper, LLM
|
|
100
|
+
for summarization) to achieve the objective.
|
|
101
|
+
2. **Complex Problem Solving:** Agents can tackle multi-step problems that require iterative
|
|
102
|
+
reasoning, external information gathering, and dynamic decision-making based on
|
|
103
|
+
observations. They can adapt their plan as they go.
|
|
104
|
+
3. **Self-Correction and Robustness:** With the **"Reason -> Act -> Observe"** loop, agents can
|
|
105
|
+
identify when a tool fails or produces unexpected results. They can then use their LLM
|
|
106
|
+
reasoning to diagnose the problem and attempt alternative strategies or tools.
|
|
107
|
+
4. **Dynamic Workflow Generation:** Instead of you explicitly defining every step of a workflow,
|
|
108
|
+
the agent generates its own execution path at runtime, choosing tools as needed. This
|
|
109
|
+
makes qflow highly adaptable to unforeseen circumstances.
|
|
110
|
+
5. **Enhanced Automation:** Automate tasks that previously required human intervention, complex
|
|
111
|
+
branching logic, or rigid, brittle scripts. Agents can handle variability and
|
|
112
|
+
uncertainty.
|
|
113
|
+
6. **Interactive Assistants:** Combined with the UserInputNode, agents can become truly
|
|
114
|
+
interactive. They can ask clarifying questions, seek approval for critical actions, or
|
|
115
|
+
provide progress updates, making them more collaborative.
|
|
116
|
+
7. **Data Analysis and Reporting:** Agents can gather data from various sources (web, files,
|
|
117
|
+
APIs), process it (potentially with a future code interpreter), and then synthesize
|
|
118
|
+
findings into structured reports or summaries.
|
|
119
|
+
8. **Research and Information Synthesis:** Agents can research topics, scrape relevant pages,
|
|
120
|
+
and synthesize information into comprehensive answers or documents, acting as automated
|
|
121
|
+
research assistants.
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
87
125
|
## Basic Usage & Examples
|
|
88
126
|
|
|
89
127
|
### 1. Simple Node
|
|
@@ -549,7 +587,8 @@ import {
|
|
|
549
587
|
HttpRequestNode,
|
|
550
588
|
ScrapeURLNode,
|
|
551
589
|
UserInputNode,
|
|
552
|
-
AgentNode
|
|
590
|
+
AgentNode,
|
|
591
|
+
CodeInterpreterNode,
|
|
553
592
|
} from '@fractal-solutions/qflow/nodes';
|
|
554
593
|
|
|
555
594
|
// Ensure your DeepSeek API Key is set as an environment variable
|
|
@@ -579,6 +618,7 @@ const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
|
|
|
579
618
|
const httpRequest = new HttpRequestNode();
|
|
580
619
|
const webScraper = new ScrapeURLNode();
|
|
581
620
|
const userInput = new UserInputNode(); // Agent can also ask for user input
|
|
621
|
+
const codeInterpreter = new CodeInterpreterNode(); // Agent can execute code
|
|
582
622
|
|
|
583
623
|
// Map tool names to their instances
|
|
584
624
|
const availableTools = {
|
|
@@ -589,6 +629,7 @@ const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
|
|
|
589
629
|
http_request: httpRequest,
|
|
590
630
|
web_scraper: webScraper,
|
|
591
631
|
user_input: userInput,
|
|
632
|
+
code_interpreter: codeInterpreter,
|
|
592
633
|
// Add other tools as needed
|
|
593
634
|
};
|
|
594
635
|
|
|
@@ -615,14 +656,155 @@ const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
|
|
|
615
656
|
})();
|
|
616
657
|
```
|
|
617
658
|
|
|
659
|
+
### 13. Data Extraction Example
|
|
660
|
+
|
|
661
|
+
Extracting structured data from HTML, JSON, or plain text.
|
|
662
|
+
|
|
663
|
+
```javascript
|
|
664
|
+
import { AsyncFlow } from '@fractal-solutions/qflow';
|
|
665
|
+
import { DataExtractorNode, WebScraperNode } from '@fractal-solutions/qflow/nodes';
|
|
666
|
+
|
|
667
|
+
(async () => {
|
|
668
|
+
console.log('--- Running DataExtractorNode Test Workflow ---');
|
|
669
|
+
|
|
670
|
+
// Example 1: Extracting from HTML (using WebScraperNode to get HTML)
|
|
671
|
+
console.log('\n--- HTML Extraction Example ---');
|
|
672
|
+
const scrapeNode = new WebScraperNode();
|
|
673
|
+
scrapeNode.setParams({ url: 'https://www.example.com' });
|
|
674
|
+
|
|
675
|
+
const extractHtmlNode = new DataExtractorNode();
|
|
676
|
+
extractHtmlNode.setParams({
|
|
677
|
+
type: 'html',
|
|
678
|
+
selector: 'h1' // Extract the text from the first h1 tag
|
|
679
|
+
});
|
|
680
|
+
|
|
681
|
+
scrapeNode.next(extractHtmlNode);
|
|
682
|
+
|
|
683
|
+
extractHtmlNode.postAsync = async (shared, prepRes, execRes) => {
|
|
684
|
+
console.log('Extracted HTML (h1 content):', execRes);
|
|
685
|
+
return 'default';
|
|
686
|
+
};
|
|
687
|
+
|
|
688
|
+
const htmlFlow = new AsyncFlow(scrapeNode);
|
|
689
|
+
try {
|
|
690
|
+
await htmlFlow.runAsync({});
|
|
691
|
+
} catch (error) {
|
|
692
|
+
console.error('HTML Extraction Flow Failed:', error);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// Example 2: Extracting from JSON
|
|
696
|
+
console.log('\n--- JSON Extraction Example ---');
|
|
697
|
+
const jsonContent = JSON.stringify({
|
|
698
|
+
user: {
|
|
699
|
+
id: 123,
|
|
700
|
+
name: 'John Doe',
|
|
701
|
+
contact: {
|
|
702
|
+
email: 'john.doe@example.com',
|
|
703
|
+
phone: '123-456-7890'
|
|
704
|
+
},
|
|
705
|
+
roles: ['admin', 'editor']
|
|
706
|
+
},
|
|
707
|
+
products: [
|
|
708
|
+
{ id: 1, name: 'Laptop', price: 1200 },
|
|
709
|
+
{ id: 2, name: 'Mouse', price: 25 }
|
|
710
|
+
]
|
|
711
|
+
}, null, 2);
|
|
712
|
+
|
|
713
|
+
const extractJsonNode = new DataExtractorNode();
|
|
714
|
+
extractJsonNode.setParams({
|
|
715
|
+
input: jsonContent,
|
|
716
|
+
type: 'json',
|
|
717
|
+
jsonPath: 'user.contact.email' // Extract email from nested JSON
|
|
718
|
+
});
|
|
719
|
+
|
|
720
|
+
extractJsonNode.postAsync = async (shared, prepRes, execRes) => {
|
|
721
|
+
console.log('Extracted JSON (user email):', execRes);
|
|
722
|
+
return 'default';
|
|
723
|
+
};
|
|
724
|
+
|
|
725
|
+
const jsonFlow = new AsyncFlow(extractJsonNode);
|
|
726
|
+
try {
|
|
727
|
+
await jsonFlow.runAsync({});
|
|
728
|
+
} catch (error) {
|
|
729
|
+
console.error('JSON Extraction Flow Failed:', error);
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
// Example 3: Extracting from Text (Regex)
|
|
733
|
+
console.log('\n--- Text Extraction Example (Regex) ---');
|
|
734
|
+
const textContent = "User IDs: user_123, user_456, admin_789. Emails: test@example.com, another@domain.org.";
|
|
735
|
+
|
|
736
|
+
const extractTextNode = new DataExtractorNode();
|
|
737
|
+
extractTextNode.setParams({
|
|
738
|
+
input: textContent,
|
|
739
|
+
type: 'text',
|
|
740
|
+
regex: 'user_(\\d+)', // Extract numbers after 'user_'
|
|
741
|
+
group: 1 // Capture group 1
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
extractTextNode.postAsync = async (shared, prepRes, execRes) => {
|
|
745
|
+
console.log('Extracted Text (User IDs):', execRes);
|
|
746
|
+
return 'default';
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
const textFlow = new AsyncFlow(extractTextNode);
|
|
750
|
+
try {
|
|
751
|
+
await textFlow.runAsync({});
|
|
752
|
+
} catch (error) {
|
|
753
|
+
console.error('Text Extraction Flow Failed:', error);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
console.log('\n--- DataExtractorNode Test Workflow Finished ---');
|
|
757
|
+
})();
|
|
758
|
+
|
|
759
|
+
```
|
|
760
|
+
|
|
761
|
+
### 14. Code Interpreter Example
|
|
762
|
+
|
|
763
|
+
Executing Python code within the workflow.
|
|
764
|
+
|
|
765
|
+
```javascript
|
|
766
|
+
import { AsyncFlow } from '@fractal-solutions/qflow';
|
|
767
|
+
import { CodeInterpreterNode } from '@fractal-solutions/qflow/nodes';
|
|
768
|
+
|
|
769
|
+
(async () => {
|
|
770
|
+
const pythonCode = `
|
|
771
|
+
print("Hello from the Code Interpreter!")
|
|
772
|
+
result = 10 + 20
|
|
773
|
+
print(f"The sum is: {result}")
|
|
774
|
+
`;
|
|
775
|
+
|
|
776
|
+
const codeInterpreter = new CodeInterpreterNode();
|
|
777
|
+
codeInterpreter.setParams({
|
|
778
|
+
code: pythonCode,
|
|
779
|
+
timeout: 5000, // Max 5 seconds for execution
|
|
780
|
+
requireConfirmation: false // Set to false to bypass user confirmation
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
codeInterpreter.postAsync = async (shared, prepRes, execRes) => {
|
|
784
|
+
console.log('--- Code Interpreter Output ---');
|
|
785
|
+
console.log('Stdout:', execRes.stdout);
|
|
786
|
+
console.log('Stderr:', execRes.stderr);
|
|
787
|
+
console.log('Exit Code:', execRes.exitCode);
|
|
788
|
+
return 'default';
|
|
789
|
+
};
|
|
790
|
+
|
|
791
|
+
const flow = new AsyncFlow(codeInterpreter);
|
|
792
|
+
try {
|
|
793
|
+
await flow.runAsync({});
|
|
794
|
+
} catch (error) {
|
|
795
|
+
console.error('Code Interpreter Flow Failed:', error);
|
|
796
|
+
}
|
|
797
|
+
})();
|
|
798
|
+
```
|
|
618
799
|
|
|
619
800
|
## Exploring More Examples
|
|
620
801
|
|
|
621
802
|
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:
|
|
622
803
|
|
|
623
|
-
* **LLMs (DeepSeek, OpenAI, Gemini):** The core of agentic behavior.
|
|
624
|
-
* For agents, use specialized LLM nodes like `AgentDeepSeekLLMNode`
|
|
804
|
+
* **LLMs (DeepSeek, OpenAI, Gemini, Ollama):** The core of agentic behavior.
|
|
805
|
+
* For agents, use specialized LLM nodes like `AgentDeepSeekLLMNode`, `AgentOpenAILLMNode`, `AgentOllamaLLMNode`.
|
|
625
806
|
* **Agent:** Orchestrating tools and LLM reasoning to achieve complex goals.
|
|
807
|
+
* **CodeInterpreter:** For executing dynamic code (e.g., Python) within the workflow.
|
|
626
808
|
* **Interactive Agent:** An agent that takes a goal from user input and uses its tools to achieve it.
|
|
627
809
|
* **Shell:** For system-level interaction and execution.
|
|
628
810
|
* **HTTP:** For universal API access.
|
|
@@ -631,7 +813,8 @@ The examples above cover the core functionalities of `qflow`. For more advanced
|
|
|
631
813
|
* **Web Search:** Discovering information on the web using either:
|
|
632
814
|
* `DuckDuckGoSearchNode`: API-key-free, using DuckDuckGo's HTML interface.
|
|
633
815
|
* `GoogleSearchNode`: Requires a Google API Key and Custom Search Engine ID for more robust results.
|
|
634
|
-
* **WebScraper:** For targeted
|
|
816
|
+
* **WebScraper:** For targeted web scraping.
|
|
817
|
+
* **DataExtractor:** For targeted data extraction.
|
|
635
818
|
* **GitHub:** Creating and managing issues.
|
|
636
819
|
* **HackerNews:** Fetching top stories and item details.
|
|
637
820
|
* **Stripe:** Creating charges and retrieving account balances.
|
package/package.json
CHANGED