Example agents¶
This notebook contains code for creating AI agents in edsl
.
Base agent
Agent names
Personas & traits
Agent panels & AgentList
Identifying relevant audiences and attributes
from edsl import Agent
Base agent¶
Here we create a single agent with no specific characteristics:
agent = Agent()
agent
Agent(traits = {})
Agent names¶
We can optionally give our agent a name for easy reference:
agent = Agent(name = "Robin")
agent
Agent(name = 'Robin', traits = {})
Personas & traits¶
We can add a description of a persona and other traits:
persona = "You are a middle-aged mom."
location = "You live in Massachusetts."
car = "You swore that you would never own a minivan but have come to appreciate their spaciousness."
agent.traits['persona'] = persona
agent.traits['location'] = location
agent.traits['car'] = car
agent.print()
Agent Attributes ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Attribute ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ _name │ 'Robin' │ │ _traits │ {'persona': 'You are a middle-aged mom.', 'location': 'You live in Massachusetts.', │ │ │ 'car': 'You swore that you would never own a minivan but have come to appreciate │ │ │ their spaciousness.'} │ │ _codebook │ {} │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ set_instructions │ False │ │ dynamic_traits_function │ None │ │ current_question │ None │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────────────┘
Note that traits are required while names are optional. Here we create the agent with a name and traits in a single step:
agent = Agent(name = "Robin", traits = {'persona': persona, 'location': location, 'car': car})
agent
Agent(name = 'Robin', traits = {'persona': 'You are a middle-aged mom.', 'location': 'You live in Massachusetts.', 'car': 'You swore that you would never own a minivan but have come to appreciate their spaciousness.'})
Agent panels¶
We can also create panels of agents for lists of traits that we want represented individually:
ages = [25, 65]
locations = ['Massachusetts', 'California']
politics = ['Socialist', 'Democrat', 'Republican', 'Libertarian']
agents = [Agent(traits = {'age':a, 'location':l, 'politics':p}) for a in ages for l in locations for p in politics]
agents
[Agent(traits = {'age': 25, 'location': 'Massachusetts', 'politics': 'Socialist'}), Agent(traits = {'age': 25, 'location': 'Massachusetts', 'politics': 'Democrat'}), Agent(traits = {'age': 25, 'location': 'Massachusetts', 'politics': 'Republican'}), Agent(traits = {'age': 25, 'location': 'Massachusetts', 'politics': 'Libertarian'}), Agent(traits = {'age': 25, 'location': 'California', 'politics': 'Socialist'}), Agent(traits = {'age': 25, 'location': 'California', 'politics': 'Democrat'}), Agent(traits = {'age': 25, 'location': 'California', 'politics': 'Republican'}), Agent(traits = {'age': 25, 'location': 'California', 'politics': 'Libertarian'}), Agent(traits = {'age': 65, 'location': 'Massachusetts', 'politics': 'Socialist'}), Agent(traits = {'age': 65, 'location': 'Massachusetts', 'politics': 'Democrat'}), Agent(traits = {'age': 65, 'location': 'Massachusetts', 'politics': 'Republican'}), Agent(traits = {'age': 65, 'location': 'Massachusetts', 'politics': 'Libertarian'}), Agent(traits = {'age': 65, 'location': 'California', 'politics': 'Socialist'}), Agent(traits = {'age': 65, 'location': 'California', 'politics': 'Democrat'}), Agent(traits = {'age': 65, 'location': 'California', 'politics': 'Republican'}), Agent(traits = {'age': 65, 'location': 'California', 'politics': 'Libertarian'})]
Note that we did not specify agent names, but we can access the default names when we generate Results
.
AgentList¶
AgentList
also lets us create panels efficiently:
from edsl import AgentList
agent_traits = [{'age':a, 'location':l, 'politics':p} for a in ages for l in locations for p in politics]
Here we also specify agent names in creating the panel:
agent_list = AgentList([Agent(traits = traits, name = f"Agent_{index}") for index, traits in enumerate(agent_traits)])
agent_list
AgentList([Agent(name = 'Agent_0', traits = {'age': 25, 'location': 'Massachusetts', 'politics': 'Socialist'}), Agent(name = 'Agent_1', traits = {'age': 25, 'location': 'Massachusetts', 'politics': 'Democrat'}), Agent(name = 'Agent_2', traits = {'age': 25, 'location': 'Massachusetts', 'politics': 'Republican'}), Agent(name = 'Agent_3', traits = {'age': 25, 'location': 'Massachusetts', 'politics': 'Libertarian'}), Agent(name = 'Agent_4', traits = {'age': 25, 'location': 'California', 'politics': 'Socialist'}), Agent(name = 'Agent_5', traits = {'age': 25, 'location': 'California', 'politics': 'Democrat'}), Agent(name = 'Agent_6', traits = {'age': 25, 'location': 'California', 'politics': 'Republican'}), Agent(name = 'Agent_7', traits = {'age': 25, 'location': 'California', 'politics': 'Libertarian'}), Agent(name = 'Agent_8', traits = {'age': 65, 'location': 'Massachusetts', 'politics': 'Socialist'}), Agent(name = 'Agent_9', traits = {'age': 65, 'location': 'Massachusetts', 'politics': 'Democrat'}), Agent(name = 'Agent_10', traits = {'age': 65, 'location': 'Massachusetts', 'politics': 'Republican'}), Agent(name = 'Agent_11', traits = {'age': 65, 'location': 'Massachusetts', 'politics': 'Libertarian'}), Agent(name = 'Agent_12', traits = {'age': 65, 'location': 'California', 'politics': 'Socialist'}), Agent(name = 'Agent_13', traits = {'age': 65, 'location': 'California', 'politics': 'Democrat'}), Agent(name = 'Agent_14', traits = {'age': 65, 'location': 'California', 'politics': 'Republican'}), Agent(name = 'Agent_15', traits = {'age': 65, 'location': 'California', 'politics': 'Libertarian'})])
agent_list.print()
AgentList ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Agents ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_0' │ │ │ │ _traits │ {'age': 25, 'location': 'Massachusetts', 'politics': 'Socialist'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_1' │ │ │ │ _traits │ {'age': 25, 'location': 'Massachusetts', 'politics': 'Democrat'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_2' │ │ │ │ _traits │ {'age': 25, 'location': 'Massachusetts', 'politics': 'Republican'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_3' │ │ │ │ _traits │ {'age': 25, 'location': 'Massachusetts', 'politics': 'Libertarian'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_4' │ │ │ │ _traits │ {'age': 25, 'location': 'California', 'politics': 'Socialist'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_5' │ │ │ │ _traits │ {'age': 25, 'location': 'California', 'politics': 'Democrat'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_6' │ │ │ │ _traits │ {'age': 25, 'location': 'California', 'politics': 'Republican'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_7' │ │ │ │ _traits │ {'age': 25, 'location': 'California', 'politics': 'Libertarian'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_8' │ │ │ │ _traits │ {'age': 65, 'location': 'Massachusetts', 'politics': 'Socialist'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_9' │ │ │ │ _traits │ {'age': 65, 'location': 'Massachusetts', 'politics': 'Democrat'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_10' │ │ │ │ _traits │ {'age': 65, 'location': 'Massachusetts', 'politics': 'Republican'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_11' │ │ │ │ _traits │ {'age': 65, 'location': 'Massachusetts', 'politics': 'Libertarian'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_12' │ │ │ │ _traits │ {'age': 65, 'location': 'California', 'politics': 'Socialist'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_13' │ │ │ │ _traits │ {'age': 65, 'location': 'California', 'politics': 'Democrat'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_14' │ │ │ │ _traits │ {'age': 65, 'location': 'California', 'politics': 'Republican'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_15' │ │ │ │ _traits │ {'age': 65, 'location': 'California', 'politics': 'Libertarian'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
from edsl.questions import QuestionFreeText
q = QuestionFreeText(
question_name = "views",
question_text = "Describe your political views."
)
result = q.by(agent_list).run()
result.select("agent_name", "age", "location", "politics", "views").print()
┏━━━━━━━━━━━━━┳━━━━━━━┳━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ agent ┃ agent ┃ agent ┃ agent ┃ answer ┃ ┃ .agent_name ┃ .age ┃ .location ┃ .politics ┃ .views ┃ ┡━━━━━━━━━━━━━╇━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ Agent_0 │ 25 │ Massachusetts │ Socialist │ I believe in a socialist political system that prioritizes │ │ │ │ │ │ social equality, worker rights, and public ownership of key │ │ │ │ │ │ industries. I advocate for policies that aim to reduce │ │ │ │ │ │ income inequality, provide universal healthcare and │ │ │ │ │ │ education, and protect the environment for future │ │ │ │ │ │ generations. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_1 │ 25 │ Massachusetts │ Democrat │ I consider myself a Democrat and I believe in policies that │ │ │ │ │ │ promote equality, social justice, and environmental │ │ │ │ │ │ protection. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_2 │ 25 │ Massachusetts │ Republican │ I believe in limited government, personal responsibility, │ │ │ │ │ │ and free market principles. I support lower taxes, a strong │ │ │ │ │ │ national defense, and individual liberties. I believe in │ │ │ │ │ │ the importance of upholding traditional values and │ │ │ │ │ │ promoting economic growth through entrepreneurship and │ │ │ │ │ │ innovation. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_3 │ 25 │ Massachusetts │ Libertarian │ I believe in individual freedom and limited government │ │ │ │ │ │ intervention in both personal and economic matters. I value │ │ │ │ │ │ personal responsibility and believe in free markets as the │ │ │ │ │ │ best way to allocate resources efficiently. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_4 │ 25 │ California │ Socialist │ I believe in a socialist system where resources are shared │ │ │ │ │ │ equally among all members of society to ensure everyone has │ │ │ │ │ │ access to basic needs and opportunities for a better life. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_5 │ 25 │ California │ Democrat │ I identify as a Democrat and believe in progressive │ │ │ │ │ │ policies that prioritize equality, social justice, and │ │ │ │ │ │ environmental sustainability. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_6 │ 25 │ California │ Republican │ I believe in limited government, individual freedom, and │ │ │ │ │ │ personal responsibility. I support lower taxes, free │ │ │ │ │ │ markets, and a strong national defense. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_7 │ 25 │ California │ Libertarian │ I believe in personal freedom, limited government │ │ │ │ │ │ intervention, and individual responsibility. I value │ │ │ │ │ │ individual rights and believe in free markets and voluntary │ │ │ │ │ │ interactions. I think government should have a minimal role │ │ │ │ │ │ in people's lives and that individuals should be free to │ │ │ │ │ │ make their own choices as long as they do not harm others. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_8 │ 65 │ Massachusetts │ Socialist │ I believe in a socialist system that prioritizes social │ │ │ │ │ │ equality, workers' rights, and providing essential services │ │ │ │ │ │ to all members of society. I advocate for policies that │ │ │ │ │ │ reduce income inequality, ensure access to healthcare and │ │ │ │ │ │ education for all, and promote a more equitable │ │ │ │ │ │ distribution of resources. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_9 │ 65 │ Massachusetts │ Democrat │ I consider myself a Democrat and believe in progressive │ │ │ │ │ │ policies that prioritize equality, social justice, and │ │ │ │ │ │ environmental protection. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_10 │ 65 │ Massachusetts │ Republican │ I believe in limited government, fiscal responsibility, and │ │ │ │ │ │ individual freedom. I support conservative principles and │ │ │ │ │ │ policies that promote economic growth and personal │ │ │ │ │ │ responsibility. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_11 │ 65 │ Massachusetts │ Libertarian │ I believe in personal freedom, limited government │ │ │ │ │ │ intervention, and individual responsibility. I think that │ │ │ │ │ │ individuals should have the right to make their own choices │ │ │ │ │ │ without excessive government interference. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_12 │ 65 │ California │ Socialist │ I believe in socialist principles that prioritize equality, │ │ │ │ │ │ social justice, and collective ownership of resources. I │ │ │ │ │ │ advocate for policies that aim to reduce income inequality, │ │ │ │ │ │ provide universal healthcare and education, and protect │ │ │ │ │ │ workers' rights. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_13 │ 65 │ California │ Democrat │ I consider myself a Democrat and generally support policies │ │ │ │ │ │ that prioritize social welfare, environmental protection, │ │ │ │ │ │ and equality for all individuals. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_14 │ 65 │ California │ Republican │ I believe in limited government, fiscal responsibility, and │ │ │ │ │ │ individual freedoms. I support conservative principles and │ │ │ │ │ │ policies that promote economic growth and national │ │ │ │ │ │ security. │ ├─────────────┼───────┼───────────────┼─────────────┼─────────────────────────────────────────────────────────────┤ │ Agent_15 │ 65 │ California │ Libertarian │ I believe in individual liberty, limited government │ │ │ │ │ │ intervention, and personal responsibility. I value free │ │ │ │ │ │ markets, voluntary interactions, and minimal regulations. I │ │ │ │ │ │ believe in maximizing personal freedom and minimizing │ │ │ │ │ │ government control in all aspects of life. │ └─────────────┴───────┴───────────────┴─────────────┴─────────────────────────────────────────────────────────────┘
Identifying relevant audiences and attributes¶
We can also use the tools to identify audiences of interest and relevant attributes of respondents for a given research topic, and then use them to create personas for panels of agents:
from edsl.questions import QuestionList
research_topic = "Views on artificial intelligence"
q_attributes = QuestionList(
question_name = "attributes",
question_text = """What are some relevant attributes of respondents answering a survey on the following topic: """
+ research_topic + """ Return each attributes as an item in a list."""
)
r_attributes = q_attributes.run()
attributes = r_attributes.select("attributes").to_list()[0]
attributes
['Age', 'Education level', 'Occupation', 'Familiarity with AI technology', 'Attitudes towards technology', 'Ethical beliefs']
q_personas = QuestionList(
question_name = "personas",
question_text = "Draft 5 diverse personas for the following attributes: " + ", ".join(attributes)
)
r_personas = q_personas.run()
personas = r_personas.select("personas").to_list()[0]
personas
[{'age': '28', 'education_level': "Master's degree", 'occupation': 'Marketing Manager', 'familiarity_with_AI_technology': 'Intermediate', 'attitudes_towards_technology': 'Enthusiastic', 'ethical_beliefs': 'Ethical considerations are important'}, {'age': '45', 'education_level': "Bachelor's degree", 'occupation': 'Teacher', 'familiarity_with_AI_technology': 'Limited', 'attitudes_towards_technology': 'Cautious', 'ethical_beliefs': 'Concerned about data privacy'}, {'age': '35', 'education_level': 'PhD', 'occupation': 'Research Scientist', 'familiarity_with_AI_technology': 'Expert', 'attitudes_towards_technology': 'Innovative', 'ethical_beliefs': 'Believes in responsible AI use'}, {'age': '50', 'education_level': 'High School Diploma', 'occupation': 'Construction Worker', 'familiarity_with_AI_technology': 'Limited', 'attitudes_towards_technology': 'Skeptical', 'ethical_beliefs': 'Values human labor over automation'}, {'age': '32', 'education_level': "Associate's degree", 'occupation': 'Small Business Owner', 'familiarity_with_AI_technology': 'Moderate', 'attitudes_towards_technology': 'Pragmatic', 'ethical_beliefs': 'Balancing profit with ethical considerations'}]
agent_list = AgentList([Agent(traits = traits, name = f"Agent_{index}") for index, traits in enumerate(personas)])
agent_list.print()
AgentList ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Agents ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_0' │ │ │ │ _traits │ {'age': '28', 'education_level': "Master's degree", 'occupation': 'Marketing │ │ │ │ │ Manager', 'familiarity_with_AI_technology': 'Intermediate', │ │ │ │ │ 'attitudes_towards_technology': 'Enthusiastic', 'ethical_beliefs': 'Ethical │ │ │ │ │ considerations are important'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_1' │ │ │ │ _traits │ {'age': '45', 'education_level': "Bachelor's degree", 'occupation': 'Teacher', │ │ │ │ │ 'familiarity_with_AI_technology': 'Limited', 'attitudes_towards_technology': │ │ │ │ │ 'Cautious', 'ethical_beliefs': 'Concerned about data privacy'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_2' │ │ │ │ _traits │ {'age': '35', 'education_level': 'PhD', 'occupation': 'Research Scientist', │ │ │ │ │ 'familiarity_with_AI_technology': 'Expert', 'attitudes_towards_technology': │ │ │ │ │ 'Innovative', 'ethical_beliefs': 'Believes in responsible AI use'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_3' │ │ │ │ _traits │ {'age': '50', 'education_level': 'High School Diploma', 'occupation': │ │ │ │ │ 'Construction Worker', 'familiarity_with_AI_technology': 'Limited', │ │ │ │ │ 'attitudes_towards_technology': 'Skeptical', 'ethical_beliefs': 'Values human │ │ │ │ │ labor over automation'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────────┘ │ │ Agent Attributes │ │ ┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ │ │ ┃ Attribute ┃ Value ┃ │ │ ┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ │ │ _name │ 'Agent_4' │ │ │ │ _traits │ {'age': '32', 'education_level': "Associate's degree", 'occupation': 'Small │ │ │ │ │ Business Owner', 'familiarity_with_AI_technology': 'Moderate', │ │ │ │ │ 'attitudes_towards_technology': 'Pragmatic', 'ethical_beliefs': 'Balancing profit │ │ │ │ │ with ethical considerations'} │ │ │ │ _codebook │ {} │ │ │ │ _instruction │ 'You are answering questions as if you were a human. Do not break character.' │ │ │ │ set_instructions │ False │ │ │ │ dynamic_traits_function │ None │ │ │ │ current_question │ None │ │ │ └─────────────────────────┴───────────────────────────────────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
from edsl.questions import QuestionFreeText
q_views = QuestionFreeText(
question_name = "ai_views",
question_text = "What are your views on artificial intelligence?"
)
r_views = q_views.by(agent_list).run()
(r_views
.select("agent.agent_name", "ai_views")
.print()
)
┏━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ agent ┃ answer ┃ ┃ .agent_name ┃ .ai_views ┃ ┡━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ Agent_0 │ I believe artificial intelligence has the potential to revolutionize industries and improve │ │ │ efficiency in many aspects of our lives. However, it is important to consider ethical │ │ │ implications and ensure that AI is developed and used responsibly. │ ├─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Agent_1 │ I believe artificial intelligence has the potential to greatly benefit society in various ways, │ │ │ but I also have concerns about its impact on privacy and ethical considerations. It is important │ │ │ to carefully consider the implications of AI technology and ensure that it is developed and used │ │ │ responsibly. │ ├─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Agent_2 │ I believe artificial intelligence has the potential to revolutionize various industries and │ │ │ improve our daily lives. It is crucial to ensure that AI is developed and used responsibly, with │ │ │ ethical considerations at the forefront. As a research scientist familiar with AI technology, I │ │ │ am excited about the possibilities it offers while also being mindful of the ethical implications │ │ │ that come with its advancement. │ ├─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Agent_3 │ As a construction worker with limited familiarity with AI technology, I have a skeptical view │ │ │ towards artificial intelligence. I value human labor over automation and believe that technology │ │ │ should not replace the skills and experience of workers in various industries. │ ├─────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────┤ │ Agent_4 │ I believe artificial intelligence has the potential to greatly benefit society, but it's │ │ │ important to approach its development and implementation with caution. We need to ensure that AI │ │ │ is used ethically and responsibly, taking into consideration its impact on jobs, privacy, and │ │ │ overall well-being of individuals. │ └─────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────┘