node-red-contrib-ai-agent 0.0.3 → 0.0.5

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 CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ## Overview
6
6
 
7
- A powerful AI Agent for Node-RED that enables natural language processing and tool integration. This node allows you to create AI-powered flows with support for function calling and external tool integration.
7
+ A powerful AI Agent for Node-RED that enables natural language processing with memory and tool integration. This package provides nodes for creating AI-powered flows with conversation context management and extensible tool integration.
8
8
 
9
9
  ## ⚠️ Beta Notice
10
10
 
@@ -18,18 +18,23 @@ Your feedback and contributions are highly appreciated!
18
18
 
19
19
  ## Features
20
20
 
21
- - Integration with OpenRouter's AI models
22
- - Support for function calling and tool execution
23
- - Easy configuration through Node-RED's interface
24
- - Conversation context management
25
- - Extensible with custom tools
21
+ - **AI Agent Node**: Process messages with AI, maintaining conversation context
22
+ - **Memory Nodes**:
23
+ - **In-Memory**: Store conversation context in memory (volatile)
24
+ - **File-based**: Persist conversation context to disk
25
+ - **AI Model Node**: Configure AI models and API settings
26
+ - **Tool Integration**: Extend functionality with custom tools
27
+ - **Stateless Design**: Memory nodes are stateless, making them more reliable and scalable
28
+ - **Context Management**: Automatic conversation history management with configurable retention
26
29
 
27
30
  ## Getting Started
28
31
 
29
32
  1. Install the package via the Node-RED palette manager
30
33
  2. Add an AI Model node to configure your OpenRouter API key and model
31
- 3. Add AI Tool nodes to define custom functions
32
- 4. Connect to an AI Agent node to process messages
34
+ 3. (Optional) Add a Memory node (In-Memory or File-based) to manage conversation context
35
+ 4. (Optional) Add AI Tool nodes to define custom functions or HTTP requests
36
+ 5. Connect to an AI Agent node to process messages
37
+ 6. (Optional) Connect more AI Agent nodes to process messages in a chain
33
38
 
34
39
  ## Example: Today's Joke
35
40
 
@@ -43,17 +48,149 @@ When executed, the flow will generate a joke related to the current date:
43
48
 
