Skip to content

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)

Alberto Schiabelcbd1a374fdc5
diff --git a/ts/examples/mastra/src/index.ts b/ts/examples/mastra/src/index.ts
index d7ae00bf1..fc4fff0f9 100644
--- a/ts/examples/mastra/src/index.ts
+++ b/ts/examples/mastra/src/index.ts
@@ -16,6 +16,7 @@ import { openai } from '@ai-sdk/openai';
import { Composio } from '@composio/core';
import { MastraProvider } from '@composio/mastra';
import { Agent } from '@mastra/core/agent';
+import { stepCountIs } from 'ai';
import 'dotenv/config';
const composio = new Composio({
@@ -44,9 +45,11 @@ const agent = new Agent({
tools,
});
-const { text } = await agent.generate([
- { role: 'user', content: 'Tell me about the HackerNews user `pg`.' },
-]);
+// Allow the agent a few steps to call the tool and then summarize the result.
+const { text } = await agent.generate(
+ [{ role: 'user', content: 'Tell me about the HackerNews user `pg`.' }],
+ { stopWhen: stepCountIs(10) }
+);
// This example doubles as a test: a healthy run returns non-empty text.
if (!text || text.trim().length === 0) {
diff --git a/ts/examples/mastra/src/tool-router.ts b/ts/examples/mastra/src/tool-router.ts
index 7caffb925..5f1761971 100644
--- a/ts/examples/mastra/src/tool-router.ts
+++ b/ts/examples/mastra/src/tool-router.ts
@@ -19,6 +19,7 @@ import { openai } from '@ai-sdk/openai';
import { Composio } from '@composio/core';
import { MastraProvider } from '@composio/mastra';
import { Agent } from '@mastra/core/agent';
+import { stepCountIs } from 'ai';
import 'dotenv/config';
const composio = new Composio({
@@ -43,9 +44,14 @@ const agent = new Agent({
tools,
});
-const { text } = await agent.generate([
- { role: 'user', content: 'What are the current top 3 HackerNews stories? Give me their titles.' },
-]);
+// Tool Router is a multi-step flow: the agent calls the router's search +
+// multi-execute meta-tools, then summarizes. Without a step budget the run
+// stops after the first tool call and returns empty text, so allow several
+// steps (matches the Mastra tool-router e2e reference).
+const { text } = await agent.generate(
+ [{ role: 'user', content: 'What are the current top 3 HackerNews stories? Give me their titles.' }],
+ { stopWhen: stepCountIs(10) }
+);
// This example doubles as a test: a healthy run returns non-empty text.
if (!text || text.trim().length === 0) {