watsonx Assistant

 View Only

 Accessing Context in Actions

Claire Berry's profile image
Claire Berry posted Tue March 25, 2025 12:27 PM

I am building a slack bot with an IBM Watson X Assistant. I am sending some details to IBM Watson in the context in my python code, and I am wondering how I access these values in the "Actions" section of the watsonx assistant. I have this working currently in the dialog section of watson, but I am trying to move to using just actions.

Please see screenshots below of the section of my code which sends the message from my slack bot to the assistant. The commented out section is the old code that works in the dialog version of this journey. And the new uncommented code is me trying to do similar in an action instead. I was referring to this document for the structure of this context: Tutorial: Setting context variables for actions from the web chat

Ibm remove preview
Tutorial: Setting context variables for actions from the web chat
This tutorial shows how you can use the web chat to set the values of context variables that your actions can access.
View this on Ibm >


I have also attached a screenshot below of the 2 watson assistants, the left being the actions only one, and the right being the one that uses dialog too. Is there another way I should be pulling these variables from the context to set in my action?

Is what I am trying to do possible? Am I doing something wrong? Or are actions more limited when it comes to this?

Thanks,
Claire

Here you can see the old code where it works in the dialog section commented out
On the right, you can see where I can pull these details from the context. And on the right I am trying to do similar in an action step, but not succeeding
Josejulio Martínez's profile image
Josejulio Martínez

Hello,

I was also interested in this feature, to make it work I had to create the variable in:

> Actions -> Variables -> Created by you.

Once you create a variable there, it gives you a "Variable ID" which is the identifier you can send in your request.

For example:

I created this draft variable:

I'm sending it like this:

And I'm able to use it in a condition as a Session variable:

or even in the "Assistant says" input: