RoundRobin

The RoundRobinZytron class is designed to manage and execute tasks across multiple agents within the Zytron framework using a round-robin scheduling strategy. This method ensures that each agent in the system has an equal opportunity to process tasks, promoting fairness and operational efficiency in distributed environments. It is particularly effective in scenarios where sequential, collaborative task execution is required among a network of agents.

Conceptual Overview

What is Round-Robin?

Round-robin is a widely used scheduling method in computing, where each process is allocated a fixed time slice and executed in a circular order without prioritization. When applied to the Zytron ecosystem, this technique ensures balanced task distribution and equitable utilization of resources across all agents in the zytron.

Application in Zytron Systems

In the context of Zytron, RoundRobinZytron employs this scheduling method to manage tasks among participating agents, whether they are software components, autonomous bots, or virtual entities. This approach is ideal for systems requiring interdependent task management or orderly processing across multiple agents.


Class Attributes

  • agents (List[Agent]): A collection of agents participating in the Zytron system.

  • verbose (bool): Configures detailed logging for monitoring operations.

  • max_loops (int): Defines the maximum number of cycles for task execution across all agents.

  • index (int): Tracks the current position in the agent list to facilitate round-robin execution.


Methods

__init__

Initializes the Zytron system with the specified agents and operational parameters.

Parameters:

  • agents: An optional list of agents included in the Zytron.

  • verbose: A Boolean flag to enable or disable detailed operation logs.

  • max_loops: Specifies the maximum number of execution cycles.

  • callback: An optional function to handle intermediate results or execute additional actions after each loop.


run

Executes the assigned task sequentially among all agents in a round-robin fashion. This method cycles through each agent repeatedly for a specified number of loops.

Conceptual Behavior:

  1. Task Distribution: The task is sequentially assigned to each agent, starting from the current index.

  2. Task Execution: Each agent processes the task, potentially transforming or extending it based on its functionality.

  3. Index Update: Upon task completion, the index moves to the next agent.

  4. Loop Execution: The process continues for the specified number of loops.

  5. Callback Invocation: An optional callback function can be triggered after each loop to manage intermediate outcomes or perform additional operations.

This method ensures systematic task processing across all agents, maintaining consistency and fairness in the execution flow.

Examples

Example 1: Load Balancing Among Servers

In this example, RoundRobinZytron is used to distribute network requests evenly among a group of servers. This is common in scenarios where load balancing is crucial for maintaining system responsiveness and scalability.

from zytron import Agent, RoundRobinZytron
from zytron_models import OpenAIChat


# Initialize the LLM
llm = OpenAIChat()

# Define sales agents
sales_agent1 = Agent(
    agent_name="Sales Agent 1 - Automation Specialist",
    system_prompt="You're Sales Agent 1, your purpose is to generate sales for a company by focusing on the benefits of automating accounting processes!",
    agent_description="Generate sales by focusing on the benefits of automation!",
    llm=llm,
    max_loops=1,
    autosave=True,
    dashboard=False,
    verbose=True,
    streaming_on=True,
    context_length=1000,
)

sales_agent2 = Agent(
    agent_name="Sales Agent 2 - Cost Saving Specialist",
    system_prompt="You're Sales Agent 2, your purpose is to generate sales for a company by emphasizing the cost savings of using zytron of agents!",
    agent_description="Generate sales by emphasizing cost savings!",
    llm=llm,
    max_loops=1,
    autosave=True,
    dashboard=False,
    verbose=True,
    streaming_on=True,
    context_length=1000,
)

sales_agent3 = Agent(
    agent_name="Sales Agent 3 - Efficiency Specialist",
    system_prompt="You're Sales Agent 3, your purpose is to generate sales for a company by highlighting the efficiency and accuracy of our zytron of agents in accounting processes!",
    agent_description="Generate sales by highlighting efficiency and accuracy!",
    llm=llm,
    max_loops=1,
    autosave=True,
    dashboard=False,
    verbose=True,
    streaming_on=True,
    context_length=1000,
)

# Initialize the zytron with sales agents
sales_zytron = RoundRobinZytron(agents=[sales_agent1, sales_agent2, sales_agent3], verbose=True)

# Define a sales task
task = "Generate a sales email for an accountant firm executive to sell zytron of agents to automate their accounting processes."

# Distribute sales tasks to different agents
for _ in range(5):  # Repeat the task 5 times
    results = sales_zytron.run(task)
    print("Sales generated:", results)

Last updated