@ai.ntellect/core 0.1.81 → 0.1.83
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.FR.md +31 -60
- package/README.md +74 -96
- package/agent/handlers/ActionHandler.ts +1 -1
- package/agent/index.ts +49 -34
- package/dist/agent/index.d.ts +0 -1
- package/dist/agent/index.js +34 -25
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/llm/orchestrator/context.js +1 -1
- package/dist/llm/orchestrator/index.js +28 -4
- package/dist/memory/cache.d.ts +4 -4
- package/dist/memory/cache.js +23 -20
- package/dist/memory/persistent.js +3 -4
- package/dist/services/queue.js +21 -8
- package/dist/t.d.ts +46 -0
- package/dist/t.js +102 -0
- package/dist/test.d.ts +40 -0
- package/dist/test.js +135 -0
- package/dist/types.d.ts +2 -3
- package/dist/utils/inject-actions.js +1 -1
- package/index.ts +0 -1
- package/llm/orchestrator/context.ts +1 -1
- package/llm/orchestrator/index.ts +45 -8
- package/memory/cache.ts +26 -26
- package/memory/persistent.ts +5 -4
- package/package.json +3 -1
- package/services/queue.ts +21 -12
- package/t.ts +133 -0
- package/types.ts +2 -3
- package/utils/inject-actions.ts +1 -1
    
        package/README.FR.md
    CHANGED
    
    | @@ -230,79 +230,50 @@ export const prepareTransaction = { | |
| 230 230 |  | 
| 231 231 | 
             
            ## 3. Exécution du workflow
         | 
| 232 232 |  | 
| 233 | 
            -
             | 
| 234 | 
            -
             | 
| 235 | 
            -
            ### Exemple de création d'un workflow :
         | 
| 233 | 
            +
            L'agent gère l'ensemble du processus de compréhension des requêtes utilisateur et de coordination des réponses. Voici un exemple d'utilisation de l'agent :
         | 
| 236 234 |  | 
| 237 235 | 
             
            ```typescript
         | 
| 238 | 
            -
            const  | 
| 239 | 
            -
               | 
| 240 | 
            -
               | 
| 241 | 
            -
             | 
| 242 | 
            -
             | 
| 243 | 
            -
            const orchestrator = new Orchestrator(tools);
         | 
| 236 | 
            +
            const memory = new PersistentMemory({
         | 
| 237 | 
            +
              host: "http://localhost:7700",
         | 
| 238 | 
            +
              apiKey: "VOTRE_CLE_API",
         | 
| 239 | 
            +
            });
         | 
| 244 240 |  | 
| 245 | 
            -
            const  | 
| 246 | 
            -
               | 
| 247 | 
            -
             | 
| 241 | 
            +
            const orchestrator = new Orchestrator(
         | 
| 242 | 
            +
              [
         | 
| 243 | 
            +
                getChainsTVL,
         | 
| 244 | 
            +
                getRssNews,
         | 
| 245 | 
            +
                // autres outils...
         | 
| 246 | 
            +
              ],
         | 
| 247 | 
            +
              memory
         | 
| 248 248 | 
             
            );
         | 
| 249 | 
            -
            ```
         | 
| 250 | 
            -
             | 
| 251 | 
            -
            - **Orchestrator** : Gestion de l'ordre des actions.
         | 
| 252 | 
            -
            - **MemoryCache** : Réutilisation des résultats précédents.
         | 
| 253 | 
            -
            - **EventEmitter** : Suivi et notification de l'état du workflow.
         | 
| 254 | 
            -
             | 
| 255 | 
            -
            ### Processus du workflow :
         | 
| 256 | 
            -
             | 
| 257 | 
            -
            1. Le prompt utilisateur est analysé.
         | 
| 258 | 
            -
            2. L'orchestrateur décide des actions nécessaires et leur ordre.
         | 
| 259 | 
            -
            3. Les actions sont exécutées.
         | 
| 260 | 
            -
            4. Les résultats sont synthétisés et renvoyés à l'utilisateur.
         | 
| 261 249 |  | 
| 262 | 
            -
             | 
| 263 | 
            -
             | 
| 264 | 
            -
             | 
| 250 | 
            +
            const agent = new Agent({
         | 
| 251 | 
            +
              user: { id: "user_id" },
         | 
| 252 | 
            +
              orchestrator,
         | 
| 253 | 
            +
              persistentMemory: memory,
         | 
| 254 | 
            +
              stream: false,
         | 
| 255 | 
            +
              maxEvaluatorIteration: 1,
         | 
| 256 | 
            +
            });
         | 
| 265 257 |  | 
| 266 | 
            -
             | 
| 267 | 
            -
             | 
| 268 | 
            -
               | 
| 269 | 
            -
             | 
| 270 | 
            -
                const { messages, from } = request.body;
         | 
| 271 | 
            -
                const latestMessage = messages[messages.length - 1];
         | 
| 272 | 
            -
             | 
| 273 | 
            -
                const workflow = new Workflow(
         | 
| 274 | 
            -
                  { id: from },
         | 
| 275 | 
            -
                  { orchestrator, memoryCache, eventEmitter }
         | 
| 276 | 
            -
                );
         | 
| 277 | 
            -
                return workflow.start(latestMessage.content, messages);
         | 
| 258 | 
            +
            // Traitement d'une requête utilisateur
         | 
| 259 | 
            +
            const result = await agent.process(prompt, context, {
         | 
| 260 | 
            +
              onMessage: (message) => {
         | 
| 261 | 
            +
                console.log({ message });
         | 
| 278 262 | 
             
              },
         | 
| 279 263 | 
             
            });
         | 
| 280 264 | 
             
            ```
         | 
| 281 265 |  | 
| 282 | 
            -
             | 
| 283 | 
            -
             | 
| 284 | 
            -
             | 
| 285 | 
            -
             | 
| 286 | 
            -
             | 
| 287 | 
            -
             | 
| 288 | 
            -
             | 
| 289 | 
            -
              return (
         | 
| 290 | 
            -
                <div>
         | 
| 291 | 
            -
                  <div>{messages}</div>
         | 
| 292 | 
            -
                  <input
         | 
| 293 | 
            -
                    type="text"
         | 
| 294 | 
            -
                    value={input}
         | 
| 295 | 
            -
                    onChange={(e) => setInput(e.target.value)}
         | 
| 296 | 
            -
                  />
         | 
| 297 | 
            -
                  <button onClick={handleSubmit}>Envoyer</button>
         | 
| 298 | 
            -
                </div>
         | 
| 299 | 
            -
              );
         | 
| 300 | 
            -
            }
         | 
| 301 | 
            -
            ```
         | 
| 266 | 
            +
            ### Flux de traitement de l'agent :
         | 
| 267 | 
            +
             | 
| 268 | 
            +
            1. L'utilisateur envoie un prompt
         | 
| 269 | 
            +
            2. L'agent analyse le prompt et le contexte
         | 
| 270 | 
            +
            3. L'orchestrateur exécute les outils/actions nécessaires
         | 
| 271 | 
            +
            4. L'évaluateur évalue les résultats
         | 
| 272 | 
            +
            5. L'agent génère la réponse finale
         | 
| 302 273 |  | 
| 303 274 | 
             
            ---
         | 
| 304 275 |  | 
| 305 | 
            -
            ##  | 
| 276 | 
            +
            ## 4. WIP (Work in Progress)
         | 
| 306 277 |  | 
| 307 278 | 
             
            Voici les éléments actuellement en développement ou à améliorer :
         | 
| 308 279 |  | 
    
        package/README.md
    CHANGED
    
    | @@ -1,50 +1,51 @@ | |
| 1 1 | 
             
            # AI.ntellect Core Framework
         | 
| 2 2 |  | 
| 3 | 
            -
            ## Table of  | 
| 3 | 
            +
            ## Table of contents
         | 
| 4 4 |  | 
| 5 | 
            -
            1. [Main  | 
| 5 | 
            +
            1. [Main components](#main-components)
         | 
| 6 | 
            +
               - [Agent](#agent)
         | 
| 6 7 | 
             
               - [Orchestrator](#orchestrator)
         | 
| 7 | 
            -
               - [Queue Manager](#queue-manager)
         | 
| 8 8 | 
             
               - [Synthesizer](#synthesizer)
         | 
| 9 9 | 
             
               - [Evaluator](#evaluator)
         | 
| 10 10 | 
             
               - [Memory](#memory-architecture)
         | 
| 11 | 
            -
            2. [Action  | 
| 12 | 
            -
            3. [ | 
| 13 | 
            -
            4. [ | 
| 14 | 
            -
            5. [WIP (Work in Progress)](#wip-work-in-progress)
         | 
| 11 | 
            +
            2. [Action creation and management](#action-creation-and-management)
         | 
| 12 | 
            +
            3. [Agent processing](#agent-processing)
         | 
| 13 | 
            +
            4. [WIP (Work in Progress)](#wip-work-in-progress)
         | 
| 15 14 |  | 
| 16 15 | 
             
            ---
         | 
| 17 16 |  | 
| 18 17 | 
             
            ## 1. Main components
         | 
| 19 18 |  | 
| 20 | 
            -
            The system relies on several key components that ensure smooth and efficient  | 
| 19 | 
            +
            The system relies on several key components that ensure smooth and efficient processing of user requests through an AI agent architecture.
         | 
| 21 20 |  | 
| 22 | 
            -
            ###  | 
| 21 | 
            +
            ### Agent
         | 
| 23 22 |  | 
| 24 | 
            -
            The  | 
| 23 | 
            +
            The agent is the core component that processes user requests and manages the entire interaction flow. It coordinates with other components to understand user needs, execute appropriate actions, and generate relevant responses.
         | 
| 25 24 |  | 
| 26 | 
            -
            - **Main  | 
| 27 | 
            -
            - ** | 
| 28 | 
            -
              -  | 
| 29 | 
            -
              -  | 
| 30 | 
            -
              -  | 
| 31 | 
            -
              -  | 
| 25 | 
            +
            - **Main role**: Process user requests and coordinate system components
         | 
| 26 | 
            +
            - **Key features**:
         | 
| 27 | 
            +
              - Processes user prompts
         | 
| 28 | 
            +
              - Manages conversation context
         | 
| 29 | 
            +
              - Coordinates with orchestrator for action execution
         | 
| 30 | 
            +
              - Handles response generation
         | 
| 31 | 
            +
              - Maintains user state and memory
         | 
| 32 32 |  | 
| 33 | 
            -
            ###  | 
| 33 | 
            +
            ### Orchestrator
         | 
| 34 34 |  | 
| 35 | 
            -
            The  | 
| 35 | 
            +
            The orchestrator works under the agent's direction to manage the execution of actions. It analyzes requirements based on the agent's interpretation of user needs and coordinates the execution of appropriate tools.
         | 
| 36 36 |  | 
| 37 | 
            -
            - **Main  | 
| 38 | 
            -
            - ** | 
| 39 | 
            -
              -  | 
| 40 | 
            -
              -  | 
| 41 | 
            -
              -  | 
| 37 | 
            +
            - **Main role**: Organize and direct the execution of actions
         | 
| 38 | 
            +
            - **Interactions**:
         | 
| 39 | 
            +
              - Manages available tools/actions
         | 
| 40 | 
            +
              - Executes actions based on agent requests
         | 
| 41 | 
            +
              - Uses memory for context and caching
         | 
| 42 | 
            +
              - Coordinates with evaluator for result assessment
         | 
| 42 43 |  | 
| 43 44 | 
             
            ### Synthesizer
         | 
| 44 45 |  | 
| 45 46 | 
             
            The synthesizer is responsible for generating responses and analyzing actions based on the results obtained in the workflow. It can create summaries or more complex responses from the raw results obtained during the execution of actions.
         | 
| 46 47 |  | 
| 47 | 
            -
            - **Main  | 
| 48 | 
            +
            - **Main role**: Transform the results of actions into a comprehensible and structured output
         | 
| 48 49 | 
             
            - **Interactions**:
         | 
| 49 50 | 
             
              - Takes the results of executed actions
         | 
| 50 51 | 
             
              - Creates summaries or tailored responses
         | 
| @@ -55,8 +56,8 @@ The synthesizer is responsible for generating responses and analyzing actions ba | |
| 55 56 |  | 
| 56 57 | 
             
            The evaluator is responsible for assessing the results of executed actions and determining if additional actions are needed. It works in conjunction with the orchestrator to ensure all user requirements are met.
         | 
| 57 58 |  | 
| 58 | 
            -
            - **Main  | 
| 59 | 
            -
            - **Main  | 
| 59 | 
            +
            - **Main role**: Evaluate action results and determine next steps
         | 
| 60 | 
            +
            - **Main functions**:
         | 
| 60 61 | 
             
              - Analyzes results from executed actions
         | 
| 61 62 | 
             
              - Determines if additional actions are needed
         | 
| 62 63 | 
             
              - Suggests next actions to the orchestrator
         | 
| @@ -139,7 +140,7 @@ sudo apt-get install redis-server | |
| 139 140 |  | 
| 140 141 | 
             
            CAG optimizes workflow execution through Redis-based caching:
         | 
| 141 142 |  | 
| 142 | 
            -
            - **Main  | 
| 143 | 
            +
            - **Main role**: Cache frequently used procedural patterns
         | 
| 143 144 | 
             
            - **Implementation**:
         | 
| 144 145 |  | 
| 145 146 | 
             
              - Uses Redis for high-performance storage
         | 
| @@ -229,81 +230,50 @@ export const prepareTransaction = { | |
| 229 230 |  | 
| 230 231 | 
             
            ---
         | 
| 231 232 |  | 
| 232 | 
            -
            ## 3.  | 
| 233 | 
            -
             | 
| 234 | 
            -
            The workflow represents the entire process of executing a number of defined actions. When a user sends a prompt, the orchestrator determines which actions to perform based on the needs.
         | 
| 233 | 
            +
            ## 3. Agent processing
         | 
| 235 234 |  | 
| 236 | 
            -
             | 
| 235 | 
            +
            The agent handles the entire process of understanding user requests and coordinating responses. Here's an example of how to use the agent:
         | 
| 237 236 |  | 
| 238 237 | 
             
            ```typescript
         | 
| 239 | 
            -
            const  | 
| 240 | 
            -
               | 
| 241 | 
            -
               | 
| 242 | 
            -
             | 
| 243 | 
            -
             | 
| 244 | 
            -
            const orchestrator = new Orchestrator(tools);
         | 
| 238 | 
            +
            const memory = new PersistentMemory({
         | 
| 239 | 
            +
              host: "http://localhost:7700",
         | 
| 240 | 
            +
              apiKey: "YOUR_API_KEY",
         | 
| 241 | 
            +
            });
         | 
| 245 242 |  | 
| 246 | 
            -
            const  | 
| 247 | 
            -
               | 
| 248 | 
            -
             | 
| 243 | 
            +
            const orchestrator = new Orchestrator(
         | 
| 244 | 
            +
              [
         | 
| 245 | 
            +
                getChainsTVL,
         | 
| 246 | 
            +
                getRssNews,
         | 
| 247 | 
            +
                // other tools...
         | 
| 248 | 
            +
              ],
         | 
| 249 | 
            +
              memory
         | 
| 249 250 | 
             
            );
         | 
| 250 | 
            -
            ```
         | 
| 251 | 
            -
             | 
| 252 | 
            -
            - **Orchestrator**: Manages the order of actions.
         | 
| 253 | 
            -
            - **MemoryCache**: Reuses previous results.
         | 
| 254 | 
            -
            - **EventEmitter**: Tracks and notifies the state of the workflow.
         | 
| 255 | 
            -
             | 
| 256 | 
            -
            ### Workflow process:
         | 
| 257 251 |  | 
| 258 | 
            -
             | 
| 259 | 
            -
             | 
| 260 | 
            -
             | 
| 261 | 
            -
             | 
| 262 | 
            -
             | 
| 263 | 
            -
             | 
| 264 | 
            -
             | 
| 265 | 
            -
            ## 4. API calls and client side
         | 
| 252 | 
            +
            const agent = new Agent({
         | 
| 253 | 
            +
              user: { id: "user_id" },
         | 
| 254 | 
            +
              orchestrator,
         | 
| 255 | 
            +
              persistentMemory: memory,
         | 
| 256 | 
            +
              stream: false,
         | 
| 257 | 
            +
              maxEvaluatorIteration: 1,
         | 
| 258 | 
            +
            });
         | 
| 266 259 |  | 
| 267 | 
            -
             | 
| 268 | 
            -
             | 
| 269 | 
            -
               | 
| 270 | 
            -
             | 
| 271 | 
            -
                const { messages, from } = request.body;
         | 
| 272 | 
            -
                const latestMessage = messages[messages.length - 1];
         | 
| 273 | 
            -
             | 
| 274 | 
            -
                const workflow = new Workflow(
         | 
| 275 | 
            -
                  { id: from },
         | 
| 276 | 
            -
                  { orchestrator, memoryCache, eventEmitter }
         | 
| 277 | 
            -
                );
         | 
| 278 | 
            -
                return workflow.start(latestMessage.content, messages);
         | 
| 260 | 
            +
            // Process a user request
         | 
| 261 | 
            +
            const result = await agent.process(prompt, context, {
         | 
| 262 | 
            +
              onMessage: (message) => {
         | 
| 263 | 
            +
                console.log({ message });
         | 
| 279 264 | 
             
              },
         | 
| 280 265 | 
             
            });
         | 
| 281 266 | 
             
            ```
         | 
| 282 267 |  | 
| 283 | 
            -
             | 
| 284 | 
            -
            export function Chat({ id, initialMessages }) {
         | 
| 285 | 
            -
              const { messages, setMessages, handleSubmit, input, setInput } = useChat({
         | 
| 286 | 
            -
                api: "/api/chat",
         | 
| 287 | 
            -
                body: { id, from: activeAccount?.address },
         | 
| 288 | 
            -
              });
         | 
| 289 | 
            -
             | 
| 290 | 
            -
              return (
         | 
| 291 | 
            -
                <div>
         | 
| 292 | 
            -
                  <div>{messages}</div>
         | 
| 293 | 
            -
                  <input
         | 
| 294 | 
            -
                    type="text"
         | 
| 295 | 
            -
                    value={input}
         | 
| 296 | 
            -
                    onChange={(e) => setInput(e.target.value)}
         | 
| 297 | 
            -
                  />
         | 
| 298 | 
            -
                  <button onClick={handleSubmit}>Send</button>
         | 
| 299 | 
            -
                </div>
         | 
| 300 | 
            -
              );
         | 
| 301 | 
            -
            }
         | 
| 302 | 
            -
            ```
         | 
| 268 | 
            +
            ### Agent process flow:
         | 
| 303 269 |  | 
| 304 | 
            -
             | 
| 270 | 
            +
            1. User sends a prompt
         | 
| 271 | 
            +
            2. Agent analyzes the prompt and context
         | 
| 272 | 
            +
            3. Orchestrator executes required tools/actions
         | 
| 273 | 
            +
            4. Evaluator assesses results
         | 
| 274 | 
            +
            5. Agent generates final response
         | 
| 305 275 |  | 
| 306 | 
            -
            ##  | 
| 276 | 
            +
            ## 4. WIP (Work in Progress)
         | 
| 307 277 |  | 
| 308 278 | 
             
            Here are the elements currently in development or improvement:
         | 
| 309 279 |  | 
| @@ -313,9 +283,10 @@ Here are the elements currently in development or improvement: | |
| 313 283 |  | 
| 314 284 | 
             
            **Objective**: Enable multiple agents to collaborate on complex tasks with specialization and coordination.
         | 
| 315 285 |  | 
| 316 | 
            -
            **Interest**: Collaboration between agents allows breaking down complex tasks into specialized subtasks, enhancing the | 
| 286 | 
            +
            **Interest**: Collaboration between agents allows breaking down complex tasks into specialized subtasks, enhancing the
         | 
| 287 | 
            +
            efficiency and quality of results. It also enables better resource management and faster adaptation to changes.
         | 
| 317 288 |  | 
| 318 | 
            -
            **Steps to  | 
| 289 | 
            +
            **Steps to implement**:
         | 
| 319 290 |  | 
| 320 291 | 
             
            - [ ] Task delegation framework.
         | 
| 321 292 | 
             
            - [ ] Shared context management.
         | 
| @@ -329,9 +300,11 @@ Here are the elements currently in development or improvement: | |
| 329 300 |  | 
| 330 301 | 
             
            **Objective**: Create a model for recognizing on-chain interactions and creating workflows for complex interactions.
         | 
| 331 302 |  | 
| 332 | 
            -
            **Interest**: This feature allows the agent to understand and interact with smart contracts more intuitively, | 
| 303 | 
            +
            **Interest**: This feature allows the agent to understand and interact with smart contracts more intuitively,
         | 
| 304 | 
            +
            facilitating the execution of complex actions on the blockchain. It improves accessibility and efficiency in
         | 
| 305 | 
            +
            interacting with smart contracts.
         | 
| 333 306 |  | 
| 334 | 
            -
            **Steps to  | 
| 307 | 
            +
            **Steps to implement**:
         | 
| 335 308 |  | 
| 336 309 | 
             
            - [ ] Extraction and processing of relevant contract ABIs.
         | 
| 337 310 | 
             
            - [ ] Filtering of relevant functions.
         | 
| @@ -347,9 +320,13 @@ Here are the elements currently in development or improvement: | |
| 347 320 |  | 
| 348 321 | 
             
            ## Lit Protocol implementation
         | 
| 349 322 |  | 
| 350 | 
            -
            **Objective**: Add the ability to execute Lit actions, enabling decentralized and secure calculations on the Lit | 
| 323 | 
            +
            **Objective**: Add the ability to execute Lit actions, enabling decentralized and secure calculations on the Lit
         | 
| 324 | 
            +
            network.
         | 
| 351 325 |  | 
| 352 | 
            -
            **Interest**: Integrating the Lit Protocol allows executing Lit actions in a decentralized manner, using cryptographic | 
| 326 | 
            +
            **Interest**: Integrating the Lit Protocol allows executing Lit actions in a decentralized manner, using cryptographic
         | 
| 327 | 
            +
            keys to validate operations. These actions can be used to run JavaScript scripts in a decentralized environment,
         | 
| 328 | 
            +
            offering transparency as all interactions are recorded on the blockchain. The main benefit lies in automation and
         | 
| 329 | 
            +
            security while preserving user privacy, which enhances trust in on-chain interactions.
         | 
| 353 330 |  | 
| 354 331 | 
             
            **Steps to Implement**:
         | 
| 355 332 |  | 
| @@ -358,4 +335,5 @@ Here are the elements currently in development or improvement: | |
| 358 335 | 
             
            - [ ] Develop modules for executing Lit actions, including signature management and secure script execution.
         | 
| 359 336 | 
             
            - [ ] Test the integration, security, and transparency of Lit actions to ensure they function properly.
         | 
| 360 337 |  | 
| 361 | 
            -
            **Status**: Under study to determine feasibility and technical implications, particularly regarding integrating | 
| 338 | 
            +
            **Status**: Under study to determine feasibility and technical implications, particularly regarding integrating
         | 
| 339 | 
            +
            decentralization into the existing system.
         | 
| @@ -17,7 +17,7 @@ export class ActionHandler { | |
| 17 17 | 
             
                    onActionStart: callbacks?.onActionStart,
         | 
| 18 18 | 
             
                    onActionComplete: callbacks?.onActionComplete,
         | 
| 19 19 | 
             
                    onQueueComplete: callbacks?.onQueueComplete,
         | 
| 20 | 
            -
                    onConfirmationRequired: async (message) => {
         | 
| 20 | 
            +
                    onConfirmationRequired: async (message: any) => {
         | 
| 21 21 | 
             
                      if (callbacks?.onConfirmationRequired) {
         | 
| 22 22 | 
             
                        return await callbacks.onConfirmationRequired(message);
         | 
| 23 23 | 
             
                      }
         | 
    
        package/agent/index.ts
    CHANGED
    
    | @@ -3,7 +3,13 @@ import { Orchestrator } from "../llm/orchestrator"; | |
| 3 3 | 
             
            import { Synthesizer } from "../llm/synthesizer";
         | 
| 4 4 | 
             
            import { CacheMemory } from "../memory/cache";
         | 
| 5 5 | 
             
            import { PersistentMemory } from "../memory/persistent";
         | 
| 6 | 
            -
            import { | 
| 6 | 
            +
            import {
         | 
| 7 | 
            +
              ActionSchema,
         | 
| 8 | 
            +
              AgentEvent,
         | 
| 9 | 
            +
              MemoryScope,
         | 
| 10 | 
            +
              MemoryType,
         | 
| 11 | 
            +
              User,
         | 
| 12 | 
            +
            } from "../types";
         | 
| 7 13 | 
             
            import { QueueItemTransformer } from "../utils/queue-item-transformer";
         | 
| 8 14 | 
             
            import { ActionHandler } from "./handlers/ActionHandler";
         | 
| 9 15 |  | 
| @@ -48,20 +54,40 @@ export class Agent { | |
| 48 54 | 
             
                contextualizedPrompt: string,
         | 
| 49 55 | 
             
                events: AgentEvent
         | 
| 50 56 | 
             
              ): Promise<any> {
         | 
| 51 | 
            -
                 | 
| 52 | 
            -
             | 
| 53 | 
            -
                 | 
| 57 | 
            +
                let actions: ActionSchema[] = [];
         | 
| 58 | 
            +
             | 
| 59 | 
            +
                if (this.cacheMemory) {
         | 
| 60 | 
            +
                  const similarActions = await this.cacheMemory.findSimilarQueries(prompt, {
         | 
| 61 | 
            +
                    similarityThreshold: this.SIMILARITY_THRESHOLD,
         | 
| 62 | 
            +
                    maxResults: this.MAX_RESULTS,
         | 
| 63 | 
            +
                    userId: this.user.id,
         | 
| 64 | 
            +
                    scope: MemoryScope.GLOBAL,
         | 
| 65 | 
            +
                  });
         | 
| 66 | 
            +
                  if (similarActions.length > 0) {
         | 
| 67 | 
            +
                    actions = similarActions[0].data;
         | 
| 68 | 
            +
                    console.log("Similar actions found for query: ", prompt);
         | 
| 69 | 
            +
                    console.dir(actions, { depth: null });
         | 
| 70 | 
            +
                  }
         | 
| 71 | 
            +
                }
         | 
| 54 72 |  | 
| 55 | 
            -
                if ( | 
| 56 | 
            -
                   | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
                    },
         | 
| 62 | 
            -
                    events
         | 
| 63 | 
            -
                  );
         | 
| 73 | 
            +
                if (!actions.length) {
         | 
| 74 | 
            +
                  console.log("No similar actions found for query: ", prompt);
         | 
| 75 | 
            +
                  console.log("Requesting orchestrator for actions");
         | 
| 76 | 
            +
                  const request = await this.orchestrator.process(contextualizedPrompt);
         | 
| 77 | 
            +
                  events.onMessage?.(request);
         | 
| 78 | 
            +
                  actions = request.actions;
         | 
| 64 79 | 
             
                }
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                return actions.length > 0
         | 
| 82 | 
            +
                  ? this.handleActions(
         | 
| 83 | 
            +
                      {
         | 
| 84 | 
            +
                        initialPrompt: prompt,
         | 
| 85 | 
            +
                        contextualizedPrompt: contextualizedPrompt,
         | 
| 86 | 
            +
                        actions: actions,
         | 
| 87 | 
            +
                      },
         | 
| 88 | 
            +
                      events
         | 
| 89 | 
            +
                    )
         | 
| 90 | 
            +
                  : undefined;
         | 
| 65 91 | 
             
              }
         | 
| 66 92 |  | 
| 67 93 | 
             
              private async handleActions(
         | 
| @@ -76,8 +102,7 @@ export class Agent { | |
| 76 102 | 
             
                },
         | 
| 77 103 | 
             
                events: AgentEvent
         | 
| 78 104 | 
             
              ): Promise<any> {
         | 
| 79 | 
            -
                const  | 
| 80 | 
            -
                const queueItems = this.transformActions(actions, similarActions);
         | 
| 105 | 
            +
                const queueItems = this.transformActions(actions);
         | 
| 81 106 |  | 
| 82 107 | 
             
                const actionsResult = await this.actionHandler.executeActions(
         | 
| 83 108 | 
             
                  queueItems,
         | 
| @@ -99,6 +124,7 @@ export class Agent { | |
| 99 124 | 
             
                  this.orchestrator.tools,
         | 
| 100 125 | 
             
                  this.persistentMemory
         | 
| 101 126 | 
             
                );
         | 
| 127 | 
            +
             | 
| 102 128 | 
             
                const evaluation = await evaluator.process(
         | 
| 103 129 | 
             
                  initialPrompt,
         | 
| 104 130 | 
             
                  contextualizedPrompt,
         | 
| @@ -107,6 +133,13 @@ export class Agent { | |
| 107 133 |  | 
| 108 134 | 
             
                events.onMessage?.(evaluation);
         | 
| 109 135 |  | 
| 136 | 
            +
                await this.cacheMemory?.createMemory({
         | 
| 137 | 
            +
                  content: initialPrompt,
         | 
| 138 | 
            +
                  data: actions,
         | 
| 139 | 
            +
                  scope: MemoryScope.GLOBAL,
         | 
| 140 | 
            +
                  type: MemoryType.ACTION,
         | 
| 141 | 
            +
                });
         | 
| 142 | 
            +
             | 
| 110 143 | 
             
                if (evaluation.nextActions.length > 0) {
         | 
| 111 144 | 
             
                  this.evaluatorIteration++;
         | 
| 112 145 | 
             
                  return this.handleActions(
         | 
| @@ -144,28 +177,10 @@ export class Agent { | |
| 144 177 | 
             
                  : await synthesizer.process(summaryData);
         | 
| 145 178 | 
             
              }
         | 
| 146 179 |  | 
| 147 | 
            -
              private  | 
| 148 | 
            -
                if (!this.cacheMemory) {
         | 
| 149 | 
            -
                  return [];
         | 
| 150 | 
            -
                }
         | 
| 151 | 
            -
             | 
| 152 | 
            -
                return this.cacheMemory.findBestMatches(prompt, {
         | 
| 153 | 
            -
                  similarityThreshold: this.SIMILARITY_THRESHOLD,
         | 
| 154 | 
            -
                  maxResults: this.MAX_RESULTS,
         | 
| 155 | 
            -
                  userId: this.user.id,
         | 
| 156 | 
            -
                  scope: MemoryScope.USER,
         | 
| 157 | 
            -
                });
         | 
| 158 | 
            -
              }
         | 
| 159 | 
            -
             | 
| 160 | 
            -
              private transformActions(actions: ActionSchema[], similarActions: any[]) {
         | 
| 180 | 
            +
              private transformActions(actions: ActionSchema[]) {
         | 
| 161 181 | 
             
                let predefinedActions =
         | 
| 162 182 | 
             
                  QueueItemTransformer.transformActionsToQueueItems(actions) || [];
         | 
| 163 183 |  | 
| 164 | 
            -
                if (similarActions?.length > 0) {
         | 
| 165 | 
            -
                  predefinedActions =
         | 
| 166 | 
            -
                    QueueItemTransformer.transformFromSimilarActions(similarActions) || [];
         | 
| 167 | 
            -
                }
         | 
| 168 | 
            -
             | 
| 169 184 | 
             
                return predefinedActions;
         | 
| 170 185 | 
             
              }
         | 
| 171 186 | 
             
            }
         | 
    
        package/dist/agent/index.d.ts
    CHANGED
    
    
    
        package/dist/agent/index.js
    CHANGED
    
    | @@ -20,19 +20,37 @@ class Agent { | |
| 20 20 | 
             
                    this.actionHandler = new ActionHandler_1.ActionHandler();
         | 
| 21 21 | 
             
                }
         | 
| 22 22 | 
             
                async process(prompt, contextualizedPrompt, events) {
         | 
| 23 | 
            -
                     | 
| 24 | 
            -
                     | 
| 25 | 
            -
             | 
| 26 | 
            -
             | 
| 23 | 
            +
                    let actions = [];
         | 
| 24 | 
            +
                    if (this.cacheMemory) {
         | 
| 25 | 
            +
                        const similarActions = await this.cacheMemory.findSimilarQueries(prompt, {
         | 
| 26 | 
            +
                            similarityThreshold: this.SIMILARITY_THRESHOLD,
         | 
| 27 | 
            +
                            maxResults: this.MAX_RESULTS,
         | 
| 28 | 
            +
                            userId: this.user.id,
         | 
| 29 | 
            +
                            scope: types_1.MemoryScope.GLOBAL,
         | 
| 30 | 
            +
                        });
         | 
| 31 | 
            +
                        if (similarActions.length > 0) {
         | 
| 32 | 
            +
                            actions = similarActions[0].data;
         | 
| 33 | 
            +
                            console.log("Similar actions found for query: ", prompt);
         | 
| 34 | 
            +
                            console.dir(actions, { depth: null });
         | 
| 35 | 
            +
                        }
         | 
| 36 | 
            +
                    }
         | 
| 37 | 
            +
                    if (!actions.length) {
         | 
| 38 | 
            +
                        console.log("No similar actions found for query: ", prompt);
         | 
| 39 | 
            +
                        console.log("Requesting orchestrator for actions");
         | 
| 40 | 
            +
                        const request = await this.orchestrator.process(contextualizedPrompt);
         | 
| 41 | 
            +
                        events.onMessage?.(request);
         | 
| 42 | 
            +
                        actions = request.actions;
         | 
| 43 | 
            +
                    }
         | 
| 44 | 
            +
                    return actions.length > 0
         | 
| 45 | 
            +
                        ? this.handleActions({
         | 
| 27 46 | 
             
                            initialPrompt: prompt,
         | 
| 28 47 | 
             
                            contextualizedPrompt: contextualizedPrompt,
         | 
| 29 | 
            -
                            actions:  | 
| 30 | 
            -
                        }, events) | 
| 31 | 
            -
             | 
| 48 | 
            +
                            actions: actions,
         | 
| 49 | 
            +
                        }, events)
         | 
| 50 | 
            +
                        : undefined;
         | 
| 32 51 | 
             
                }
         | 
| 33 52 | 
             
                async handleActions({ initialPrompt, contextualizedPrompt, actions, }, events) {
         | 
| 34 | 
            -
                    const  | 
| 35 | 
            -
                    const queueItems = this.transformActions(actions, similarActions);
         | 
| 53 | 
            +
                    const queueItems = this.transformActions(actions);
         | 
| 36 54 | 
             
                    const actionsResult = await this.actionHandler.executeActions(queueItems, this.orchestrator.tools, {
         | 
| 37 55 | 
             
                        onQueueStart: events.onQueueStart,
         | 
| 38 56 | 
             
                        onActionStart: events.onActionStart,
         | 
| @@ -46,6 +64,12 @@ class Agent { | |
| 46 64 | 
             
                    const evaluator = new evaluator_1.Evaluator(this.orchestrator.tools, this.persistentMemory);
         | 
| 47 65 | 
             
                    const evaluation = await evaluator.process(initialPrompt, contextualizedPrompt, JSON.stringify(actionsResult.data));
         | 
| 48 66 | 
             
                    events.onMessage?.(evaluation);
         | 
| 67 | 
            +
                    await this.cacheMemory?.createMemory({
         | 
| 68 | 
            +
                        content: initialPrompt,
         | 
| 69 | 
            +
                        data: actions,
         | 
| 70 | 
            +
                        scope: types_1.MemoryScope.GLOBAL,
         | 
| 71 | 
            +
                        type: types_1.MemoryType.ACTION,
         | 
| 72 | 
            +
                    });
         | 
| 49 73 | 
             
                    if (evaluation.nextActions.length > 0) {
         | 
| 50 74 | 
             
                        this.evaluatorIteration++;
         | 
| 51 75 | 
             
                        return this.handleActions({
         | 
| @@ -72,23 +96,8 @@ class Agent { | |
| 72 96 | 
             
                        ? (await synthesizer.streamProcess(summaryData)).toDataStreamResponse()
         | 
| 73 97 | 
             
                        : await synthesizer.process(summaryData);
         | 
| 74 98 | 
             
                }
         | 
| 75 | 
            -
                 | 
| 76 | 
            -
                    if (!this.cacheMemory) {
         | 
| 77 | 
            -
                        return [];
         | 
| 78 | 
            -
                    }
         | 
| 79 | 
            -
                    return this.cacheMemory.findBestMatches(prompt, {
         | 
| 80 | 
            -
                        similarityThreshold: this.SIMILARITY_THRESHOLD,
         | 
| 81 | 
            -
                        maxResults: this.MAX_RESULTS,
         | 
| 82 | 
            -
                        userId: this.user.id,
         | 
| 83 | 
            -
                        scope: types_1.MemoryScope.USER,
         | 
| 84 | 
            -
                    });
         | 
| 85 | 
            -
                }
         | 
| 86 | 
            -
                transformActions(actions, similarActions) {
         | 
| 99 | 
            +
                transformActions(actions) {
         | 
| 87 100 | 
             
                    let predefinedActions = queue_item_transformer_1.QueueItemTransformer.transformActionsToQueueItems(actions) || [];
         | 
| 88 | 
            -
                    if (similarActions?.length > 0) {
         | 
| 89 | 
            -
                        predefinedActions =
         | 
| 90 | 
            -
                            queue_item_transformer_1.QueueItemTransformer.transformFromSimilarActions(similarActions) || [];
         | 
| 91 | 
            -
                    }
         | 
| 92 101 | 
             
                    return predefinedActions;
         | 
| 93 102 | 
             
                }
         | 
| 94 103 | 
             
            }
         | 
    
        package/dist/index.d.ts
    CHANGED
    
    
    
        package/dist/index.js
    CHANGED
    
    | @@ -17,7 +17,6 @@ Object.defineProperty(exports, "__esModule", { value: true }); | |
| 17 17 | 
             
            __exportStar(require("./agent"), exports);
         | 
| 18 18 | 
             
            __exportStar(require("./llm/orchestrator"), exports);
         | 
| 19 19 | 
             
            __exportStar(require("./llm/synthesizer"), exports);
         | 
| 20 | 
            -
            __exportStar(require("./services/queue"), exports);
         | 
| 21 20 | 
             
            __exportStar(require("./types"), exports);
         | 
| 22 21 | 
             
            __exportStar(require("./memory/cache"), exports);
         | 
| 23 22 | 
             
            __exportStar(require("./memory/persistent"), exports);
         | 
| @@ -7,7 +7,7 @@ exports.orchestratorContext = { | |
| 7 7 | 
             
                guidelines: {
         | 
| 8 8 | 
             
                    important: [
         | 
| 9 9 | 
             
                        "If there is no action to do, you must answer in the 'answer' field.",
         | 
| 10 | 
            -
                        "If some parameters are not clear or missing, YOU MUST ask the user for them.",
         | 
| 10 | 
            +
                        "If some parameters are not clear or missing, don't add the action, YOU MUST ask the user for them.",
         | 
| 11 11 | 
             
                        "ALWAYS use the same language as user request. (If it's English, use English, if it's French, use French, etc.)",
         | 
| 12 12 | 
             
                        "For QUESTIONS or ANALYSIS, BEFORE executing ANY actions, you MUST search in memory for similar queries AS THE ONLY ACTION TO EXECUTE.",
         | 
| 13 13 | 
             
                    ],
         |