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
And my tool
[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_GYArlXZG4Pn4dSe8RNk3ICovawait 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;
},
});