Tool calling & Structured output
When calling my agent through the mastra client sdk, it does not use the tools i provided,
with the same prompt in the chat in the playground it does call the tool, why ?
after debuging, tool is not found 404
agent definition :
very frustrating and blocking, any workaround ?
35 Replies
Hey @Rafik Belkadi ! Looks like
getTool
is calling an endpoint that does not exist.
As a workaround, you can gets the tools this way for now:
Opened this PR to add the missing endpoint: https://github.com/mastra-ai/mastra/pull/7250Thanks for the PR @Romain :), although
getTool
method was just for debugging, the issue was the agent was not calling any tools when called from the client sdk
alright i found out that when adding threadId & resourceId it does not call tools, after removing these two it does call the tools
means i can't use memory with that
also even when tools are called, the
toolCalls &
toolResults`arrays are always empty in the response๐ Created GitHub issue: https://github.com/mastra-ai/mastra/issues/7302
GitHub
[DISCORD:1412091272453161082] Tool calling & Structured output ยท I...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1412091272453161082 When calling my agent through the mastra client sdk, it does not use the tools i provi...
Hey @Rafik Belkadi ! Could you share a small repro example please? Thanks ๐
@Romain want a repo or just my actual code ?
Doesn't have to be a repo, just enough code to reproduce the issue.
@Romain here it is :
agent.ts:
tool.ts :
mastra/index.ts :
( by the way i don't see traces in the mastra playground on the agent, i just have the logs, is it normal or ? )
mastra-client.service.ts :
here i call the agent via the mastra client sdk :
```ts
const response = await this._mastraClientService.getEmailRespondAgent().generate({
messages: [
{
role: 'system',
content: systemPrompt,
},
{
role: 'user',
content: userPrompt,
},
],
// // Mastra uses threadId for memory scoping
threadId:
${user.id}_${contactEmail}`,
// Resource ID for contact-specific memory
resourceId: contactEmail,
experimental_output: mySchema
runtimeContext: {
google_auth_token: googleAuthToken,
},
});
```
uppon removing threadId and resourceId, the tools are called ( i also removed experimental_output later cause it couldn't parse it..)
tell me if you need anything elseThanks @Rafik Belkadi !
@Rafik Belkadi I'm unable to reproduce this issue. What versions of mastra packages are you using?
It would also help to get a repo for a minimal reproduction that can consistently reproduce it so we can fix it.
"@mastra/auth": "^0.1.2",
"@mastra/client-js": "^0.11.2",
"@mastra/core": "^0.14.1",
"@mastra/libsql": "^0.0.1",
"@mastra/memory": "^0.13.1",
"@mastra/mongodb": "^0.13.3",
i will tryto add a reproducible repo this weekend
It looks like you have some outdated packages, can you bump all the packages to the latest and see if it works. We ship lots of fixes every week, so chances are it might be fixed already!
I upgraded everything related to mastra and vercel ai sdk, i think it was because my resourceId was something like 'unknown' which i was defaulting to as a fallback.
tool calls seem to work now thx !
still can't use structured outpout tho
okay great! Glad to hear that tool calls are working now. What do you mean you can't use structured output? Can you give an example of what's not working?
when i add the
output
property to the generateVNext
method, it doesnt call tools @Daniel Lewcan you see if the
structuredOutput
property works better?
the
structuredOutput
property doesn't exist on the mastra client sdkit looks like that property does exist on the MastraClient agent instance. is it possible that you just need to bump the client-js package as well?
i am already at latest version 0.12.0 :/
ah, I misread things, I have a PR up to fix it here https://github.com/mastra-ai/mastra/pull/7597
GitHub
fix(core, client-js): add structuredOutput to client js by DanielSL...
Description
add structuredOutput property to client-js, falls back to using agent model
model is optional now in structuredOutput
Fixes #7302
Related Issue(s)
Type of Change
Bug fix (non-brea...
Ah Great thank you รจ
@Daniel Lew , after upgrading to the latest version i got this type error, any idea ?


i added
as any
to fix the type error, and got this afterwards :
Can you paste the full code snippet
oh wait I think it's supposed to be nested under a schema property
ah ok yeah after adding "schema" type is good, but got no autocompletion tho since default type for structuredOutput is "undefined"
and here
wouldn't it be better to be able to define the fallbackValue as a function like :
and structuredOutput fails here are the logs :
my code:
`
We've got a PR in to fix the types for it https://github.com/mastra-ai/mastra/pull/7668, and that's a good point for the fallback, if you want to open a issue for that, or even PR it that would be great!
I'll look into the issue with this schema. It looks like youre using zod v3? I'm guessing it's just not parsing the schema properly
i'll try to open a PR for that asap ๐
Yup it's v3
And you're on the latest version? we just released a new version yesterday with some fixes for structuredOutput, might be worth trying to upgrade first
Yep just upgraded this morning
what is the prompt & system instruction you're using for this?
gonna delete this after if you don't mind :p
for sure! I got it
okay I'm able to repro, it works fine by invoking the agent directly, but using MastraClient it doesn't work. So I'm guessing our schema serialization logic to send it over the wire isn't working properly
got a fix here for it https://github.com/mastra-ai/mastra/pull/7691
GitHub
fix(core): fix structuredOutput over clientjs by DanielSLew ยท Pull...
Description
When structuredOutput gets sent over the wire through client-js, it becomes jsonSchema, but the backend code incorrectly assumes it will be of type Schema instead of JSONSchema
Related...