Tool Call aggregate_workitems

Computes a single number - sum, count, average, minimum or maximum - over a set of workitems, e.g. “the total of all billable hours booked to this project.”

The computation always runs on the server. The agent never sees the individual cases or their values, only the final result. LLMs are not reliable at exact arithmetic over many records, and a figure that feeds a report or an invoice has to be exactly right, not approximately right.

See Tool Calls for the general concept.

When to use

If… Use
the cases are selected by field values you give in the prompt aggregate_workitems
a DataView already selects the cases you want to calculate over aggregate_dataview

Arguments

Argument Required Description
criteria yes Field name/value pairs to select the workitems, combined with AND
filter yes Additional condition, or an empty value if not needed. See Why filter is required
function yes One of sum, count, avg, min, max
aggregateField no The numeric field to aggregate, e.g. service.hours. Not needed for count
targetField no Field of the current case to write the result into. If omitted, the result is only returned, not saved
matchIdsField no Field of the current case to write the list of matched cases into, for traceability

How to write criteria, filter and <item>itemname</item> is described in Selecting Workitems.

What happens

  • All matching cases are included. Unlike find_workitem and link_workitem, there is no limit of 10 or 20.
  • Only the list written to matchIdsField is capped at 500 entries. The computed number is always exact.
  • For avg the result is rounded to 4 decimal places.
  • The agent receives the result, the number of included cases (matchCount) and truncated, which is true if the list of matched cases was cut off at 500 entries. It never receives the values of individual cases.

Why filter is required

filter has to be present in every call, even if you don't need it. Pass an empty value to select everything that matches the criteria.

This is intentional. In tests with a locally hosted model, an optional filter was reproducibly forgotten in one of two almost identical calls within the same completion. Making the field required removed the problem. It costs nothing when it is not needed.

Because of this:

  • Always include the filter key in the example you give in the prompt, even when it is empty.
  • For several similar calls (e.g. billable and non-billable hours), write every call as a complete, copy-ready parameter set. Don't describe only what differs.

Prompt example

Use the tool call "aggregate_workitems" to sum up all billable hours booked to the current
project. Pass the following as the criteria parameter:
{"$workflowgroup": "Efforts", "$workitemref": "<item>$uniqueid</item>"}

Pass the following as the filter parameter, exactly as given:
(service.billable:true)

Use "service.hours" as the aggregateField, "sum" as the function, and store the result in
the targetField "service.hours.total".

After the tool call returns, call task_complete with a short summary stating the total
billable hours and how many bookings were included (matchCount). Do not calculate or state
any percentage or budget comparison yourself.

Tips

  • Use targetField so the figure is stored in the case. Don't let the agent copy the number with update_workitem.
  • Tell the agent explicitly not to calculate anything itself. Ratios and deviations (e.g. hours booked vs. hours contracted) belong into a script step of the BPMN model after the aggregation.
  • If the same selection is needed in many prompts, model it once as a DataView and use aggregate_dataview.