Legion.Tools.HumanTool (Legion v0.5.0)

View Source

Built-in tool for asking a human a question mid-execution.

Configuration

Configure via tool_config/1 in your agent:

def tool_config(Legion.Tools.HumanTool) do
  [handler: MyApp.ChatHandler, timeout: 30_000]
end

Options:

  • :handler (required) — a pid or registered name that receives {:human_request, ref, from_pid, question, meta} and must send {:human_response, ref, answer} back to from_pid.
  • :timeout — milliseconds to wait for a response. Defaults to :infinity.

ask/1 blocks inside the code evaluation, so the agent's sandbox_timeout (60 seconds by default) still applies and kills the eval regardless of this setting. Raise it, or set it to :infinity, for agents that wait on humans.

Usage (for LLM agent)

HumanTool.ask("What format do you prefer?")

Summary

Functions

Asks a human a question and blocks until they respond.

Callback implementation for Legion.Tool.description/0.

Functions

ask(question)

Asks a human a question and blocks until they respond.

Returns the human's answer as a string.

Only works under eval_and_continue - the answer comes back to you as the eval result so you can act on it. Under eval_and_complete the turn would end the moment this code returns and the answer would be discarded, so ask/1 raises there.

description()

Callback implementation for Legion.Tool.description/0.

extra_allowed_modules()

Callback implementation for Legion.Tool.extra_allowed_modules/0.