Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions example/convex/agents/fashion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ export const fashionAgent = new Agent(components.agent, {
tools: {
getUserPreferences: createTool({
description: "Get clothing preferences for a user",
args: z.object({
inputSchema: z.object({
search: z.string().describe("Which preferences are requested"),
}),
handler: async (ctx, args) => {
console.log("getting user preferences", args);
execute: async (ctx, input) => {
console.log("getting user preferences", input);
return {
userId: ctx.userId,
threadId: ctx.threadId,
search: args.search,
search: input.search,
information: `The user likes to look stylish`,
};
},
Expand Down
6 changes: 3 additions & 3 deletions example/convex/agents/story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export const storyAgent = new Agent(components.agent, {
getCharacterNames: createTool({
description:
"Get the names of characters for the story. Only call this once.",
args: z.object({
inputSchema: z.object({
count: z.number().describe("The number of character names to get"),
}),
handler: async (ctx, args) => {
execute: async (ctx, input) => {
return [
"Eleanor",
"Henry",
Expand All @@ -39,7 +39,7 @@ export const storyAgent = new Agent(components.agent, {
"Malachai",
"Selene",
"Victor",
].slice(0, args.count);
].slice(0, input.count);
},
}),
},
Expand Down
14 changes: 7 additions & 7 deletions example/convex/rag/ragAsTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,29 @@ export const sendMessage = action({
tools: {
addContext: createTool({
description: "Store information to search later via RAG",
args: z.object({
inputSchema: z.object({
title: z.string().describe("The title of the context"),
text: z.string().describe("The text body of the context"),
}),
handler: async (ctx, args) => {
execute: async (ctx, input) => {
await rag.add(ctx, {
namespace: userId,
title: args.title,
text: args.text,
title: input.title,
text: input.text,
});
},
}),
searchContext: createTool({
description: "Search for context related to this user prompt",
args: z.object({
inputSchema: z.object({
query: z
.string()
.describe("Describe the context you're looking for"),
}),
handler: async (ctx, args) => {
execute: async (ctx, input) => {
const context = await rag.search(ctx, {
namespace: userId,
query: args.query,
query: input.query,
limit: 5,
});
// To show the context in the demo UI, we record the context used
Expand Down
6 changes: 3 additions & 3 deletions example/convex/tools/agentAsTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export const runAgentAsTool = action({
const agentWithToolsAsTool = createTool({
description:
"agentWithTools which can either doSomething or doSomethingElse",
args: z.object({
inputSchema: z.object({
whatToDo: z.union([
z.literal("doSomething"),
z.literal("doSomethingElse"),
]),
}),
handler: async (ctx, args) => {
execute: async (ctx, input) => {
// Create a nested thread to call the agent with tools
const threadId = await createThread(ctx, components.agent, {
userId: ctx.userId,
Expand All @@ -59,7 +59,7 @@ export const runAgentAsTool = action({
messages: [
{
role: "assistant",
content: `I'll do this now: ${args.whatToDo}`,
content: `I'll do this now: ${input.whatToDo}`,
},
],
},
Expand Down
4 changes: 2 additions & 2 deletions example/convex/tools/searchMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import { textEmbeddingModel } from "../modelsForDemo";

export const searchMessages = createTool({
description: "Search for messages in the thread",
args: z.object({
inputSchema: z.object({
query: z.string().describe("The query to search for"),
}),
handler: async (ctx, { query }) => {
execute: async (ctx, { query }) => {
return fetchContextMessages(ctx, components.agent, {
userId: ctx.userId,
threadId: ctx.threadId,
Expand Down
6 changes: 3 additions & 3 deletions example/convex/tools/updateThreadTitle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { components } from "../_generated/api";
import { z } from "zod/v3";

export const updateThreadTitle = createTool({
args: z.object({
inputSchema: z.object({
title: z.string().describe("The new title for the thread"),
}),
description:
"Update the title of the current thread. It will respond with 'updated' if it succeeded",
handler: async (ctx, args) => {
execute: async (ctx, input) => {
if (!ctx.threadId) {
console.warn("updateThreadTitle called without a threadId");
return "missing or invalid threadId";
}
await ctx.runMutation(components.agent.threads.updateThread, {
threadId: ctx.threadId,
patch: { title: args.title },
patch: { title: input.title },
});
return "updated";
},
Expand Down
5 changes: 1 addition & 4 deletions src/UIMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,7 @@ function createAssistantUIMessage<
call.output = output;
}
} else {
console.warn(
"Tool result without preceding tool call.. adding anyways",
contentPart,
);
// Tool call is on a previous page - create standalone tool part
if (hasError) {
allParts.push({
type: `tool-${contentPart.toolName}`,
Expand Down
6 changes: 2 additions & 4 deletions src/mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ import {
convertUint8ArrayToBase64,
type ProviderOptions,
type ReasoningPart,
type ToolApprovalRequest,
type ToolApprovalResponse,
} from "@ai-sdk/provider-utils";
import { parse, validate } from "convex-helpers/validators";
import {
Expand Down Expand Up @@ -590,7 +588,7 @@ export function toModelMessageContent(
approvalId: part.approvalId,
toolCallId: part.toolCallId,
...metadata,
} satisfies ToolApprovalRequest;
} satisfies Infer<typeof vToolApprovalRequest>;
case "tool-approval-response":
return {
type: part.type,
Expand All @@ -599,7 +597,7 @@ export function toModelMessageContent(
reason: part.reason,
providerExecuted: part.providerExecuted,
...metadata,
} satisfies ToolApprovalResponse;
} satisfies Infer<typeof vToolApprovalResponse>;
default:
return null;
}
Expand Down
Loading