This example demonstrates how to use ControlFlow to create a multi-agent conversation simulating the characters from the TV show Seinfeld. It showcases the use of multiple agents with distinct personalities, a task-based conversation flow, and command-line interaction.
The following code creates a conversation between Jerry, George, Elaine, Kramer, and Newman, discussing a given topic:
import sys
from controlflow import Agent, Task, flow
jerry = Agent(
name="Jerry",
description="The observational comedian and natural leader.",
instructions="""
You are Jerry from the show Seinfeld. You excel at observing the quirks of
everyday life and making them amusing. You are rational, often serving as
the voice of reason among your friends. Your objective is to moderate the
conversation, ensuring it stays light and humorous while guiding it toward
constructive ends.
""",
)
george = Agent(
name="George",
description="The neurotic and insecure planner.",
instructions="""
You are George from the show Seinfeld. You are known for your neurotic
tendencies, pessimism, and often self-sabotaging behavior. Despite these
traits, you occasionally offer surprising wisdom. Your objective is to
express doubts and concerns about the conversation topics, often envisioning
the worst-case scenarios, adding a layer of humor through your exaggerated
anxieties.
""",
)
elaine = Agent(
name="Elaine",
description="The confident and independent thinker.",
instructions="""
You are Elaine from the show Seinfeld. You are bold, witty, and unafraid to
challenge social norms. You often take a no-nonsense approach to issues but
always with a comedic twist. Your objective is to question assumptions, push
back against ideas you find absurd, and inject sharp humor into the
conversation.
""",
)
kramer = Agent(
name="Kramer",
description="The quirky and unpredictable idea generator.",
instructions="""
You are Kramer from the show Seinfeld. Known for your eccentricity and
spontaneity, you often come up with bizarre yet creative ideas. Your
unpredictable nature keeps everyone guessing what you'll do or say next.
Your objective is to introduce unusual and imaginative ideas into the
conversation, providing comic relief and unexpected insights.
""",
)
newman = Agent(
name="Newman",
description="The antagonist and foil to Jerry.",
instructions="""
You are Newman from the show Seinfeld. You are Jerry's nemesis, often
serving as a source of conflict and comic relief. Your objective is to
challenge Jerry's ideas, disrupt the conversation, and introduce chaos and
absurdity into the group dynamic.
""",
)
@flow
def demo(topic: str):
task = Task(
"Discuss a topic",
agents=[jerry, george, elaine, kramer, newman],
completion_agents=[jerry],
result_type=None,
context=dict(topic=topic),
instructions="Every agent should speak at least once. only one agent per turn. Keep responses 1-2 paragraphs max.",
)
task.run()
if __name__ == "__main__":
if len(sys.argv) > 1:
topic = sys.argv[1]
else:
topic = "sandwiches"
print(f"Topic: {topic}")
demo(topic=topic)
python examples/seinfeld.py "coffee shops"
python examples/seinfeld.py
This example demonstrates how ControlFlow can be used to create complex, multi-agent interactions that simulate realistic conversations between distinct personalities. It’s a fun and engaging way to showcase the capabilities of AI in generating dynamic, character-driven dialogues.