Instruction Node¶
NodeType = Instruction (wire ordinal 5)
Attaches a named instruction string to the current interaction as a
slot.
A downstream Generate node can reference it inside a
Mustache template via the
{{#instructions}} list or the {{slot.<name>}} direct lookup.
The node itself does not call a model and does not modify the
conversation history that the model sees. It only adds a
kind=Instruction SlotComponent to the current turn's interaction
data, which the projection stage picks up when rendering the Generate
node's template.
Parameters¶
| Param | Type | Default | Range | Structural | Description |
|---|---|---|---|---|---|
instruction |
Optional[str] (multiline) | inherit model default | — | — | The instruction text. Mutable. |
output_name |
Optional[str] | inherit model default | — | ✓ | Name this node's output slot is stored under. Empty = the node's own name. Downstream templates look it up via slot. |
Exits¶
Each exit is a structural string field on the node's params; its value names the target node (empty = END).
| Exit | Param field | Description |
|---|---|---|
default |
default_exit |
Default exit target after attaching the instruction. Empty string = END. |
Exit routes¶
| Exit | Condition |
|---|---|
default |
Always taken after the instruction is attached. |
Mustache exposure¶
Given a node named greeter with instruction = "Welcome the user.":
| Template expression | Renders to |
|---|---|
{{slot.greeter}} |
Welcome the user. |
{{#instructions}}{{name}}: {{text}}{{/instructions}} |
greeter: Welcome the user. |
Multiple Instruction nodes in one graph each contribute one entry to
the {{#instructions}} list, in the order they executed.
Example¶
from copy import deepcopy
from tryll_client.graph import GraphDescription, InstructionParams, GenerateParams, Placement
greeter_baseline = InstructionParams(
instruction="You are a friendly greeter. Welcome the user warmly.",
default_exit="generate",
)
graph = (
GraphDescription()
.add_node("greeter", greeter_baseline)
.add_node("generate", GenerateParams(
template="{{slot.greeter}}",
placement=Placement.BeforeUserAsSystem,
default_exit="", # empty = END
))
.set_start_node("greeter")
.set_default_model_name("Llama 3.2 3B Instruct (Q4_K_M)")
)
agent = client.create_agent(graph)
# Change the instruction without recreating the agent:
p = deepcopy(greeter_baseline)
p.instruction = "You are a stern librarian."
agent.change_params("greeter", p)
using namespace Tryll::Client;
using namespace Tryll::NodeParams;
InstructionParamsT ip;
ip.instruction = "You are a friendly greeter. Welcome the user warmly.";
ip.default_exit = "generate";
InstructionParamsT greeterBaseline = ip; // keep a copy for mutations
GenerateParamsT gp;
gp.template_ = "{{slot.greeter}}";
gp.placement = ::Tryll::Placement::BeforeUserAsSystem;
// gp.default_exit = ""; // empty = END (the default)
GraphDescription graph;
graph.AddInstruction("greeter", std::move(ip))
.AddGenerate("generate", std::move(gp))
.SetStartNode("greeter")
.SetDefaultModelName("Llama 3.2 3B Instruct (Q4_K_M)");
auto agent = client.CreateAgent(graph);
// Change the instruction without recreating the agent:
InstructionParamsT mutated = greeterBaseline;
mutated.instruction = "You are a stern librarian.";
agent.ChangeParams("greeter", std::move(mutated));