Installation

View Source
  1. Add :legion to your dependencies in mix.exs and run mix deps.get:
def deps do
  [
    {:legion, "~> 0.5"}
  ]
end
  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.4", 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

  • Give agents tools and run them: Usage
  • Pick a language and trust model for generated code: Sandboxes
  • Persist conversations across restarts with Legion.Store.Postgres, whose table is created by Legion.Store.Postgres.Migration.up() in a migration
  • Monitor agents in a LiveView dashboard: legion_web