# Repository Briefing: huggingface/legion
> Source: https://repoforai.com/repo/huggingface/legion (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/huggingface/legion
- **Category**: Agents & Frameworks (智能体与框架)
- **Primary Language**: Python
- **License**: See repository
- **Engineering Health**: B+ (64/100 · Maintenance 35/35 · Adoption 12/25 · Releases 11/20 · License 6/20)
- **Review Snapshot**: 2026-12-01
- **Deployment / Stack Signals**: Docker, Self-Hosted, CLI
- **Momentum**: 125 ★ total (+4 24h / +24 7d) · 12 forks
- **When to Use**: Best for: Engineering and research teams running collaborative Harbor tasks that need per-agent environments, configurable roles, shared findings, and run-level usage tracking. Skip if: You need only one coding session or independent trials, or require stable interfaces, confirmed commercial licensing, or a verified fully offline deployment.

## Overview
```text
### Architecture & Core Mechanics
Legion adds team orchestration around Harbor: each agent runs as a Trial in its own container, while Legion launches agents, maintains their sessions, and reports progress and model usage. Specs define the task, model endpoint, team size, and role instructions. The mini-swarm configuration demonstrates that the controller and worker can run locally while agent execution and the message board run on separate hosted services.

The Python 3.12+ stack declares Typer, Pydantic, PyYAML, FastAPI, and Uvicorn, and pins `harbor[e2b]` to `0.25.0` and `msgboard[hf]` to a Git commit. The extension point is a Python module exposing a `TOOLS` mapping. Legion packages the selected functions for agents and describes them in their instructions; a tool list in the spec replaces the default board tools rather than extending them.

### Key Capabilities & Differentiators
Teams can share instructions through `team_file` or specialize through `agents.roles`; supported coding harnesses are Pi, Codex, and Claude Code. A spec loop can send prompts automatically, or an operator can target a role with `legion prompt --swarm my-team --type agent`. Model calls can use Hugging Face Inference Providers or an OpenAI-compatible endpoint you operate.

The message board lets agents exchange findings without sharing a task container. The four-agent escape-room example uses separate task copies with one board; ProgramBench adds a shared Hugging Face repository for exchanging code. Tasks can be selected from a Hugging Face dataset at a pinned revision. For local runs, `legion status` shows state and usage, and the run bundle under `.legion/` supports later inspection of outcomes and rewards from Python.

### Trade-offs & Limitations
Use Harbor directly for independent trials, or run Pi, Codex, or Claude Code directly for a single interactive coding session. Legion earns its extra operational layer when separate agents need coordinated roles, shared findings, and team-level run visibility. Containers separate task environments, but shared boards and repositories still need access controls, and the inference credential enters every agent container.

For hosted runs, scope inference separately from infrastructure permissions and include both sandbox and inference charges in cost estimates. Stopping a mini-swarm run does not delete its board Space; clean up only a Space created for that run, after its workers stop. CLI, spec, and API changes can break integrations without deprecation, so pin a Legion commit and test upgrades against representative specs. Licensing is unspecified and should be resolved before commercial adoption.

### Hardware & Deployment Guide
Install with Python 3.12+, Git, and `uv`, then use `uv sync` and `uv run legion`. Rootless Podman is the default task-container backend; Docker with Compose is supported for local runs only. Hugging Face Jobs and Slurm are execution options, and the root contains `Dockerfile.controller` and `Dockerfile.worker`. The mini-swarm path needs neither local container engine: its controller and worker run locally, agents run in paid HF Sandboxes, and the board runs on a Space.

The local Docker quickstart requires no Jobs or Space permissions, but private Hub tasks still require Hub read access and model calls require a reachable inference endpoint. Self-hosting does not by itself establish a fully offline deployment. Size task compute for the chosen images and concurrent agents, and size model serving separately if you host it. The manifest version is `0.0.1`, no latest release is listed, and `docs/migrations.md` maps the former Flock names and breaking spec changes.
```

## Key Capabilities
```text
- Execution unit: Each agent runs in its own container as a Harbor Trial; the manifest pins `harbor[e2b]==0.25.0`.
- Role configuration: `team_file` supplies shared instructions, while `agents.roles` defines distinct roles using Pi, Codex, or Claude Code.
- Task versioning: `task.repo`, `task.revision`, and `task.selector` locate and pin a Harbor task independently of Legion code.
- Tool selection: Spec entries such as `message_board.*` and `calculator.add` select Python tools; an explicit list replaces the defaults.
- Observability: `legion status` reports agent state and model usage; local runs persist logs and a run bundle under `.legion/`.
- Credential isolation: The HF Sandbox configuration rejects `HF_TOKEN` as the inference key; agents receive a separately scoped inference credential.
```

## Quick Start / Clone
```bash
git clone https://github.com/huggingface/legion
cd legion
uv sync
```
