Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.swarms.world/llms.txt

Use this file to discover all available pages before exploring further.

Overview

The AgentLoader class provides a unified interface for instantiating Agent objects from on-disk definitions. It supports three file formats and dispatches automatically based on the file extension.
FormatExtensionBacking loader
Markdown.mdload_agents_from_markdown
YAML.yamlcreate_agents_from_yaml
CSV.csvCSVAgentLoader
Use this when you want agent definitions to live as data — checked into git, edited by humans, generated by tools — rather than hard-coded in Python.

Installation

pip install -U swarms

Constructor

from swarms import AgentLoader

loader = AgentLoader(concurrent=True)
concurrent
bool
default:"True"
Default for concurrent loading when multiple files are passed. Individual load_* methods accept their own concurrent override.

Methods

auto()

Dispatch to the right loader based on file extension. The simplest entry point.
def auto(self, file_path: str, *args, **kwargs) -> List[Agent]
Parameters:
  • file_path (str): Path to .md, .yaml, or .csv file.
  • *args, **kwargs: Forwarded to the underlying loader.
Returns: List[Agent] Raises: ValueError if the file extension is not .md, .yaml, or .csv.

load_single_agent()

Alias for auto() — loads a single file by dispatching on extension.
def load_single_agent(self, *args, **kwargs) -> List[Agent]

load_multiple_agents()

Apply auto() to a list of files. Each file may be a different format.
def load_multiple_agents(
    self,
    file_paths: List[str],
    *args,
    **kwargs,
) -> List[List[Agent]]
Parameters:
  • file_paths (List[str]): Paths to agent definition files.
Returns: List of agent lists, one per input file.

load_agent_from_markdown()

Load a single agent from a Markdown file.
def load_agent_from_markdown(
    self,
    file_path: str,
    **kwargs,
) -> Agent

load_agents_from_markdown()

Load multiple agents from one or more Markdown files.
def load_agents_from_markdown(
    self,
    file_paths: Union[str, List[str]],
    concurrent: bool = True,
    max_file_size_mb: float = 10.0,
    **kwargs,
) -> List[Agent]
file_paths
Union[str, List[str]]
Single path or list of paths to Markdown agent files.
concurrent
bool
default:"True"
Load files in parallel.
max_file_size_mb
float
default:"10.0"
Files above this size are skipped.

load_agents_from_yaml()

Load agents from a single YAML file.
def load_agents_from_yaml(
    self,
    yaml_file: str,
    return_type: ReturnTypes = "auto",
    **kwargs,
) -> List[Agent]
yaml_file
str
Path to the YAML definitions file.
return_type
ReturnTypes
default:"\"auto\""
Controls the return shape from the underlying YAML loader.

load_many_agents_from_yaml()

Load agents from a list of YAML files with per-file return type control.
def load_many_agents_from_yaml(
    self,
    yaml_files: List[str],
    return_types: List[ReturnTypes] = ["auto"],
    **kwargs,
) -> List[Agent]

load_agents_from_csv()

Load agents from a CSV file via CSVAgentLoader.
def load_agents_from_csv(
    self,
    csv_file: str,
    **kwargs,
) -> List[Agent]

parse_markdown_file()

Lower-level: parse a Markdown file via MarkdownAgentLoader directly, using the host’s CPU count as worker count.
def parse_markdown_file(self, file_path: str) -> List[Agent]

Usage Examples

Auto-Dispatch on Extension

The shortest path — let auto() figure out the format.
from swarms import AgentLoader

loader = AgentLoader()

# Each file uses its own format; auto() picks the right loader
research_agents = loader.auto("agents/research_team.yaml")
support_agents = loader.auto("agents/support_squad.md")
sales_agents = loader.auto("agents/sales_reps.csv")

Load Many Files in One Call

from swarms import AgentLoader

loader = AgentLoader()

all_agents = loader.load_multiple_agents([
    "agents/research_team.yaml",
    "agents/support_squad.md",
    "agents/sales_reps.csv",
])

# all_agents is a list-of-lists; one entry per file
for file_agents in all_agents:
    for agent in file_agents:
        print(agent.agent_name)

Markdown with Concurrency Control

from swarms import AgentLoader

loader = AgentLoader()

agents = loader.load_agents_from_markdown(
    file_paths=[
        "agents/researcher.md",
        "agents/writer.md",
        "agents/editor.md",
    ],
    concurrent=True,
    max_file_size_mb=5.0,
)

Compose with a Swarm

from swarms import AgentLoader, SequentialWorkflow

loader = AgentLoader()
agents = loader.auto("agents/research_pipeline.yaml")

workflow = SequentialWorkflow(agents=agents, max_loops=1)
result = workflow.run("Summarize the current state of multi-agent research")

Source Code

View the source on GitHub.