Legion.Executor (Legion v0.5.0)

View Source

Drives the LLM thinking loop for a single agent turn.

Given a complete message history, calls the LLM, parses its response, runs sandboxed code if needed, and recurses until the LLM signals completion.

Returns the final result and updated message history so the caller can persist context across turns.

Summary

Functions

Builds a conversation message stamped with its :type and creation time (:at, milliseconds). The extra keys ride along into persisted state so consumers (e.g. LegionWeb) can classify messages without parsing content; ReqLLM ignores them.

Functions

message(type, content)

Builds a conversation message stamped with its :type and creation time (:at, milliseconds). The extra keys ride along into persisted state so consumers (e.g. LegionWeb) can classify messages without parsing content; ReqLLM ignores them.

run(agent_module, messages, config, bindings \\ [], executor_state \\ :nonexistent)

Runs the LLM loop against the given message history.

messages must already include the system prompt and the current user message. bindings seeds the code-evaluation binding. executor_state resumes a step checkpoint when present: :awaiting_llm continues from its saved iteration and retry counters, while :completing finishes without another LLM request. Pass :nonexistent (the default) to start a new loop. :turn_usage is the complete, ordered list of usage maps returned by LLM requests in the current turn.

Returns {:ok, result, messages, bindings, turn_usage} or {:cancel, reason, messages, bindings, turn_usage}.