AgentSkillsCN

edsl-agent-create-agent-list

从CSV文件、Excel文件、字典、DataFrame、代理人列表,或通过生成代理(如通过网络搜索、描述文字,或程序化生成)来创建AgentList。

SKILL.md
--- frontmatter
name: edsl-agent-create-agent-list
description: Create AgentLists from CSV files, Excel files, dictionaries, DataFrames, lists of agents, or by generating agents (e.g., from web searches, descriptions, or programmatic generation)
allowed-tools: Read, Glob, Bash(python:*), WebSearch, WebFetch, AskUserQuestion

Creating AgentLists

Important: Ask User for Output Preference

After gathering the agent data, ALWAYS use AskUserQuestion to ask the user how they want the result delivered:

  • Python script: Write a .py file they can import/run
  • JSON file: Save the AgentList to a .json or .json.gz file using agents.save("filename")
  • Show code only: Display the code in the chat without creating files
  • Interactive: Return the AgentList object for immediate use in a session

Generating Agents

Agents can be generated from descriptions or external sources (not just loaded from files):

python
# Example: Generate agents from web search results
# 1. Search for data (e.g., sports roster, company employees, historical figures)
# 2. Extract relevant traits
# 3. Build AgentList programmatically

from edsl import Agent, AgentList

# Generated from research/web data
agents = AgentList([
    Agent(name="Person A", traits={"role": "CEO", "age": 45, "company": "Acme"}),
    Agent(name="Person B", traits={"role": "CTO", "age": 38, "company": "Acme"}),
])

From a List of Agents

python
from edsl import Agent, AgentList

# Create agents individually
agent1 = Agent(traits={"age": 25, "occupation": "teacher"})
agent2 = Agent(traits={"age": 35, "occupation": "doctor"})

# Combine into AgentList
agents = AgentList([agent1, agent2])

From External Data Sources

The from_source() method auto-detects the source type:

python
from edsl import AgentList

# From CSV file
agents = AgentList.from_source("people.csv")

# From Excel file
agents = AgentList.from_source("data.xlsx", sheet_name="Participants")

# From dictionary
agents = AgentList.from_source({
    "age": [25, 30, 35],
    "name": ["Alice", "Bob", "Charlie"],
    "occupation": ["teacher", "doctor", "engineer"]
})

# From pandas DataFrame
import pandas as pd
df = pd.DataFrame({"age": [25, 30], "city": ["NYC", "LA"]})
agents = AgentList.from_source(df)

With Instructions and Codebook

python
# Apply instructions to all agents at creation time
agents = AgentList.from_source(
    "people.csv",
    instructions="Answer as if you were this person",
    codebook={"age": "Age in years", "income": "Annual income in USD"},
    name_field="respondent_name"  # Use this column as agent names
)

# Or load codebook from a CSV file (2 columns: key, description)
agents = AgentList.from_source(
    "people.csv",
    codebook="codebook.csv"
)

Programmatically with Combinations

python
from edsl import Agent, AgentList
from itertools import product

# Create agents for all combinations
ages = [25, 35, 45]
occupations = ["teacher", "doctor", "engineer"]

agents = AgentList([
    Agent(traits={"age": age, "occupation": occ})
    for age, occ in product(ages, occupations)
])
# Creates 9 agents (3 ages × 3 occupations)

Quick Reference

SourceExample
List of AgentsAgentList([agent1, agent2])
CSV fileAgentList.from_source("file.csv")
Excel fileAgentList.from_source("file.xlsx", sheet_name="Sheet1")
DictionaryAgentList.from_source({"col": [1, 2, 3]})
DataFrameAgentList.from_source(df)