software-mansion/legion/install-legion
Claude Code and agent skill by software-mansion/legion
- community
Checking that the SKILL.md file is still in the repository.
Install Legion or legion_web into an existing Mix or Phoenix app. Use when asked to install, add, set up, wire or integrate Legion, an AI agent, or the Legion dashboard into an app that already exists.
Install
npx vskill@latest install software-mansion/legion/install-legionSKILL.md
The same SKILL.md was published earlier as software-mansion/legion/install-legion.
Install Legion into an existing app
Legion is one dependency, one supervisor child, an LLM key and a few plain modules next to the code the app already has. Nothing gets rewritten. The install is one reviewable diff: minimal edits, in the order below, nothing the user did not choose in step 0.
Steps 1, 2, 3, 8 and 10 run on every install. Steps 4 to 7 and 9 run only when the matching answer from step 0 is yes; each names its gate in its heading.
0. Look, then ask
Read, editing nothing yet:
mix.exs- is:legionalready there?:phoenix?:ecto_sqlwith
:postgrex? :ash? :igniter?
lib/*/application.ex- thechildrenlist, where the Repo sits.config/runtime.exs- an existingconfig :req_llm, <provider>_api_key
line. Config files only; .env, .envrc and other secret files stay unread.
lib/*_web/router.ex- the auth pipelines andlive_sessions, and
whether any of them admits admins only (phx.gen.auth gives :require_authenticated_user, which admits every signed-in user).
lib/<app>/- the contexts (orders, tickets, catalog) a tool could wrap.lib/*_web/live/,lib/*_web/controllers/,lib/<app>/workers/- the
entry points a message could reach the agent through: a chat or assistant LiveView, a support form, a webhook action, an Oban worker, a mix task.
git status- start from a clean tree so the install is one reviewable
diff.
Then interview the user: one question at a time, recommendation first, in this order. Offer a question only when its condition holds; otherwise say in one line why it is not offered.
- Provider and model. Recommend the provider already configured, else
OpenAI (default model openai:gpt-5.6-luna, no model line needed). Any other provider needs a model in ReqLLM's provider:model form.
- Store - Postgres Ecto repo present. Conversations survive deploys and
resume by id; costs one migration.
- Rate limiter - store = yes. Caps agents, tokens and code evaluations per user or IP on
the same table; meant for agents driven by untrusted users.
- Dashboard -
:phoenixpresent.legion_webshows every user's
prompts, generated snippets and results, so only admins may reach it - a plain signed-in check lets any customer read everyone's conversations. Choices: admin-only scope (needs a pipeline that admits admins only), dev-only block, skip. Recommend the dev-only block when the router has no admin pipeline.
- Tool context. List the contexts found, recommend the one the user's
request points at.
- Identity - asked after the tool context. Does the tool answer on
behalf of a signed-in user (their orders, their tickets)? Yes means the user's identity travels in Vault. No means a public tool, such as catalog search, and no Vault at all.
- Entry point - asked last. List the ones found, recommend the one the
user's request points at; step 9 wires the agent into it. None found: say so and ask whether to create one; yes means step 9 adds a minimal chat LiveView (a message list, a text input) at a route the user names. Skip means the agent stays callable from code only.
Done when: the plan (provider, model, each yes/no, context, entry point) is recapped and the user has confirmed it.
1. Dependency
Pin to the current release:
The sandbox stays on its default, Lua, which cannot reach the host BEAM.
Done when: mix deps.get succeeds with :legion as the only new entry in deps.
2. Supervisor child
Legion is a supervisor. Put it after the Repo (the store and the rate limiter query it, and Legion.Recovery, when configured, reads the store on boot); its position relative to the Endpoint does not matter.
Done when: Legion sits in children after the Repo.
3. LLM provider key
Runtime config only, never config.exs, never a literal key. The key name is <provider>_api_key. With OpenAI nothing else is needed:
Another provider needs its key and the chosen model:
If the app already loads .env through dotenvy or similar, follow that pattern instead of a bare System.get_env/1.
Done when: the chosen provider's key line is in runtime.exs and the user knows which environment variable to set.
4. Postgres store (store = yes)
Skip unless store = yes.
Done when: the migration ran and :store is configured.
5. Rate limiter (rate limiter = yes)
Skip unless rate limiter = yes. The store's table backs it, no extra migration.
The config holds the limiter and policy only. Rules naming the group go on every Legion.start_link/2 call (step 9); without them Legion logs a warning and runs unlimited. Identity keys are strings:
A denied turn returns {:cancel, {:rate_limited, violations}}. A start is checked against max_agents too: past it, Legion.start_link/2 returns {:error, {:rate_limited, violations}} with no agent started, and Legion.execute/3 returns {:cancel, {:rate_limited, violations}}. Legion.resume/2 is not checked.
Done when: the limiter module and :rate_limit config exist and the start_link/2 call in step 9 names its group.
6. Dashboard (dashboard = yes)
Skip unless dashboard = yes. Add the package the same way as step 1:
The dashboard shows every user's prompts, generated snippets and results, so the route lives inside the scope chosen in step 0. :browser plus a signed-in check is not enough.
With :igniter in the project, mix legion_web.install adds the import and a /legion route behind :browser alone; move that route into the chosen scope afterwards. Otherwise edit the router by hand:
Done when: :legion_web is a dependency and legion_dashboard sits inside the admin-only scope or the dev-only block, and nowhere else.
7. Identity (identity = yes)
Skip unless identity = yes. The app calls Vault itself, so it declares the package, the same way as step 1:
The app puts the signed-in user in Vault once, in the process that will start the agent, after its usual authentication:
Ash app: put the whole record in, Vault.init(current_user: socket.assigns.current_user), since policies read actor fields beyond the id. Generated code cannot read Vault, so the record never reaches the prompt. guides/ash.md covers the rest.
Vault.init/1 runs once per process subtree and raises on a second call, so when the app already calls it (grep -rn "Vault.init" lib/), add :current_user to that existing call. The agent inherits the Vault map when it is started from that process with Legion.start_link/2; generated code cannot read it.
Done when: :vault is a dependency, exactly one Vault.init site carries :current_user, and the agent starts under it in step 9.
8. First tool and agent
Write a small facade over the chosen context, not the context itself - the agent can call any public function of a tool.
Identity = no: the tool takes no user at all, for example def search(query), do: MyApp.Catalog.search(query).
Rules that keep this safe and cheap:
- Identity comes from
Vault.get(:current_user)inside the tool, never from
a tool argument.
- Return plain maps with the fields the agent needs. Tool results go into the
prompt, so a %User{} with a password hash has no business there.
- Arguments arrive from Lua as string-keyed maps and tuples come back as
lists. Match string keys in a tool.
- Keep irreversible actions (charging, deleting, sending) out of tools or
behind a confirmation step in the UI.
- Ash app: the tool calls the domain's code interface with
actor: Vault.get(:current_user) so policies keep applying.
Done when: one tool module and one agent module exist, the agent lists the tool, and the facade exposes only the functions the chosen context needs.
9. Entry point (entry point = yes)
Wire the entry point chosen in step 0 to the agent, or the chat LiveView agreed there. Its look and every other behaviour stay; only what happens to the message changes.
A LiveView starts the agent in its own process, under the identity of step 7 when identity = yes; a controller or a job runs it with Legion.execute/3 instead (below):
start_link/2 links the agent to the caller, so in a LiveView it dies with the socket. The gates from step 0 add to that call:
- Rate limiter = yes: pass
rate_limit: [rules: ...]from step 5, and
handle {:error, {:rate_limited, violations}} from start_link/2 where the handler shows errors today, so a refused start does not crash the caller.
- Store = yes: give the agent a stable
agent_id, or every start writes a
fresh conversation under a random id and nothing can be resumed. Legion.resume/2 brings a stored one back:
```elixir agent_id = "user_#{user.id}:support" # the rate_limit option when rate limiter = yes, else [] opts = []
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/install-legion/SKILL.md
Popularity
- 7-day trend score
- 5
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/software-mansion/legion/install-legion)