MaviOG
MaviOG2w ago

tool_calls

Hey so im making a simple agent with a tool that can access rag-search and display that content but im getting an error
[CONVEX A(public/messages:create)] [Request ID: 7ffca58ab010e094] Server Error
Uncaught AI_APICallError: An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages: call_GYArlXZG4Pn4dSe8RNk3ICov
[CONVEX A(public/messages:create)] [Request ID: 7ffca58ab010e094] Server Error
Uncaught AI_APICallError: An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages: call_GYArlXZG4Pn4dSe8RNk3ICov
await supportAgent.generateText(
ctx,
{ threadId: args.threadId },
{
prompt: args.propt,
tools: {
searchTool: search,
},
},
);
await supportAgent.generateText(
ctx,
{ threadId: args.threadId },
{
prompt: args.propt,
tools: {
searchTool: search,
},
},
);
And my tool
export const search = createTool({
description:
"Search the knowledge base for relevant information to help answer user questions",
args: z.object({
query: z.string().describe("The search query to find relevant information"),
}),
handler: async (ctx, args) => {
const conversation = await ctx.runQuery(
internal.system.conversations.getByThreadId,
{ threadId: ctx.threadId },
);

const searchResault = await rag.search(ctx, {
namespace: conversation.organizationId,
query: args.query,
limit: 5,
});

const contextText = `Found results in ${searchResault.entries
.map((e) => e.title || null)
.filter((t) => t !== null)
.join(", ")}. Here is the context:\n\n${searchResault.text}`;

const response = await generateText({
messages: [
{
role: "system",
content: SEARCH_INTERPRETER_PROMPT,
},
{
role: "user",
content: `User asked:"${args.query}"\n\nSearch results:${contextText}`,
},
],
model: openai.chat("gpt-4o-mini"),
});
await supportAgent.saveMessage(ctx, {
threadId: ctx.threadId,
message: { role: "assistant", content: response.text },
});
console.log("Search tool response:", response);
return response.text;
},
});
export const search = createTool({
description:
"Search the knowledge base for relevant information to help answer user questions",
args: z.object({
query: z.string().describe("The search query to find relevant information"),
}),
handler: async (ctx, args) => {
const conversation = await ctx.runQuery(
internal.system.conversations.getByThreadId,
{ threadId: ctx.threadId },
);

const searchResault = await rag.search(ctx, {
namespace: conversation.organizationId,
query: args.query,
limit: 5,
});

const contextText = `Found results in ${searchResault.entries
.map((e) => e.title || null)
.filter((t) => t !== null)
.join(", ")}. Here is the context:\n\n${searchResault.text}`;

const response = await generateText({
messages: [
{
role: "system",
content: SEARCH_INTERPRETER_PROMPT,
},
{
role: "user",
content: `User asked:"${args.query}"\n\nSearch results:${contextText}`,
},
],
model: openai.chat("gpt-4o-mini"),
});
await supportAgent.saveMessage(ctx, {
threadId: ctx.threadId,
message: { role: "assistant", content: response.text },
});
console.log("Search tool response:", response);
return response.text;
},
});
1 Reply
Convex Bot
Convex Bot2w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!

Did you find this page helpful?