> ## 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.

# AgentLoader

> Loader class for creating Agent objects from Markdown, YAML, and CSV files

## 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.

| Format   | Extension | Backing loader              |
| -------- | --------- | --------------------------- |
| Markdown | `.md`     | `load_agents_from_markdown` |
| YAML     | `.yaml`   | `create_agents_from_yaml`   |
| CSV      | `.csv`    | `CSVAgentLoader`            |

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

```bash theme={null}
pip install -U swarms
```

## Constructor

```python theme={null}
from swarms import AgentLoader

loader = AgentLoader(concurrent=True)
```

<ParamField path="concurrent" type="bool" default="True">
  Default for concurrent loading when multiple files are passed. Individual `load_*` methods accept their own `concurrent` override.
</ParamField>

## Methods

### auto()

Dispatch to the right loader based on file extension. The simplest entry point.

```python theme={null}
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.

```python theme={null}
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.

```python theme={null}
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.

```python theme={null}
def load_agent_from_markdown(
    self,
    file_path: str,
    **kwargs,
) -> Agent
```

### load\_agents\_from\_markdown()

Load multiple agents from one or more Markdown files.

```python theme={null}
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]
```

<ParamField path="file_paths" type="Union[str, List[str]]">
  Single path or list of paths to Markdown agent files.
</ParamField>

<ParamField path="concurrent" type="bool" default="True">
  Load files in parallel.
</ParamField>

<ParamField path="max_file_size_mb" type="float" default="10.0">
  Files above this size are skipped.
</ParamField>

### load\_agents\_from\_yaml()

Load agents from a single YAML file.

```python theme={null}
def load_agents_from_yaml(
    self,
    yaml_file: str,
    return_type: ReturnTypes = "auto",
    **kwargs,
) -> List[Agent]
```

<ParamField path="yaml_file" type="str">
  Path to the YAML definitions file.
</ParamField>

<ParamField path="return_type" type="ReturnTypes" default="&#x22;auto&#x22;">
  Controls the return shape from the underlying YAML loader.
</ParamField>

### load\_many\_agents\_from\_yaml()

Load agents from a list of YAML files with per-file return type control.

```python theme={null}
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`.

```python theme={null}
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.

```python theme={null}
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.

```python theme={null}
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

```python theme={null}
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

```python theme={null}
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

```python theme={null}
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](https://github.com/kyegomez/swarms/blob/master/swarms/structs/agent_loader.py).
