Legion.AgentServer (Legion v0.4.0)

View Source

GenServer that maintains conversation history for a long-lived agent.

Holds the message history across multiple turns. Each call or cast appends the user message and runs Executor to completion (blocking).

Summary

Functions

Returns a specification to start this module under a supervisor.

Normalizes message, appends it to the conversation, and runs the executor to completion. Returns {{status, value}, new_state}.

Functions

call(agent, message, timeout \\ :infinity)

cast(agent, message)

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_messages(agent)

handle_message(message, state)

Normalizes message, appends it to the conversation, and runs the executor to completion. Returns {{status, value}, new_state}.

Accepted message shapes:

  • binary - passed verbatim as the user message
  • {:image, data, media_type} - single inline image from binary data
  • {:image_url, url} - single image from a URL
  • {:multipart, [ContentPart.t()]} - mixed text/image/file content; build parts with ReqLLM.Message.ContentPart.text/1, image/2, image_url/1, file/3
  • anything else - rendered via inspect/2

start_link(agent_module, opts \\ [])