clara-rules icon indicating copy to clipboard operation
clara-rules copied to clipboard

Support Focus/Agenda Groups

Open rbrush opened this issue 9 years ago • 5 comments

Support for focus (Drools uses the term agenda groups) has been brought up on the mailing list. [1]

I'm tempted to support this by treating Clojure namespaces as the group and adding a set-focus or similar function that pushes the focus of that namespace so its rules will fire ahead of any others. We would plug into a mechanism similar to how salience works, but rather than simply comparing salience values we'd check and order by the stack of modules in focus. [1] https://mail.google.com/mail/u/0/#inbox/14ce1a22b1ed8958

rbrush avatar Apr 23 '15 21:04 rbrush

What about a more general mechanism like Jess' Strategy - wouldn't that allow you to do the same thing?

We could install a strategy function into the session and that function could examine the activation's rules' namespaces to determine which gets priority/focus.

kahunamoore avatar Apr 23 '15 21:04 kahunamoore

Clara actually already supports something that is as expressive as Strategy in Jess, via the activation-group-fn and the activation-group-sort-fn described here:

https://github.com/rbrush/clara-rules/wiki/Conflict-Resolution-and-Salience#specialized-activation-groups

Basically the caller can provide their own sort function to order activations, much like a Strategy in Jess. (At some point we should expand that documentation with some examples to make it a bit more clear.)

Focus (in Jess) or Agenda Groups (in Drools) is a bit different in that it allows focus to dynamically pushed and popped, changing the ordering of activation on the fly.

rbrush avatar Apr 23 '15 21:04 rbrush

Clearly my Jess knowledge is rusty... it has been over ten years since I last used it. Even then, I never used Strategy, salience or focus/modules so my knowledge of those is badly lacking.

I just re-read the docs and it seems to me that if you don't use salience (in Jess) then every activation will necessarily involve a conflict resolution - at which point your Strategy will get a chance to define which rules fire before others (e.g. by controlling the sort order.) That decision could then take into account just about anything it knows about the rules/facts involved... or at least that is how I read it.

If this is true, a big if..., then it seems Clara's existing activation-group-sort-fn could do the same thing. Correct? Or is there something about this that I'm clearly misunderstanding :-\

kahunamoore avatar Apr 24 '15 01:04 kahunamoore

Yes, you're right. Clara could do that today with the activation-group-sort-fn a user can provide. But the user would need to implement and maintain a stack of focus groups (to work like agenda groups)...so this issue would basically do that work for them.

rbrush avatar Apr 24 '15 14:04 rbrush

Thanks for the clarification - I just want to make sure I understand the issue correctly. It sounds like a good idea and matches well with other engine's features, principle of least surprise and all that. Obviously I have a lot to learn about Clara but I'll get there... Thanks for your patience in this.

kahunamoore avatar Apr 24 '15 15:04 kahunamoore