What the runtime hands an action
The action in lesson 16 asked for a parameter called context and got one. Nothing in the Colang said so. The runtime fills parameters by name, and knowing which names it knows is most of what makes actions easy to write.
Printing what arrives
import pretend_nemo
from nemoguardrails import LLMRails, RailsConfig
from nemoguardrails.actions import action
@action(name="peek_context")
async def peek_context(context: dict):
print(sorted(context))
return True
rails = LLMRails(RailsConfig.from_path("."))
rails.register_action(peek_context, "peek_context")
rails.generate(messages=[{"role": "user", "content": "Where is my order?"}])user_message is the one an input rail almost always wants. last_bot_message is what the assistant said last turn, which is what makes a rail able to notice a repeated refusal. triggered_input_rail names the flow that is running, and input_flows is the whole list from config.yml.
An output rail sees a different set, with bot_message in it. That is lesson 21.
Named parameters from Colang
define flow order status
user ask order status
$status = execute lookup_order(order_id="A17")Anything in the brackets is passed by name, so this calls lookup_order(order_id="A17"). Values may be Colang variables too, written with a $, and lesson 25 uses that to pass one action's result into the next.
The parameters the runtime owns
| Name | What it is |
|---|---|
context | The conversation variables, as a dictionary |
events | The raw event list for this turn |
llm | The main model, so an action can ask it something |
llm_task_manager | Renders a named prompt, the way self check input does |
config | The whole RailsConfig |
Ask for the ones you need and leave the rest out. A parameter the runtime does not recognise is expected to come from the Colang call, and if it is not there the action raises.
- Action parameters are filled by name, not by position.
contextcarriesuser_messageon the way in andbot_messageon the way out.execute name(x=...)passes your own arguments alongside.
- Add
eventsto the signature and printlen(events). - Ask for a parameter called
nonsenseand read the error.
You understood something today that you didn't yesterday.