@devries-cameron20 / composio-1 / commits / cbd1a374f
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix(examples): give the Mastra agents a step budget so tool-router returns output (#3789)

## What Add `stopWhen: stepCountIs(10)` to both Mastra example agent entries (`src/index.ts`, `src/tool-router.ts`). ## Why The first nightly `workflow_dispatch` run of `ts.examples-nightly` (after #3788 merged) failed on the **tool-router** example with `Agent returned empty output`. `agent.generate(...)` had no step budget, so the multi-step Tool Router flow (router `search` + `multi-execute` meta-tools, then summarize) stopped after the first tool call and produced no final text. The non-empty-output assertion added in #3788 turned that silent no-op into a loud failure — working as intended. Every other tool-router example/e2e in the repo already sets a step budget; this matches the Mastra tool-router e2e reference (`ts/e2e-tests/runtimes/node/mastra-tool-router-zod-v4/e2e.test.ts` → `stopWhen: stepCountIs(10)`). ## Verification - `pnpm run lint:examples` and `pnpm run typecheck:examples` green. - Nightly re-dispatch to confirm the tool-router example now returns non-empty output against staging (follow-up once merged). ## Notes - No changeset — example package is private/unpublished. - `index.ts` passed without the budget but gets the same `stepCountIs(10)` for robustness/consistency.

Alberto Schiabel committed Jul 10, 2026 at 02:08 UTC cbd1a374fdc5ebe7c50f4834ee64367410e1f6cb
2 files changed +15 -6
ts/examples/mastra/src/index.ts
+6 -3
@@ -16,6 +16,7 @@ import { openai } from '@ai-sdk/openai';
16 import { Composio } from '@composio/core';
17 import { MastraProvider } from '@composio/mastra';
18 import { Agent } from '@mastra/core/agent';
19 +import { stepCountIs } from 'ai';
20 import 'dotenv/config';
21
22 const composio = new Composio({
@@ -44,9 +45,11 @@ const agent = new Agent({
45 tools,
46 });
47
47 -const { text } = await agent.generate([
48 - { role: 'user', content: 'Tell me about the HackerNews user `pg`.' },
49 -]);
48 +// Allow the agent a few steps to call the tool and then summarize the result.
49 +const { text } = await agent.generate(
50 + [{ role: 'user', content: 'Tell me about the HackerNews user `pg`.' }],
51 + { stopWhen: stepCountIs(10) }
52 +);
53
54 // This example doubles as a test: a healthy run returns non-empty text.
55 if (!text || text.trim().length === 0) {
ts/examples/mastra/src/tool-router.ts
+9 -3
@@ -19,6 +19,7 @@ import { openai } from '@ai-sdk/openai';
19 import { Composio } from '@composio/core';
20 import { MastraProvider } from '@composio/mastra';
21 import { Agent } from '@mastra/core/agent';
22 +import { stepCountIs } from 'ai';
23 import 'dotenv/config';
24
25 const composio = new Composio({
@@ -43,9 +44,14 @@ const agent = new Agent({
44 tools,
45 });
46
46 -const { text } = await agent.generate([
47 - { role: 'user', content: 'What are the current top 3 HackerNews stories? Give me their titles.' },
48 -]);
47 +// Tool Router is a multi-step flow: the agent calls the router's search +
48 +// multi-execute meta-tools, then summarizes. Without a step budget the run
49 +// stops after the first tool call and returns empty text, so allow several
50 +// steps (matches the Mastra tool-router e2e reference).
51 +const { text } = await agent.generate(
52 + [{ role: 'user', content: 'What are the current top 3 HackerNews stories? Give me their titles.' }],
53 + { stopWhen: stepCountIs(10) }
54 +);
55
56 // This example doubles as a test: a healthy run returns non-empty text.
57 if (!text || text.trim().length === 0) {