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) ABaseAgent
to act as the observer, adding versatility to the cycle. Defaults toNone
.**kwargs
: Inherits the adaptable keyword arguments fromCycleFlow
, allowing for broad customization.
Attributes π#
observer_agent
: TheBaseAgent
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
ifobserver_agent
isnβt a validBaseAgent
.
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.