# How to use tracker in a custom class and call custom function in an action class?

**URL:** <https://forum.rasa.com/t/how-to-use-tracker-in-a-custom-class-and-call-custom-function-in-an-action-class/4061>\
**Category:** Rasa Open Source\
**Created:** [January 5, 2019, 11:15am UTC](https://forum.rasa.com/t/how-to-use-tracker-in-a-custom-class-and-call-custom-function-in-an-action-class/4061 "2019-01-05T11:15:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cwying817](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/cwying817/32/8386_2.png) [@cwying817](https://forum.rasa.com/u/cwying817)\
**Post date:** [January 5, 2019, 11:15am UTC](https://forum.rasa.com/t/how-to-use-tracker-in-a-custom-class-and-call-custom-function-in-an-action-class/4061/1 "2019-01-05T11:15:52Z")

</div>

I would like to use tracker in my custom actions. The tracker works well for the class taking Action as its parameter. However, Can I use tracker in my self-defined classes which are not taking Action/ FormAction as parameter?

Besides, can I add new function into the an action class? For example, if I define a function sum() in class ActionCalculation(Action), there will be an error saying “name ‘sum’ is not defined”. What can I to with this?

Thank you.

---

<div class="post-metadata">

**Author:** ![asokolow](https://avatars.discourse-cdn.com/v4/letter/a/5fc32e/32.png) [@asokolow](https://forum.rasa.com/u/asokolow)\
**Post date:** [January 16, 2019, 8:38am UTC](https://forum.rasa.com/t/how-to-use-tracker-in-a-custom-class-and-call-custom-function-in-an-action-class/4061/2 "2019-01-16T08:38:13Z")

</div>

Hi there,

> [@cwying817](#):
>
> ActionCalculation(Action)

Does not mean that Action is the parameter of ActionCalculation! it means that ActionCalculation inherits from Action class.

The entry point of your ActionCalculation is run(), inside this function you can call your custom function sum().

---

<div class="post-metadata">

**Author:** ![ricwo](https://avatars.discourse-cdn.com/v4/letter/r/7ea924/32.png) [@ricwo](https://forum.rasa.com/u/ricwo)\
**Post date:** [January 17, 2019, 8:17pm UTC](https://forum.rasa.com/t/how-to-use-tracker-in-a-custom-class-and-call-custom-function-in-an-action-class/4061/3 "2019-01-17T20:17:14Z")

</div>

Hi @cwying817, custom actions need to inherit from `Action` (`CustomAction(Action)`), and if you want to use the tracker it has to be in an action’s `run()` method. You can perform other calculations in your custom action. Here’s an example using a function called `get_sum()`:

```auto
from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet

def get_sum(x, y):
    return x + y

class CustomAction(Action):
   def name(self):
      # type: () -> Text
      return "custom_action"

   def run(self, dispatcher, tracker, domain):
      # type: (CollectingDispatcher, Tracker, Dict[Text, Any]) -> List[Dict[Text, Any]]

      a = tracker.get_slot('value_a')
      b = tracker.get_slot('value_b')

      result = get_sum(a, b)
      
      print("Do something with result {}".format(result))

      return [SlotSet("result", result)]

```
