Legion. Tool behaviour
(Legion v0.4.0)
View Source
use Legion.Tool to mark a module as a tool available to agents.
By default, description/0 returns the module's source code so the LLM
knows what functions are available.
Overridable
description/0— override to return a hand-written summary instead of the source code. Defaults to the module's source code.extra_allowed_modules/0— override to return additional modules that the sandbox should alias and permit when this tool is available. Defaults to[]. Useful for tools likeLegion.Tools.AgentToolthat dispatch to other modules the agent needs to reference by name.
Example
defmodule MyApp.WeatherTool do
use Legion.Tool
def description do
"""
WeatherTool — fetches current weather data.
## Functions
- `current(city)` — returns weather JSON for the given city name.
"""
end
@doc "Returns current weather for a city."
def current(city) do
Req.get!("https://wttr.in/#{city}?format=j1").body
end
end