44
49
  ![Today's Joke Output](https://raw.githubusercontent.com/lesichkovm/node-red-contrib-ai-agent/refs/heads/main/snapshots/todays-joke.png "Example output showing a date-related joke")
45
50
 
46
- ## Basic Usage
51
+ ##
52
+
53
+ ## Node Types
54
+
55
+ ### AI Agent
56
+ Processes messages using the configured AI model and maintains conversation context through connected memory nodes.
57
+
58
+ **Properties:**
59
+ - **Name**: Display name for the node
60
+ - **System Prompt**: Initial instructions for the AI
61
+ - **Response Type**: Format of the response (text or JSON object)
62
+
63
+ ### Memory (In-Memory)
64
+ A configuration node that initializes the conversation context in memory. The agent node uses this configuration to manage the conversation context.
65
+
66
+ **Properties:**
67
+ - **Max Items**: Maximum number of conversation turns to keep in memory
68
+ - **Name**: Display name for the node
69
+
70
+ ### Memory (File)
71
+ A configuration node that initializes the conversation context with file-based persistence. The agent node uses this configuration to manage the conversation context across restarts.
72
+
73
+ **Properties:**
74
+ - **Max Items**: Maximum number of conversation turns to keep
75
+ - **File Path**: Path to store the conversation history
76
+ - **Name**: Display name for the node
77
+
78
+ ### AI Model
79
+ Configures the AI model and API settings.
80
+
81
+ **Properties:**
82
+ - **Model**: The AI model to use (e.g., gpt-4, claude-3-opus)
83
+ - **API Key**: Your OpenRouter API key
84
+ - **Name**: Display name for the node
85
+
86
+ ### AI Tool Function
87
+ Creates a JavaScript function tool that can be used by the AI Agent.
88
+
89
+ **Properties:**
90
+ - **Name**: Display name for the node
91
+ - **Tool Name**: Name of the tool (used by the AI to identify the tool)
92
+ - **Description**: Description of what the tool does
93
+ - **Function**: JavaScript code to execute when the tool is called
94
+
95
+ ### AI Tool HTTP
96
+ Creates an HTTP request tool that can be used by the AI Agent to make external API calls.
97
+
98
+ **Properties:**
99
+ - **Name**: Display name for the node
100
+ - **Tool Name**: Name of the tool (used by the AI to identify the tool)
101
+ - **Description**: Description of what the tool does
102
+ - **Method**: HTTP method (GET, POST, PUT, DELETE, etc.)
103
+ - **URL**: The URL to make the request to (supports template variables)
104
+ - **Headers**: JSON object of headers to include in the request
105
+ - **Body**: Content to send in the request body
106
+
107
+ **Template Variables:**
108
+ You can use template variables in the URL, headers, and body to reference properties from the input object that the AI provides when calling the tool.
109
+
110
+ Example: `https://api.example.com/users/${input.userId}`
111
+
112
+ ## Example: Basic Usage
113
+
114
+ Here's how to use the AI Agent:
115
+
116
+ 1. Add an AI Agent node to your flow
117
+ 2. Configure it with an AI Model node
118
+ 3. (Optional) Add a Memory configuration node if you need conversation context
119
+ 4. Connect your flow: `[Input] --> [AI Model] --> [AI Agent] --> [Output]`
120
+
121
+ Memory is only required if you need to maintain conversation context between messages or chain multiple agents together. For simple, stateless interactions, you can use the AI Agent without any memory configuration.
122
+
123
+ ## Example: Using AI Tools
47
124
 
48
- 1. **AI Model Node**: Configure your AI model and API settings
49
- 2. **AI Tool Node**: Define custom functions and tools
50
- 3. **AI Agent Node**: Process messages with AI and tool integration
125
+ To extend the AI Agent with custom tools:
126
+
127
+ 1. Add an AI Tool Function or AI Tool HTTP node to your flow
128
+ 2. Configure the tool with appropriate settings
129
+ 3. Connect the tool to the AI Agent: `[Input] --> [AI Model] --> [AI Tool] --> [AI Agent] --> [Output]`
130
+
131
+ The AI Agent will automatically detect and use the tools in its processing. You can add multiple tools to give the AI Agent different capabilities.
132
+
133
+ ### HTTP Tool Example
134
+
135
+ ```
136
+ [AI Tool HTTP] --> |
137
+ |--> [AI Agent] --> [Output]
138
+ [AI Tool Function] --> |
139
+ ```
140
+
141
+ In this example, the AI Agent has access to both an HTTP tool for making external API calls and a function tool for custom logic.
142
+
143
+
144
+
145
+ ## Example: Chained Agents
146
+
147
+ For more complex scenarios, you can chain multiple agents to process messages in sequence:
148
+
149
+ 1. Create Memory node (it will init the context, it will be shared between agents)
150
+ 2. Configure Agent 1
151
+ 3. Configure Agent 2
152
+ 4. Connect your flow: `[Input] --> [AI Model] --> [AI Memory] --> [Agent 1] --> [Agent 2] --> [Output]`
153
+
154
+ Each agent will maintain its own conversation context based on its memory configuration.
155
+
156
+ ## Best Practices
157
+
158
+ ### Memory Management
159
+ - Memory nodes are configuration nodes that define how conversation context is managed
160
+ - Each AI Agent node references a memory configuration
161
+ - The memory configuration is instantiated once and can be shared between multiple agents
162
+ - The AI Agent node is responsible for managing and updating the conversation context based on its memory configuration
163
+ - Memory configurations are particularly useful in chained agent scenarios where different agents need different context handling
164
+ - Use **In-Memory** configuration for temporary conversations
165
+ - Use **File-based** configuration for conversations that should persist across restarts
166
+ - Set appropriate `maxItems` to control context length and memory usage
167
+
168
+ ### Error Handling
169
+ - Always handle errors from the AI Agent node
170
+ - Check for API key and model configuration errors
171
+ - Monitor memory usage with large conversation histories
172
+
173
+ ### Performance
174
+ - For high-volume applications, consider using a database-backed memory implementation
175
+ - Be mindful of token usage with large contexts
176
+ - Use appropriate timeouts for API calls
177
+
178
+ ## Advanced: Chaining Agents
179
+
180
+ You can chain multiple AI Agents with different memory scopes to create complex conversation flows:
181
+
182
+ ```
183
+ [Input] -->[Memory 1] --> [Agent 1] --> [Agent 2] --> [Memory 2] --> [Agent 3] --> [Agent 4] --> [Output]
184
+ ```
185
+
186
+ This allows for complex conversation flows where different agents handle different aspects of the interaction.
51
187
 
52
188
  ## Advanced Features
53
189
 
54
- - **Tool Integration**: Extend functionality with custom tools
190
+ - **Tool Integration**: Extend functionality with custom tools (Function and HTTP)
55
191
  - **Context Management**: Maintain conversation history
56
192
  - **Flexible Configuration**: Customize model parameters and behavior
193
+ - **Template Variables**: Use dynamic values in HTTP requests
57
194
 
58
195
  ## Contributing
59
196