Installation

View Source

Legion needs Elixir 1.18 and Erlang/OTP 26 or later.

  1. Add :legion to your dependencies in mix.exs and run mix deps.get:
def deps do
  [
    {:legion, "~> 0.6"}
  ]
end

To serve agents over MCP, add {:anubis_mcp, "~> 2.0"} too; see the MCP guide.

  1. Legion instances are isolated supervision trees and should be included in your application's supervisor to run:
# lib/my_app/application.ex
children = [
  MyApp.Repo,
  Legion
]
  1. Configure an LLM provider. The default model is "openai:gpt-5.6-luna", so an OpenAI key is enough to start (all options):
# config/runtime.exs
config :req_llm, openai_api_key: System.get_env("OPENAI_API_KEY")
  1. Verify the setup in iex -S mix:
defmodule PingAgent do
  @moduledoc "Answers trivial questions."
  use Legion.Agent
end

Legion.execute(PingAgent, "Return the sum of 2 and 2")
#=> {:ok, "4"}

Next steps