Triggering and calling a form action from another function

Hi there, I’m using Rasa 1.10.24. I really google’d and searched for the answer but I couldn’t find. I’m trying to call form action from another function. (I’m not looking to call it from another custom action as I know how to do it, also, it won’t be in any story) Then I’ll get slot values and send a post request, this is what I have in mind:

 action_form() #call the custom action
 slot = tracker.get_slot("slot1"), body={"slot1":slot}

At the submit I might return the slots themselves then it might look like this: slot1, slot2 = action_form()

This might look really messy though but I’m just trying to explain what I want to do. Any help is appreciated

Forms work a bit differently in 1.10 and I should admit: I only started using forms in 2.x so my advice here might be limited.

That said, I experience a form as a loop that is triggered in a conversation. Just like a custom action is an event in a conversation, so is this loop. I’m a bit hesitant to control the triggering of these events manually with a lot of logic because that’s what we have dialogue policies for. It might be that I’m not understanding the question though.

to call form action from another function

When you say “another function” here, do you mean a custom action or an external python function?

Is there a reason why you cannot fix this with stories?

I have this function that checks out if user accepted agreement or not, and prompts few buttons after that, and then I want it to call form action. So form will not be triggered with an intent (thus story). I get your point that I shouldn’t be hard coding it but the reason why I’m using form is because I want the bot to make the distinction between a regular user input and an input that will go to the DB (a slot).

I think I’ll redefine action_session_starts for this as I’m checking it when the session starts and then call form action as a follow-up action instead. Do you think that would work?

Technically, you can also use the availability of a slot value in your stories. Slot values are used in TED to predict the next action, so given enough training data you should be covered. The “given enough training data” is tricky to get right though.

As a rule of thumb, my school of thought is “whats the simplest thing that we can varify”. In your case, if it’s really more of a “did you accept our agreement” … then you could see if you can handle this with custom actions since it might be simpler than a form. You only seem to be asking for the contents of a single slot and generating a custom response for either situation.

So instead of a slot, you’re saying that I should use a custom action:

dispatcher.utter_message("question about the slot")
tracker.get_slot(user input)

My problem with this is that I’m going to ask two subsequent questions and they’re open ended so I’ll do .from_text(). I think I can solve it like that. (fingers crossed) Thanks!

Ah pardon, I thought it was a single question and a single slot. In that case, you might need to go with a form.

Let me know!

Hello Vincent, I need the form to appear at the beginning of the chat. So what I thought was to overwrite the action_session_start and then do a followup action with a form. I have no intent to trigger this and I already have tons of intents to I didn’t want to create one, another thing I thought was to create an intent, map it to FormAction and then trigger it with UserUttered instead, but again, we have a generic bot, I don’t want user inputs to be classified as that intent and mess things up. Another thing I thought I could do is to write a custom action instead since slots will be mapped to .from_text() so there’s no problem with slots being not filled.

I’ve given up and created a mock intent and used agent.trigger_intent() in another function instead. I haven’t tested yet though, I’ll see how it goes. I thought agent.execute_action() could be useful but from docs I didn’t exactly get what it was doing.