Template Techniques
Async Execution Actions
Explains how to run long-running work asynchronously so a conversational agent can continue responding to the user.
Some tasks on actions can take a long time to run. When used on a conversational agent this introduces a period of no response from the agent leading to a bad user experience.
Examples of Long-Running Work
- generation of an image using an LLM (generate_image)
- long and complex database or lookup queries
- using a separate LLM task to analyze chat history, or find answers to a question using the knowledge library
For these cases a good technique to use is async execution action.
Structure
Use a sendaction task to trigger another action that runs "out of band."
- On the AI Enabled action in the conversation flow, use a
sendactiontask to trigger the execution of the long running action. eggenerate_banner_imageaction is triggered. - In the AI Inject data note to the calling agent that the task is queued and busy
- The conversational agent can resume interaction with the user
- Once the triggered action is complete it again can use a
sendactionto pass the results back to the calling stub. egreceive_image_resultaction. - The result receiving action can inject into the LLM chat the results
Triggered Action Notes
- If the action is defined on the same context as the conversational agent it needs to be run as a bulk action and the action should be set to read only in order not to overwrite data on the stub
- If the functionality is general (eg. image generation) it is best to define the action on a separate context then create a single stub to be used to run the actions on. Again setting bulk action and read only so the action runs idempotently.
- On the AI enabled action, remember to pass a note to the calling agent to let it know that the task running and will return, so that it can inform the user.