View Source Agens.Prefixes (agens v0.2.0)

The Prefixes struct is used to configure prompt prefixes for building advanced prompts.

For each field used in the prompt (based on the configuration of Servings, Jobs, and their Nodes), a heading will be added, as well as some additional detail.

For example, if you are running an Agens.Job and have defined an objective for the current Agens.Job.Node, the following will be added to the prompt:

## Node Objective

The objective of this node is to {{node.objective}}

However, if you have not defined an objective for the current Agens.Job.Node, the heading and detail will also be omitted.

Default prefixes are returned by default/0. To customize, build an %Agens.Prefixes{} struct and set it on the :prefixes field of Agens.Serving.Config. To share custom prefixes across many Servings, define a module that returns the struct and reference it from each Serving's Config.

Fields and Sources

Each field maps a prompt section to a value sourced from the running Agens.Message. Fields with nil/empty values are omitted from the final prompt entirely.

FieldSource
contextAgens.Serving.load_context/2 (derived from agent_id)
objectiveAgens.Job.Node.objective
descriptionAgens.Job.Config.description
inputThe original value passed to Agens.Job.run/3 (never overwritten across Nodes)
previous_resultThe result of the previous Node in the Job (nil on the starting Node)
schemaJSON schema built from the Router's declared outputs/1 (plus response/tool-call shape)
retryValidation/retry reason when re-running a Node
tool_defsAgens.Job.Node.tools (MCP-style tool schemas)
tool_callsTool call requests emitted by the LM in the previous turn
tool_resultsResolved tool-call results merged back from Agens.Serving.tool_call/3
resourcesLoaded Agens.Resource content (from Agens.Serving.load_resource/3)

Note:

Depending on your use case, some fields may be more relevant than others. It's often beneficial to be more descriptive at granular levels (Node objective, Router outputs) while taking a more minimal approach at higher levels (Job description).

Summary

Functions

Returns the default Agens.Prefixes struct used when a Serving's Agens.Serving.Config.prefixes is nil.

Types

@type pair() :: {heading :: String.t(), detail :: String.t()}
@type t() :: %Agens.Prefixes{
  context: pair(),
  description: pair(),
  input: pair(),
  objective: pair(),
  previous_result: pair(),
  resources: pair(),
  retry: pair(),
  schema: pair(),
  tool_calls: pair(),
  tool_defs: pair(),
  tool_results: pair()
}

Functions

@spec default() :: t()

Returns the default Agens.Prefixes struct used when a Serving's Agens.Serving.Config.prefixes is nil.

Customize by building your own struct (typically starting from this default and overriding select fields) and setting it on the relevant Agens.Serving.Config.