@fractal-solutions/qflow 1.0.13 → 1.0.14

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 (2) hide show
  1. package/README.md +76 -0
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -589,6 +589,7 @@ import {
589
589
  UserInputNode,
590
590
  AgentNode,
591
591
  CodeInterpreterNode,
592
+ MemoryNode
592
593
  } from '@fractal-solutions/qflow/nodes';
593
594
 
594
595
  // Ensure your DeepSeek API Key is set as an environment variable
@@ -619,6 +620,7 @@ const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
619
620
  const webScraper = new ScrapeURLNode();
620
621
  const userInput = new UserInputNode(); // Agent can also ask for user input
621
622
  const codeInterpreter = new CodeInterpreterNode(); // Agent can execute code
623
+ const memoryNode = new MemoryNode(); // Agent can store and retrieve memories
622
624
 
623
625
  // Map tool names to their instances
624
626
  const availableTools = {
@@ -630,6 +632,7 @@ const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
630
632
  web_scraper: webScraper,
631
633
  user_input: userInput,
632
634
  code_interpreter: codeInterpreter,
635
+ memory_node: memoryNode,
633
636
  // Add other tools as needed
634
637
  };
635
638
 
@@ -797,13 +800,86 @@ print(f"The sum is: {result}")
797
800
  })();
798
801
  ```
799
802
 
803
+ ### 15. Memory Node (Lightweight RAG)
804
+
805
+ Storing and retrieving text-based memories for lightweight Retrieval-Augmented Generation (RAG).
806
+
807
+ ```javascript
808
+ import { AsyncFlow } from '@fractal-solutions/qflow';
809
+ import { MemoryNode, AgentDeepSeekLLMNode } from '@fractal-solutions/qflow/nodes';
810
+
811
+ const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY;
812
+
813
+ (async () => {
814
+ if (!DEEPSEEK_API_KEY) {
815
+ console.warn("WARNING: DEEPSEEK_API_KEY is not set. Please set it to run the MemoryNode RAG example.");
816
+ return;
817
+ }
818
+
819
+ console.log('--- Running MemoryNode RAG Example ---');
820
+
821
+ // 1. Store a memory
822
+ const storeMemory = new MemoryNode();
823
+ storeMemory.setParams({
824
+ action: 'store',
825
+ content: 'The capital of France is Paris. It is known for the Eiffel Tower.',
826
+ id: 'france_capital'
827
+ });
828
+ await new AsyncFlow(storeMemory).runAsync({});
829
+ console.log('Memory stored.');
830
+
831
+ // 2. Store another memory for RAG
832
+ const storeRagMemory = new MemoryNode();
833
+ storeRagMemory.setParams({
834
+ action: 'store',
835
+ content: 'The primary function of a CPU is to execute instructions that make up a computer program.',
836
+ id: 'cpu_function'
837
+ });
838
+ await new AsyncFlow(storeRagMemory).runAsync({});
839
+ console.log('Another memory stored.');
840
+
841
+ // 3. Retrieve relevant memories based on a query
842
+ const ragRetrieve = new MemoryNode();
843
+ ragRetrieve.setParams({
844
+ action: 'retrieve',
845
+ query: 'computer program'
846
+ });
847
+
848
+ // 4. Use an LLM to answer a question based on retrieved memories
849
+ const ragLLM = new AgentDeepSeekLLMNode();
850
+ ragLLM.setParams({ apiKey: DEEPSEEK_API_KEY });
851
+
852
+ ragRetrieve.next(ragLLM);
853
+
854
+ ragLLM.preparePrompt = (shared) => {
855
+ const retrievedContent = shared.memoryResult.map(mem => mem.content).join('\n\n');
856
+ ragLLM.setParams({
857
+ prompt: `Based on the following context, answer the question:\n\nContext:\n${retrievedContent}\n\nQuestion: What is the main role of a CPU?`
858
+ });
859
+ };
860
+
861
+ const ragFlow = new AsyncFlow(ragRetrieve);
862
+ try {
863
+ const ragResult = await ragFlow.runAsync({});
864
+ console.log('\n--- RAG Example LLM Response ---');
865
+ console.log(ragResult);
866
+ } catch (error) {
867
+ console.error('RAG Flow Failed:', error);
868
+ }
869
+
870
+ console.log('\n--- MemoryNode RAG Example Finished ---');
871
+ })();
872
+ ```
873
+
800
874
  ## Exploring More Examples
801
875
 
876
+
802
877
  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:
803
878
 
804
879
  * **LLMs (DeepSeek, OpenAI, Gemini, Ollama):** The core of agentic behavior.
805
880
  * For agents, use specialized LLM nodes like `AgentDeepSeekLLMNode`, `AgentOpenAILLMNode`, `AgentOllamaLLMNode`.
806
881
  * **Agent:** Orchestrating tools and LLM reasoning to achieve complex goals.
882
+ * **Memory:** For lightweight, keyword-based long-term memory and RAG.
807
883
  * **CodeInterpreter:** For executing dynamic code (e.g., Python) within the workflow.
808
884
  * **Interactive Agent:** An agent that takes a goal from user input and uses its tools to achieve it.
809
885
  * **Shell:** For system-level interaction and execution.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fractal-solutions/qflow",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
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",