1. Template Techniques
  2. Async Execution Actions

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."

  1. On the AI Enabled action in the conversation flow, use a sendaction task to trigger the execution of the long running action. eg generate_banner_image action is triggered.
  2. In the AI Inject data note to the calling agent that the task is queued and busy
  3. The conversational agent can resume interaction with the user
  4. Once the triggered action is complete it again can use a sendaction to pass the results back to the calling stub. eg receive_image_result action.
  5. 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.