CycleObserverFlow: Watch Your Cycles#

Overview 🌟#

CycleObserverFlow πŸ”„, a creative twist in the comma_agents package, evolves from CycleFlow to offer a unique feature: the integration of an β€˜observer’ agent. This agent acts as a smart analyst πŸ•΅οΈβ€β™‚οΈ or transformer within the cyclical execution, enriching each round of processing with insights or modifications.

Key Features πŸ”‘#

  • Observer Agent Inclusion πŸ‘€: Adds an extra layer of processing by integrating a BaseAgent as an observer. This agent steps in after each cycle to analyze or tweak outputs.

  • Enhanced Cyclical Execution πŸš€: Combines the repetitive pattern of CycleFlow with the added depth of an observer agent, leading to more sophisticated output after each cycle.

Initialization Parameters πŸ—οΈ#

  • observer_agent: (Optional) A BaseAgent to act as the observer, adding versatility to the cycle. Defaults to None.

  • **kwargs: Inherits the adaptable keyword arguments from CycleFlow, allowing for broad customization.

Attributes πŸ“Š#

  • observer_agent: The BaseAgent taking on the observer’s role, adding an extra dimension to the cycle flow.

Methods πŸ› οΈ#

alter_message_after_cycle#

  • Activated post-cycle, this method lets the observer BaseAgent process and potentially reshape the intermediate message, adding a twist to the tale.

Exceptions 🚨#

  • Signals a ValueError if observer_agent isn’t a valid BaseAgent.

Code Example 🎨#

from comma_agents.flows import CycleObserverFlow
from comma_agents.agents import BaseAgent

# Crafting an analyzing agent
class AnalyzingAgent(BaseAgent):
    def call(self, message):
        # Analyzes or modifies the message
        return "[Analyzed] " + message

# Initializing the observer agent
analyzer = AnalyzingAgent(name="DataAnalyzer")

# Setting up CycleObserverFlow with an analytical twist
cycle_observer_flow = CycleObserverFlow(observer_agent=analyzer, cycles=3)

# Kickstarting the flow
response = cycle_observer_flow.run_flow(message="Observing cycles...")

In this setup, AnalyzingAgent enriches the message with β€œ[Analyzed]” after each cycle, leading to an evolving narrative through the cycles.