Josh-XT / AGiXT

AGiXT is a dynamic AI Agent Automation Platform that seamlessly orchestrates instruction management and complex task execution across diverse AI providers. Combining adaptive memory, smart features, and a versatile plugin system, AGiXT delivers efficient and comprehensive AI solutions.
https://AGiXT.com
MIT License
2.61k stars 348 forks source link

Add Some Parallelism to AGiXT #1141

Closed birdup000 closed 3 months ago

birdup000 commented 6 months ago

Feature/Improvement Description

I wonder would it be possible to basically set a looping chain step until it gets the necessary required information to complete the step and the prompt can set a variable when it thinks the chain should be finished so an example research until you figure out this aspect of the task is the chain and then it starts the prompt after it has gotten information, then you execute a prompt and the prompt analyzes the info it grabbed and checks it to see if it makes sense and then say it can set a variable false to stop looping back to the chain if it has enough information to proceed with the next step of the chain. kind of like a chain to chain operation but instead within itself but using different prompts and chains to do that

Proposed Solution

I asked Sonnet to expand on it

Yes, it is possible to create a looping process where an initial prompt or chain gathers information and research on a topic, and then it passes that information to another prompt or chain for analysis and evaluation. This second prompt or chain can then determine if the gathered information is sufficient to proceed to the next step, or if it needs to loop back and gather more information from the initial prompt or chain.

This can be achieved using a technique called "re-ranking" or "recursive re-ranking," where the output of one prompt or chain is fed back into the initial prompt or chain as additional context or instruction. The initial prompt or chain can then use this additional context to refine its search and gather more relevant information.

To implement this, you would typically use a combination of prompts and chains, with a "controller" prompt or chain orchestrating the flow between the different components. Here's a high-level outline of how this might work:

Initial Prompt or Chain: This prompt or chain is responsible for gathering information and research on the given topic. It can be a simple search query, a more complex research prompt, or a chain of prompts and tools designed for information gathering. Analysis Prompt or Chain: This prompt or chain receives the output from the initial prompt or chain and analyzes the information to determine if it is sufficient to proceed to the next step or if more information is needed. Controller Prompt or Chain: This prompt or chain manages the flow between the initial prompt or chain and the analysis prompt or chain. It initializes the loop, passes the output from the initial prompt or chain to the analysis prompt or chain, and based on the analysis output, determines whether to loop back to the initial prompt or chain for more information or to proceed to the next step. Within this structure, you can set variables or flags to control the flow and determine when the loop should terminate. For example, the analysis prompt or chain could set a variable (e.g., is_information_sufficient = True/False) that the controller prompt or chain can use to decide whether to loop back or proceed.

This approach allows for a flexible and adaptive information gathering and analysis process, where the system can iteratively refine its understanding and gather more information as needed before moving forward.

It's important to note that implementing this type of recursive re-ranking process can be complex and may require significant engineering effort, particularly when dealing with large amounts of data or complex tasks. However, it can be a powerful technique for building intelligent systems that can adaptively gather and analyze information.

Acknowledgements

birdup000 commented 6 months ago

Of course the feature and description also Solution is just scratching the surface that's not all to the ideas I have for parallelism in AGiXT.

JamesonRGrieve commented 3 months ago

Example of self-solving chain step parallelism, use how you please:

import asyncio
import random

class Step:
    def __init__(self, id, name, dependencies=[]):
        self.id = id
        self.name = name
        self.dependencies = dependencies

    async def execute(self):
        results = await asyncio.gather(*(dep for dep in self.dependencies))
        print(
            f"Executing step {self.id}: {self.name}. Dependencies resolved as {results}."
        )
        delay = random.randint(3, 10)
        await asyncio.sleep(delay)
        self.resolved = True
        toReturn = random.randint(1, 100)
        print(f"Completed step {self.id}: {self.name} - returned {toReturn}.")
        return toReturn

async def resolve():
    step1 = asyncio.create_task(Step(1, "Step 1").execute())
    step2 = asyncio.create_task(Step(2, "Step 2", [step1]).execute())
    step3 = asyncio.create_task(Step(3, "Step 3", [step1]).execute())
    step4 = asyncio.create_task(Step(4, "Step 4", [step2, step3]).execute())
    step5 = asyncio.create_task(Step(5, "Step 5", [step1, step2]).execute())
    step6 = asyncio.create_task(Step(6, "Step 6", [step4, step5]).execute())
    step7 = asyncio.create_task(Step(7, "Step 7", [step6]).execute())
    step8 = asyncio.create_task(Step(8, "Step 8", [step1]).execute())
    step9 = await asyncio.create_task(Step(9, "Step 9", [step7, step8]).execute())

asyncio.run(resolve())

Executing step 1: Step 1. Dependencies resolved as [].
Completed step 1: Step 1 - returned 22.
Executing step 2: Step 2. Dependencies resolved as [22].
Executing step 3: Step 3. Dependencies resolved as [22].
Executing step 8: Step 8. Dependencies resolved as [22].
Completed step 2: Step 2 - returned 60.
Executing step 5: Step 5. Dependencies resolved as [22, 60].
Completed step 8: Step 8 - returned 87.
Completed step 3: Step 3 - returned 92.
Executing step 4: Step 4. Dependencies resolved as [60, 92].
Completed step 5: Step 5 - returned 83.
Completed step 4: Step 4 - returned 32.
Executing step 6: Step 6. Dependencies resolved as [32, 83].
Completed step 6: Step 6 - returned 88.
Executing step 7: Step 7. Dependencies resolved as [88].
Completed step 7: Step 7 - returned 31.
Executing step 9: Step 9. Dependencies resolved as [31, 87].
Completed step 9: Step 9 - returned 43.```
Josh-XT commented 3 months ago

Added in PR #1201