View Source Agens.Message (agens v0.2.0)
The Message struct defines the details of a message passed between Jobs and Servings.
A Message accumulates context as it flows through a Job: it carries the user/previous-Node input, the prepared system/user prompts, the Serving's result, structured outputs, tool calls/results, resources, retry state, and the routing decision for the next hop.
Fields
Identity / lifecycle
:caller- The pid of the process that invokedAgens.Job.run/3. Backends receive this as their first argument so they can fan events back out to the right consumer.:id- Per-message identifier. Generated as a hex uid; set tonilafter a successful Node result so the next Node generates a fresh one.:run_id- The Job run identifier this message belongs to.:parent_run_id- When the message is part of a Sub-Job run, therun_idof the enclosing parent Job.:thread_id- Identifier of the parallel thread within the run. New threads are spawned when a:routeinstruction fans out withcount > 1.
Input / output
:input- The original input string passed toAgens.Job.run/3. Required (@enforce_keys). Carried forward unchanged across every Node in the run.:system- The prepared system prompt string, populated by the Serving'sAgens.Serving.build_prompt/3callback before inference.:user- The prepared user prompt string, populated alongside:system.:result- The Serving's response body for this Node.:previous_result- The:resultof the previous Node in the Job.nilon the starting Node; rolls forward on each:routetransition. Surfaced in the next prompt under thePrevious Resultprefix.:outputs- Map of structured outputs parsed from the Serving's response, keyed byAgens.Router.Output.key. Used byAgens.Router.resolve/2to determine routing.
Job / Node references
:job_id- The id of theAgens.Job.Configthis run is executing.:job_description- The Job's:description, added to the LM prompt under theJob Descriptionprefix.:node_id- The identifier of theAgens.Job.Nodecurrently being processed.:node_objective- The Node's:objective, added to the LM prompt under theNode Objectiveprefix.:agent_id- An opaque identifier passed toAgens.Serving.load_context/2. Not a process or first-class entity — just a hook for the Serving to resolve agent-specific context.:serving_name- The name of theAgens.Servingresolved from the Node's:servingfield; the target ofAgens.Serving.handle_message/3for this Node.
Tools / resources
:tool_defs- MCP-style tool schemas declared on the Node's:toolsfield, surfaced to the LM underTool Definitions.:tool_calls- Tool call requests emitted by the LM. When non-empty, the runtime invokesAgens.Serving.tool_call/3for each entry and re-runs the Node with results merged in.:tool_results- Map of resolved tool results keyed bytool_call["id"]. Surfaced to the LM underTool Resultson the retry prompt.:resources- List ofAgens.Resourcestructs declared on the Node, loaded byAgens.Serving.load_resource/3prior to inference and inlined underResources.
Retry / routing
:retries- The number of times this Node has been retried in the current run. Capped byAgens.Job.Config.max_retries.:retry_reason- Optional reason string for the most recent retry, surfaced to the LM underRetry.:next- List of routing instructions emitted by the Serving's Router ({:route, node_id, count},{:yield, node_id},{:sub, job_id},:end,:retry,{:retry, reason}). Drives the next hop in the Job graph.
Summary
Functions
Sends an Agens.Message to an Agens.Serving.
Types
@type t() :: %Agens.Message{ agent_id: binary() | nil, caller: pid() | nil, id: binary() | nil, input: String.t(), job_description: String.t() | nil, job_id: binary() | nil, next: [Agens.Serving.Result.next()], node_id: binary() | nil, node_objective: String.t() | nil, outputs: map() | nil, parent_run_id: binary() | nil, previous_result: String.t() | nil, resources: [Agens.Resource.t()] | nil, result: String.t() | nil, retries: non_neg_integer(), retry_reason: String.t() | nil, run_id: binary() | nil, serving_name: atom() | nil, system: String.t() | nil, thread_id: binary() | nil, tool_calls: list() | nil, tool_defs: list() | nil, tool_results: map() | nil, user: String.t() | nil }
Functions
Sends an Agens.Message to an Agens.Serving.