rich kopelow
V.I.P
Posts: 47
Joined: Thu Aug 25, 2016 7:45 am

Dynamic SIML eventing

Mon Aug 27, 2018 1:31 am

I'm trying to launch an event (action) that might exist in my SIML. I have code that can safely launch the action, but (as I discussed in my last post) Actions don't return responses. So how can I have code "call into" SIML and allow that SIML to generate a response (to be added to any current response.)
What I'm doing now:

...
SafeInvokeAction(result.Bot,$"blah.{gd.Name}.start",context, result);
...

public static bool SafeInvokeAction(OscovaBot bot, string action, Context context, Result result)
{
bool res = false;
if(bot!=null && bot.Actions.Contains(action))
{
bot.Actions[action].Invoke(context, result);
res = true;
}
return res;
}

But this cannot add anything to the response. I guess I could really hack things up by creating a user variable and set it equal to the result of the SIML, but that seems kludgy.

If the "result" of evaluating all of the SIML was available I might be able to do something with that. Which may mean writing a wrapper adapter, evaluating all of the sub-nodes and then forcing the resulting value into a user variable?

<Action ID="blah.Convo.start">
<x:GatherResponse Result="blah.Convo.start.result">
Starting up the Convo.
<x:InitSomeStuffandReturnErrorIfAny />
</x:GatherResponse>
</Action>
Gather response would then need to save this off somewhere (user settings: blah.Convo.start.result) to be retrieved by the invoking call.
Any thoughts? I'm hoping there is a better way within the framework that I'm just not aware of.

Thanks,
Rich.

User avatar
Leslie
Lead Software Architect
Posts: 353
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Re: Dynamic SIML eventing

Mon Aug 27, 2018 12:55 pm

I feel this post reminisce your previous post "Building single response from several actions" a bit, so I will try to answer both the posts here. If you feel to add something to your previous post please update it here.

Actions can enable re-usability of subroutines via IDs. At times one can use an Action, instead of a fully implemented adapter, to perform identical tasks.

In many of my projects I've used back-end Action implementations for calling subroutines that I might regularly use throughout development and in other cases to store redundant responses to the newly introduced Trait(s) feature.

My personal recommendation is that back-end implementations of Action(s) shouldn't generate a response. Otherwise, it would simply defeat re-usability in many different scenarios and inject an overhead of dealing with whatever response that gets generated.

So to answer the question in your previous post, Yes your approach is all good as it is conventionally encouraged to create and use an Adapter when a subroutine needs to generate a response.

Actions can also go global within SIML as well. So to address your case, if I've understood it correctly, I might take a slightly different approach as shown below.


SIML Code

<!--Goes within SIML-->
<Action ID="SomeAction">
  <Response>
    <Action ID="blah.Convo.start"/>
      Starting up the Convo.
    <InitSomeStuffandReturnErrorIfAny />
  </Response>
</Action>

<!--Goes within a Dialog-->
<Intent Name="FooBar">
  <Expression Value="someverb @objects" />
  <Action ID="SomeAction"/>
</Intent>

rich kopelow
V.I.P
Posts: 47
Joined: Thu Aug 25, 2016 7:45 am

Re: Dynamic SIML eventing

Tue Aug 28, 2018 3:09 am

Thanks for your reply. You nailed the other post perfectly and they are related, but maybe I should explain this one better.

I have code that is running and I would like to fire events from that code back into SIML. The idea being that the I want to afford the SIML author the opportunity to add some functionality or response. I know that I can call an Action from inside an Adapter. My hope was that there was some way I could call back into SIML and "run" some SIML code.

I would also like to be able to trigger this from outside and adapter, but I can't figure out how to create a Result object to pass into the Invoke call.

To make this clearer, I would like to able to trigger an Action (or something else in SIML) to run every time there is any request. (I don't know of a way to forcibly trigger an intent.)

Thanks,
Rich.

User avatar
Leslie
Lead Software Architect
Posts: 353
Joined: Fri Sep 14, 2012 12:20 pm
Contact: Website

Re: Dynamic SIML eventing

Fri Aug 31, 2018 4:25 am

Indeed, triggering an SIML action outside an AdapterNode or Intent is going to be a bit difficult. Usually triggering an SIML action, something like what's shown below will require you to pass a Result object.


CSharp Code

Bot.Actions["SomeAction"].Invoke(SomeUser.Context, RESULT?);

SIML Code

<Action ID="SomeAction">
  <Response>
    Say something to the user.
  </Response>
</Action>


I do not see a legitimate way of doing it as the CurrentIntent property on Result object wouldn't be available to the Bot. So probably for the meantime you can resort to variables.

I tried checking what's coming up in the next iteration of Syn.Bot framework. The only useful commit in your case, I see, is the availability of a new property called CurrentResponse in AdapterNode.

rich kopelow
V.I.P
Posts: 47
Joined: Thu Aug 25, 2016 7:45 am

Re: Dynamic SIML eventing

Sat Sep 01, 2018 2:18 am

Leslie, thanks again for your feedback. It is always good to talk things out.
I have a much better sense of my problem now. There are two different cases.
1) Executing an action that returns a response (only reasonable from inside an adapter node with a result tag/result variable).
2) Executing an action that doesn't return a response, but manipulates user data (reasonable any time that context is available).

The first is all good.
The second doesn't seem to be possible. I will take that to the feature suggestion board. In addition to a language bot, you have created a scripting engine. It would be a drag to have to implement a second one to deal with activity that the bot author could do in SIML, outside of a specific intent. There are cases when some code should run, like at the beginning of an utterance or at the end of one, regardless of what dialog/result triggers. It would be great if the application could fire some SIML action that doesn't return a response at these times.

As an aside I tried to create an action without a result and found that when the SIML is read, that action simply doesn't show up in the actions collection.
<Action ID="test.action">
<If User="thing" Value="0">
<something that doesn't return a response />
</If>
</Action>

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest