Skip to main content

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. Extensions are matched exactly: auto() does not accept .yml or upper-case extensions. 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

Constructor

bool
default:"True"
Stored as loader.concurrent. No method reads it; pass concurrent to load_agents_from_markdown() to control parallel loading.

Methods

auto()

Dispatch to the right loader based on file extension. The simplest entry point.
Parameters:
  • file_path (str): Path to .md, .yaml, or .csv file.
  • *args, **kwargs: Forwarded to the underlying loader.
Returns: Whatever the matching loader returns: a List[Agent] for Markdown and CSV, and the shape described under load_agents_from_yaml() for YAML. 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, and returns the same shape.

load_multiple_agents()

Apply auto() to a list of files. Each file may be a different format.
Parameters:
  • file_paths (List[str]): Paths to agent definition files.
Returns: One auto() result per input file, in order.

load_agent_from_markdown()

Load a single agent from a Markdown file.

load_agents_from_markdown()

Load multiple agents from one or more Markdown files.
Union[str, List[str]]
A single file, a directory (every *.md file in it), or a list of file paths.
bool
default:"True"
Load files in parallel when there is more than one. Agents are then returned in completion order.
float
default:"10.0"
Files above this size are skipped.
Any
Override the parsed configuration for every agent, for example model_name="gpt-5.4".
A file that fails to parse or build is logged and skipped. Each file needs YAML frontmatter and a non-empty body, which becomes the system prompt. The frontmatter keys read are name, description, model_name (or model), temperature, max_loops, mcp_url, and streaming_on. Markdown agents default to temperature=0.1 when the frontmatter sets none.
The parsed mcp_url field is typed as an integer, so a URL in the frontmatter fails validation and the file is skipped. Pass it as a keyword argument instead, e.g. load_agents_from_markdown("agents/", mcp_url="http://localhost:8000/sse").

load_agents_from_yaml()

Load agents from a single YAML file through create_agents_from_yaml.
str
Path to the YAML definitions file. It needs an agents list and may have a swarm_architecture section.
ReturnTypes
default:"\"auto\""
Controls the return shape. One of "auto", "agents", "both", "swarm", "run_swarm", "tasks".
"swarm" and "run_swarm" execute the swarm, which calls the model. They raise ValueError when the file has no swarm_architecture or no task.

load_many_agents_from_yaml()

Load agents from a list of YAML files with per-file return type control.
Returns one load_agents_from_yaml() result per file. return_types needs one entry per file; the default ["auto"] covers a single file and raises IndexError for more.

load_agents_from_csv()

Load agents from a CSV file via CSVAgentLoader.
**kwargs are accepted but ignored. Each row becomes one agent, built on up to 10 threads, so agents come back in completion order. Rows that fail validation are printed and skipped. Boolean cells count as true only when they read true (any case).

parse_markdown_file()

Lower-level: parse a Markdown file via MarkdownAgentLoader without building an agent.
Returns the parsed configuration (a Pydantic model). Raises FileNotFoundError when the file is missing and ValueError when it has no frontmatter or fails validation.

Usage Examples

Auto-Dispatch on Extension

The shortest path — let auto() figure out the format.

Load Many Files in One Call

Markdown with Concurrency Control

Compose with a Swarm

Source Code

View the source on GitHub.