Skip to content

feat(engine): count on list tools so a Builder If can test "Number of events > 0" (#264) - #265

Merged
Lexirieru merged 4 commits into
mainfrom
feat/engine-if-count-and-answer
Nov 11, 2026
Merged

Lexirieru merged 4 commits into
mainfrom
feat/engine-if-count-and-answer

Conversation

@Lexirieru

Copy link
Copy Markdown
Contributor

Engine part of #264. The FE part (offering the fields in the If editor) is for @AncungAulia.

What

  • withCount(field, config) (engine/src/counted.ts) adds count: number to a tool's output schema and fills it from the list length after execute.
  • It is applied to every tool that returns a list of results:
Tool List Tool List
googlecalendar_list_events events googlesheets_read_range values
googlecalendar_find_free_time slots googledrive_find_files files
gmail_list_emails, outlook_list_emails emails slack_list_channels channels
mail_list messages notion_search results
list_payments payments notion_query_database rows
get_quotes quotes zoom_list_meetings meetings
googlesheets_find_spreadsheets spreadsheets
  • So "Number of events > 0" becomes { left: "{{steps.<node>.count}}", op: "gt", right: 0 }.
  • {{steps.<node>.events.length}} is still refused (400 invalid_workflow, Mastra's invalid-predicate-reference).

If on an Ask reply ({{steps.<agent>.text}})

  • It already saves and runs, with no change needed.
  • Mastra's predicates only compare exact text (eq/ne, in/notIn, no contains or ignore-case).
  • Probe on 11 Nov: prompt "Answer only yes or no: is 2 bigger than 1?" → the Mind answered Yes, so eq "yes" took the else way.
  • Usable today only with exact wording. A real "Mind says yes" would need a normalising step; not built here (feature freeze is close).

Tests (local)

  • bun run typecheck: passes.
  • bun run test:unit: 172/172. test/counted.test.ts fails for any registry tool with a top-level array and no count.
  • bun run test, real NEAR AI plus local Postgres: 309/309. New case in test/workflows.test.ts: events.length refused; count > 0 on the sample calendar takes the then way.
  • k6, If on count with the demo calendar, 5 VUs for 30 s: 4103 runs, 0 failed, every run took the then way, p95 82 ms.
  • load/workflow.js: 19338 checks, 0 failed.
  • Not tried against a real Google account; the count comes from the same list either way.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Q5ZrzK8une3S2YyhDG746e

Lexirieru and others added 4 commits November 11, 2026 23:07
A Builder If compares one value and Mastra validates its path against the
step's output schema, where an array has no length. withCount wraps a
createTool config: count in the output schema, filled after execute.
Wraps the config because Tool converts outputSchema in its constructor.

Tests: typecheck passes (helper unit tests land with the next commit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q5ZrzK8une3S2YyhDG746e
Calendar events and free slots, Gmail/Outlook/Mind mail, payments, quotes,
Sheets, Drive, Slack, Notion search and rows, Zoom meetings.
test/counted.test.ts fails for any registry tool with a top-level array
and no count (one-item and write results are listed as exceptions).

Tests: typecheck; test:unit 172/172.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q5ZrzK8une3S2YyhDG746e
events.length is refused by Mastra's validator; count > 0 on the sample
calendar takes the then way.

Tests: bun run test 309/309; k6 count-If 5 VUs 30s 4103 runs, 0 failed,
p95 82 ms; load/workflow.js 19338 checks, 0 failed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q5ZrzK8une3S2YyhDG746e
@Lexirieru
Lexirieru merged commit 8b9f947 into main Nov 11, 2026
1 check passed
@Lexirieru

Copy link
Copy Markdown
Contributor Author

Merged, so it deploys to the hosted demo after main's CI (rule 3).

@AncungAulia the FE part of #264 is yours:

  • In the If editor, offer count as "Number of …" for these tools: googlecalendar_list_events (events), googlecalendar_find_free_time (slots), gmail_list_emails / outlook_list_emails (emails), mail_list, list_payments, get_quotes, googlesheets_find_spreadsheets, googlesheets_read_range, googledrive_find_files, slack_list_channels, notion_search, notion_query_database (rows), zoom_list_meetings.
  • The canvas sends { left: "{{steps.<node>.count}}", op: "gt", right: 0 }. Never .events.length: that is refused with 400.
  • For an Ask node, {{steps.<node>.text}} works, but it is an exact text match. The Mind answered Yes while the If expected yes, so please don't offer "Mind says yes" as a preset yet.

@Lin1er no backend change is needed; the field only appears in tool outputs.

@Lin1er

Lin1er commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Live on the hosted demo: main 8b9f947 (automatic deploy after the merge).

  • Before: a1ae9a0, and the box matched git at that revision. CI: passed: test.
  • GET /v1/health → {"ok":true,"engine":true,"revision":"8b9f947"}. No rollback.
  • Rollback target: a1ae9a0 (/opt/hellonear/release-old).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants