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 >> How to use an agent's attributes in a query
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1215470449

Message started by Penny on Jul 7th, 2008, 6:40pm

Title: How to use an agent's attributes in a query
Post by Penny on Jul 7th, 2008, 6:40pm

I struggled with this for a bit, so I thought I'd provide my solution. I got inspired by some recent blog posts on using Tinderbox as a Daybook. I wanted to create agents to help me find notes related to different projects. I wanted to be able to create an agent based on a prototype, give it a project name as its name, and have the prototype construct the query using the agent's name. Since queries don't have access to the agent's attributes, this stumped me for a bit.

My solution was to define a macro called createQuery. The value of createQuery is Tags($1). [I have a set-valued attribute called Tags, and the project name will appear in the tag set.]

I created an agent prototype which sets the query in its rule: AgentQuery=do(createQuery, $Name)

If the agent's name is "projectname", when its rule runs, its query becomes Tags(projectname).

I'm not sure if this is the best way to do this, but it works.

Title: Re: How to use an agent's attributes in a query
Post by Mark Anderson on Jul 7th, 2008, 8:03pm

That works fine but I think you can simply use this as your prototype Agent's Rule:

Code:
AgentQuery="Tags("+$Name+")";

Note, when you first set that prototype for a new agent using the create/rename agent dialog, the Query box in the will appear to have a query for the prototypes name but once you close the dialog the Rule runs and the correct query is set.

In both the above case and in your method you can't use the more efficient|= operator which only sets a value for the left-side attribute if no value is already set; it more efficient as ideally we need the rule to run only once. This is because the prototype's Rule sets its own AgentQuery and other agents using the prototype inherit that value until the own Rule fires, setting the right value.

So, although the Rule really only needs to run the once, in fact it will fire every update cycle of agents/actions/rules. A method avoiding that would be more efficient but i can't think of one right now!

Title: Re: How to use an agent's attributes in a query
Post by Mark Bernstein on Jul 8th, 2008, 10:10am

In an agent query, you can refer to the agent's attributes using the keyword agent:

      $Tags=$Tags(agent)

means "gather all the notes whose tags are the same as this agent's tags."

The exception here is regular expression matching and set containment.  The regular expression argument is not evaluated, because all sorts of special characters that mean one thing in expresssions mean something else in regular expressions.  For example, would '+' mean "addition", "concatenation", or its regular-expression meaning of "one or more repetitions of the previous expression"?  Mark Anderson's technique is ideal for these situations (and also more efficient!)

Title: Re: How to use an agent's attributes in a query
Post by Mark Anderson on Jul 8th, 2008, 12:45pm

I can't make 'agent' work in this context.  My understanding was this let a child[sic] of an agent refer to the aliases parent (the container) instead of the aliases parent - which is the parent of the aliases original.

In the OP's scenario we've 2 issues.  The agent is trying to self-refer and we're trying to set this self-reference at arms length via a prototype. If I set a prototype agent's Rule as AgentQuery=$Tags(agent) the result is no AgentQuery value is set.

I'm not arguing that agent should work in the OP's scenario but simply noting that I read your last post as implying that it but am unable to prove that it does!

Title: Re: How to use an agent's attributes in a query
Post by Mark Bernstein on Jul 8th, 2008, 2:05pm

The inherited AgentQuery is being overridden by the (empty) AgentQuery in the create/rename dialog -- we hadn't anticipated that an agent would inherit a query!

But you can use QuickStamp or an action to restore the default.

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.