# Custom action set slot

**URL:** <https://forum.rasa.com/t/custom-action-set-slot/4169>\
**Category:** Rasa Open Source\
**Created:** [January 9, 2019, 12:57pm UTC](https://forum.rasa.com/t/custom-action-set-slot/4169 "2019-01-09T12:57:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![reedsch](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/reedsch/32/1548_2.png) [@reedsch](https://forum.rasa.com/u/reedsch)\
**Post date:** [January 9, 2019, 12:57pm UTC](https://forum.rasa.com/t/custom-action-set-slot/4169/1 "2019-01-09T12:57:21Z")

</div>

Hi, a simple question here: is the only way to set a slot value in a custom action is at the return?

def run(self, dispatcher, tracker, domain): return [SlotSet(“make”, “honda”)]

Can I not set the slot value in the body of the run() method?

```
def run(self, dispatcher, tracker, domain):
   SlotSet("make", "honda")
   dispatcher.utter_message("OK") 
   return[]

```

or:

```
def run(self, dispatcher, tracker, domain):
   tracker._set_slot("make", "honda")
   dispatcher.utter_message("OK") 
   return[]

```

In both of these code examples, the value of the “make” slot in any later utterances is ‘None’

Thanks!

---

<div class="post-metadata">

**Author:** ![MetcalfeTom](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/metcalfetom/32/1422_2.png) [@MetcalfeTom](https://forum.rasa.com/u/MetcalfeTom)\
**Post date:** [January 18, 2019, 4:35pm UTC](https://forum.rasa.com/t/custom-action-set-slot/4169/2 "2019-01-18T16:35:09Z")

</div>

Hi @reedsch,

Thanks for your post! I take it you are using an action endpoint for this? Because the line `tracker._set_slot("make", "honda")` will set the tracker’s slot on the _action endpoint side_ only. The “real” tracker on core’s side only gets updated by the events which are passed back from the `action.run()` call ([see the processor code](https://github.com/RasaHQ/rasa_core/blob/master/rasa_core/processor.py#L341))

I like your curiosity though

---

<div class="post-metadata">

**Author:** ![PatrickDS](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/patrickds/32/4515_2.png) [@PatrickDS](https://forum.rasa.com/u/PatrickDS)\
**Post date:** [February 26, 2019, 10:11am UTC](https://forum.rasa.com/t/custom-action-set-slot/4169/3 "2019-02-26T10:11:15Z")

</div>

To both of you (Tom and the OP) : would it work if you set the slot in the tracker in the action endpoint, and then type

dispatcher.utter\_template(“utter\_example\_template”, tracker)

if the example template I put there has a slot in its string? (I am referring to when a string is something like “Hey there, {name}!” and there is a slot & entity called “name”)

Would the same work with utter\_message instead of utter\_template?

dispatcher.utter\_message(“Hey there, {name}!”, tracker)

Although I would agree that the second version is not that useful since you can extract the slot from the current tracker, but… always good to know 🙂

---

<div class="post-metadata">

**Author:** ![kabeer](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/kabeer/32/5310_2.png) [@kabeer](https://forum.rasa.com/u/kabeer)\
**Post date:** [December 2, 2019, 9:30am UTC](https://forum.rasa.com/t/custom-action-set-slot/4169/4 "2019-12-02T09:30:30Z")

</div>

@reedsch, have you found any answer. i am slso facing same situation.

---

<div class="post-metadata">

**Author:** ![chris.chu](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chris.chu/32/15483_2.png) [@chris.chu](https://forum.rasa.com/u/chris.chu)\
**Post date:** [June 23, 2021, 7:10pm UTC](https://forum.rasa.com/t/custom-action-set-slot/4169/5 "2021-06-23T19:10:27Z")

</div>

i also have the same issue

---

<div class="post-metadata">

**Author:** ![solyarisoftware](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/solyarisoftware/32/8464_2.png) [@solyarisoftware](https://forum.rasa.com/u/solyarisoftware)\
**Post date:** [July 14, 2021, 3:52pm UTC](https://forum.rasa.com/t/custom-action-set-slot/4169/6 "2021-07-14T15:52:02Z")

</div>

Hi @reedsch

doesn’t your first code chunk works? It should! See [https://stackoverflow.com/a/57471253/1786393](https://stackoverflow.com/a/57471253/1786393)

Giorgio

---

<div class="post-metadata">

**Author:** ![jonathanpwheat](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/jonathanpwheat/32/4880_2.png) [@jonathanpwheat](https://forum.rasa.com/u/jonathanpwheat)\
**Post date:** [July 15, 2021, 1:19pm UTC](https://forum.rasa.com/t/custom-action-set-slot/4169/7 "2021-07-15T13:19:29Z")

</div>

If you want to interact with the slots you set on the Action server side, you actually need to return them back to the Rasa server. There are two ways to do this

```auto
def run(self, dispatcher, tracker, domain):
   dispatcher.utter_message("OK") 
   return[{"make", "honda"}]

```

```auto
def run(self, dispatcher, tracker, domain):
   dispatcher.utter_message("OK") 
   return[SlotSet("make", "honda")]

```

---

<div class="post-metadata">

**Author:** ![AWeheid](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/aweheid/32/15842_2.png) [@AWeheid](https://forum.rasa.com/u/AWeheid)\
**Post date:** [February 17, 2022, 10:56am UTC](https://forum.rasa.com/t/custom-action-set-slot/4169/8 "2022-02-17T10:56:14Z")

</div>

This may help you :

> [@Setting Slots outside the Action Class when Using Rasa SDK](http://forum.rasa.com/t/setting-slots-outside-the-action-class-when-using-rasa-sdk/20504/2):
>
> I solved my issue, for anybody that is interested in the answer, the code goes as follows: from rasa.core.channels.channel import UserMessage from rasa.core.events import SlotSet dst = agent.tracker\_store.get\_or\_create\_tracker(UserMessage.DEFAULT\_SENDER\_ID) ss = SlotSet('username', 'Alex') dst.update(ss) agent.tracker\_store.save(dst)
