Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Agent, Actions, Rules & Automation >> Action preventing update of subsequent agents
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1213742663

Message started by Loryn on Jun 17th, 2008, 6:44pm

Title: Action preventing update of subsequent agents
Post by Loryn on Jun 17th, 2008, 6:44pm

OK. So here's a puzzle.

My mental model of Tinderbox is that an Agent performs a query, returns results, and then executes the Agent Action against the results.

As mentioned elsewhere, I initially had code of the form:


Code:
Field1(agent) = count(collect_if(child,$TextFrom="Number1",$Name));
Field2(agent) = count(collect_if(child,$TextFrom="Number2",$Name));
Field3(agent) = count(collect_if(child,$TextFrom="Number3",$Name));
TermScore(agent) = ($Field1*2) + ($Field2*1) + ($Field3*0.5)


I then added a guard capability to limit execution of the code.


Code:
if( !(ComputedCount(agent)=$ChildCount(agent) | ComputedTotal(TermScoreTotaller)=$ComputedTotal(agent)) )
{
Field1(agent) = count(collect_if(child,$TextFrom="Number1",$Name));
Field2(agent) = count(collect_if(child,$TextFrom="Number2",$Name));
Field3(agent) = count(collect_if(child,$TextFrom="Number3",$Name));
TermScore(agent) = ($Field1*2) + ($Field2*1) + ($Field3*0.5);

ComputedCount(agent)=$ChildCount(agent); ComputedTotal(agent)=$ComputedTotal(TermScoreTotaller);
}


At first, I was elated at the speedup. Alas, I found that the use of this code made all but the first agent fail to query.

I think I could figure out what was going wrong if all but the first agent action failed to execute. But I can't understand how what I've written in this agent action could possibly prevent subsequent agents from querying.

:'(


Title: Re: Action preventing update of subsequent agents
Post by Mark Bernstein on Jun 18th, 2008, 10:19am

If an agent's action or query can't be parsed, Tinderbox may "give up" and stop evaluating agents, on the assumption that subsequent agents might be working with the wrong answers from the flawed agent.

Title: Re: Action preventing update of subsequent agents
Post by Loryn on Jun 18th, 2008, 6:13pm

Thank you, Mark!

Seems that I had to add a $ sign to the variables in the if test. Corrected and working code is:


Code:
if( !($ComputedCount(agent)=$ChildCount(agent) | $ComputedTotal(TermScoreTotaller)=$ComputedTotal(agent)) )
{
Field1(agent) = count(collect_if(child,$TextFrom="Number1",$Name));
Field2(agent) = count(collect_if(child,$TextFrom="Number2",$Name));
Field3(agent) = count(collect_if(child,$TextFrom="Number3",$Name));
TermScore(agent) = ($Field1*2) + ($Field2*1) + ($Field3*0.5);

ComputedCount(agent)=$ChildCount(agent); ComputedTotal(agent)=$ComputedTotal(TermScoreTotaller);
}


The now-working guard function improved performance from the original 23.0 secs to 4.2 seconds, according to Agent Update Time.

Title: Re: Action preventing update of subsequent agents
Post by Mark Anderson on Jun 18th, 2008, 6:44pm

Ah, that makes sense.  Inside the 'if' comparison - the bit in () - the equals sign is an equality check (such as to give a Boolean true/false result) as using in TB agent queries;  i.e. the test is one that in some scripting languages would be written as '==' instead of '='.

Elsewhere in your example, the the '=' is setting the value of the left side of the '=' to the value of the right side as in an Action or Rule. In Actions & rules, it is not necessary to use a $ sign as it's taken as implied  - though there's nothing to stop you using a $ prefix if you prefer to.

Bottom line, '=' means different things in different contexts.  In a query statement '=' denotes equality, whereas in an action is denotes assignment.

[It was difficult to guess at before as, taken out of context of a TBX, the code sample wasn't obvious as to what it was doing]

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.