#ReACT Looping of an agent

2 messages · Page 1 of 1 (latest)

lilac canopy
#

Hi everyone
I want to know if in a group chat manager, is it possible that one agent keep calling itself in loop without the interference of chat manager.

I want an agent to keep in progression calling itself in loop without the interference of chat manager untill the task of that particuler agent is completed. Once the agent is done with its task, it can give its output to chat manager that can now call some other agent.

So it will be some nested incorporated within the group cahat manager

wooden copper
#

Yes this is possible but you have to change the autogen agents for that. Means you have to change the original files and the behavior of the agents. For example:

class Agent:
def init(self, task_value):
self.task_value = task_value

def perform_task(self):
    if self.task_value > 0:
        print(f"Task in progress: {self.task_value}")
        self.task_value -= 1
        self.perform_task()  # Recursive call
    else:
        print("Task completed!")
        self.notify_chat_manager()

def notify_chat_manager(self):
    print("Notifying chat manager that the task is completed.")

Example usage

agent = Agent(task_value=5)
agent.perform_task()

The perform_task method is a recursive function that keeps calling itself until the task value reaches zero.