Welcome, Guest. Please Login
Tinderbox
  News:
IMPORTANT MESSAGE! This forum has now been replaced by a new forum at http://forum.eastgate.com and no further posting or member registration is allowed. The forum is still accessible via read-only access for reference purposes. If you wish to discuss content here, please use the new forum. N.B. - posting in the new forum requires a fresh registration in the new forum (sorry - member data can't be ported).
  HomeHelpSearchLogin  
 
Pages: 1
Send Topic Print
How to use an agent's attributes in a query (Read 5754 times)
Penny
Full Member
*
Offline



Posts: 18

How to use an agent's attributes in a query
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.
Back to top
 
« Last Edit: Jul 07th, 2008, 6:43pm by Penny »  
  IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: How to use an agent's attributes in a query
Reply #1 - 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!
Back to top
 
 

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: How to use an agent's attributes in a query
Reply #2 - 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!)
Back to top
 
 
WWW   IP Logged
Mark Anderson
YaBB Administrator
*
Offline

User - not staff!

Posts: 5689
Southsea, UK
Re: How to use an agent's attributes in a query
Reply #3 - 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!
Back to top
 
« Last Edit: Jul 8th, 2008, 3:56pm by Mark Anderson »  

--
Mark Anderson
TB user and Wiki Gardener
aTbRef v6
(TB consulting - email me)
WWW shoantel   IP Logged
Mark Bernstein
YaBB Administrator
*
Offline

designer of
Tinderbox

Posts: 2871
Eastgate Systems, Inc.
Re: How to use an agent's attributes in a query
Reply #4 - 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.
Back to top
 
 
WWW   IP Logged
Pages: 1
Send Topic Print