Run actions to retrieve data before the LLM begins reasoning.
Place action calls at the top of your reasoning instructions to fetch data before the prompt is constructed. This ensures the LLM has access to current, accurate information when generating responses.
Why Use This Pattern
Fetching before reasoning ensures the LLM has accurate, current data. For example, you can store the output of an action in a variable and use it to personalize instructions. Or you can create a filter based on the variable to refine the prompt that’s sent to the LLM. Actions inside reasoning instructions execute before the prompt is sent to the LLM.
Pattern Example: Look up the user’s current order before the conversation starts so the agent can greet them with their order status and personalized recommendations.
Basic Pattern
Fetch Order Data
1reasoning:2 instructions: ->34 # Check if data has been fetched5 if @variables.order_summary == "":67 # If not, fetch data with an action8 # (and store results in a variable)9 run @actions.lookup_current_order10 with member_email=@variables.member_email11 set @variables.order_summary=@outputs.order_summary1213 # Reference the variable in the prompt14 | Refer to the user by name {!@variables.member_name}.15 Show them their current order summary: {!@variables.order_summary}.
The pattern:
Check if data has already been fetched
If not, run the lookup action
Store results in a variable
Reference the variable in the prompt
Fetch and Validate
Fetch data and immediately check it to determine what options to present.
Fetch and Validate Eligibility
1reasoning:2 instructions: ->3 if @variables.order_summary == "":4 run @actions.lookup_current_order5 with member_email=@variables.member_email6 set @variables.order_summary=@outputs.order_summary78 | If user wants to make a return:9 if @variables.order_summary.days_since_order <= 60:10 set @variables.return_eligibility = true11 | Offer to process return using {!@actions.create_return}.12 else:13 | Politely explain the return period has expired.
Tips
Avoid unnecessary calls: Always check if data exists (if @variables.data == "") before making a call to fetch data to avoid running actions unnecessarily.