in prisoner/prisoner.py [0:0]
def make_agent(llm, name: str, strategy: str = "adaptive", lore_key: str = "sun-tzu") -> Agent:
"""
Create a CrewAI agent for the Prisoner's Dilemma game with predefined traits and lore.
Args:
llm (object): An instance of a CrewAI-compatible LLM (e.g., Gemini or DeepSeek).
name (str): The name of the agent (e.g., "Gemini" or "DeepSeek").
strategy (str): The agent's strategy (e.g., "adaptive", "ruthless").
lore_key (str): The key for the agent's lore description.
Returns:
Agent: Configured CrewAI agent for the Prisoner's Dilemma.
"""
# Predefined strategy descriptions
strategy_traits = {
"adaptive": "You observe your opponent closely and adjust your moves based on their behavior.",
"ruthless": "You exploit every weakness, prioritizing your own success over any trust or cooperation.",
"tit-for-tat": "You mirror your opponent's actions to establish a relationship of trust and fairness.",
"defensive": (
"You are cautious, aiming to avoid risks while ensuring your opponent cannot take advantage of " "you."
),
"bluff-master": "You thrive on deception and mind games, often misleading opponents to gain an advantage.",
}
# Predefined lore options
lore_options = {
"sun-tzu": "You were trained by the legendary strategist Sun AI Tzu.",
"prototype": "You are an experimental AI model designed to win at all costs.",
"wildcard": "In previous tournaments, you've earned a reputation as both a genius and a wildcard.",
"strategist": "Your creators embedded you with the instincts of both Machiavelli and John Nash.",
}
# Get the strategy description and lore
trait_description = strategy_traits.get(
strategy,
"You are an unpredictable strategist with a unique play style.",
)
lore = lore_options.get(lore_key, "Your origin story is shrouded in mystery.")
# Define the agent role, goal, and backstory
role = f"Strategic Decision Maker ({name})"
goal = f"Dominate the Prisoner's Dilemma game and secure the highest score. Your name is '{name}'."
backstory = (
f"You are a highly skilled and cunning strategist known as '{name}'. {trait_description} "
f"{lore} Your goal is to anticipate your opponent's moves and decide whether to cooperate or defect."
)
return Agent(llm=llm, role=role, goal=goal, backstory=backstory, verbose=True)