Chaining supervisor agent with agents which own vector tools does not work
I have created a supervisor agent, which has a tool calling agent B. Agent B has an access to the vector tool and if called directly - it works. However when it is invoked from another tool, then I get the following error:
{
"message": "Invalid schema for function 'vectorTool': In context=('additionalProperties',), schema must have a 'type' key.",
"details": {
"message": "Invalid schema for function 'vectorTool': In context=('additionalProperties',), schema must have a 'type' key.",
"domain": "TOOL",
"category": "USER",
"details": {
"errorMessage": "[Agent:Agent B] - Failed tool execution",
"argsJson": "{\"brief\":\"A.\",\"pov\":\"customer\",\"endingType\":\"quiz\"}",
"model": "gpt-4o-mini"
}
},
"code": "TOOL_EXECUTION_FAILED"
}
Agent B looks like this:
export const agentB = new Agent({
name: "Agent B",
instructions: async ({
runtimeContext,
}: {
runtimeContext: RuntimeContext<SomeRuntimeContext>;
}) => {
return getPrompt(
runtimeContext.get("brief"),
runtimeContext.get("pov"),
runtimeContext.get("endingType")
)
},
model: openai("gpt-4o-mini"),
tools: { vectorTool }
});
and it works if called separately.
Vector tool looks like this:
export const vectorTool = createVectorQueryTool({
id: "get-sample-results-vector",
description: "Query the style guideline RAG.",
vectorStoreName: 'ragStore',
indexName: 'myrags',
model: openai.embedding("text-embedding-3-small"),
databaseConfig: {
pgvector: {
minScore: 0.2,
ef: 400,
probes: 75,
},
}
});3 Replies
Tool which calls Agent B looks like this:
export const agentBTool = createTool({
id: "call-agent-b",
description: "Calls the agent B to write the article according tobrief, pov and ending type.",
inputSchema: z.object({
brief: z.string(),
pov: z.any(),
endingType: z.any()
}),
outputSchema: z.object({
title: z.string(),
body: z.string()
}),
execute: async ({ context, mastra }) => {
const { brief, pov, endingType } = context;
const agent = mastra!.getAgent("agentB");
const runtimeContext = new RuntimeContext<SomeRuntimeContext>();
runtimeContext.set("brief", brief);
runtimeContext.set("pov", pov);
runtimeContext.set("endingType", endingType);
const result = await agent!.generate(
"Execute according to the given brief, pov and endingType.",
{
runtimeContext,
structuredOutput: {
schema: z.object({
title: z.string(),
body: z.string()
})
}
}
);
return {
title: result.object.title,
body: result.object.body,
};
},
});
Supervisor agent code:
export const supervisorAgent = new Agent({
name: "Supervisor Agent",
instructions:
"
You are a publisher agent that first calls the copywriter agent via advertorial copywriter tool.
- Always ask for brief, point of view (expert or customer) and endingType (quiz or product link). Do not continue without these parameters.
- Output the raw JSON which is returned from the tool. Do not make any changes.
",
model: openai("gpt-4o-mini"),
tools: { agentBTool },
memory: new Memory({
storage: new LibSQLStore({
url: 'file:../mastra.db',
}),
}),
});📝 Created GitHub issue: https://github.com/mastra-ai/mastra/issues/9699
GitHub
Chaining supervisor agent with agents which own vector tools does n...
This issue was created from Discord post 1435311074948943993: I have created a supervisor agent, which has a tool calling agent B. Agent B has an access to the vector tool and if called directly - ...
Alright, so I was able to resolve the issue, although it was not that intuitive to do. Instead of passing vectorTool directly, I have wrapped the invocation like into non-vector tool:
export const genericTool = createTool({
id: 'get-sample-results',
description:
"Query the style guideline RAG.",
inputSchema: z.object({
queryText: z.string().min(1).describe("Query text"),
topK: z.number().int().min(1).max(20).describe("Number of results"),
}).strict(),
execute: async ({ context, runtimeContext, mastra }) => {
const { queryText, topK } = context;
return vectorTool.execute({
context: { queryText, topK },
runtimeContext: runtimeContext,
mastra: mastra
});
},
});
Strange thing is - that I also needed to supply mastra instance into vectorTool which is not documented anywhere.
I still think this is a bug and needs to be fixed.