import { DynamicStructuredTool } from '@langchain/core/tools';
import { z } from 'zod';
const searchProducts = new DynamicStructuredTool({
name: 'search_products',
description: 'Search the Podium product catalog. Use when the user asks about products, wants to browse, or needs recommendations.',
schema: z.object({
categories: z.string().optional().describe('Comma-separated category filter'),
limit: z.number().min(1).max(50).default(10).describe('Max results'),
page: z.number().min(1).default(1).describe('Page number'),
}),
func: async ({ categories, limit, page }) => {
const feed = await client.agentic.listProductsFeed({ categories, limit, page });
return JSON.stringify(feed.products.map((p: any) => ({
id: p.id, name: p.name, brand: p.brand, price: p.price,
})));
},
});
const getProduct = new DynamicStructuredTool({
name: 'get_product',
description: 'Get full details for a specific product by ID.',
schema: z.object({
productId: z.string().describe('Product ID'),
}),
func: async ({ productId }) => {
const product = await client.product.get({ id: productId });
return JSON.stringify(product);
},
});
const getRecommendations = new DynamicStructuredTool({
name: 'get_recommendations',
description: 'Get personalized product recommendations for a user based on their taste profile.',
schema: z.object({
userId: z.string().describe('Podium user ID'),
count: z.number().min(1).max(20).default(5),
category: z.string().optional(),
}),
func: async ({ userId, count, category }) => {
const recs = await client.companion.listRecommendations({ userId, count, category });
return JSON.stringify(recs);
},
});
const getUserProfile = new DynamicStructuredTool({
name: 'get_user_profile',
description: 'Get a user\'s companion/taste profile with their preferences, skin type, and concerns.',
schema: z.object({
userId: z.string().describe('Podium user ID'),
}),
func: async ({ userId }) => {
const profile = await client.companion.listProfile({ userId });
return JSON.stringify(profile);
},
});
const checkPoints = new DynamicStructuredTool({
name: 'check_points',
description: 'Check a user\'s loyalty points balance.',
schema: z.object({
userId: z.string().describe('Podium user ID'),
}),
func: async ({ userId }) => {
const points = await client.user.listPoints({ id: userId });
return JSON.stringify(points);
},
});
const createCheckout = new DynamicStructuredTool({
name: 'create_checkout',
description: 'Create a checkout session to purchase a product. Only call after confirming with the user.',
schema: z.object({
productId: z.string().describe('Product ID to purchase'),
quantity: z.number().min(1).default(1),
}),
func: async ({ productId, quantity }) => {
const session = await client.agentic.createCheckoutSessions({
requestBody: {
items: [{ id: productId, quantity }],
},
});
return JSON.stringify({ sessionId: session.id, total: session.total, status: session.status });
},
});
const recordInteraction = new DynamicStructuredTool({
name: 'record_interaction',
description: 'Record a user interaction with a product (like, dislike, skip, or purchase intent).',
schema: z.object({
userId: z.string(),
productId: z.string(),
action: z.enum(['RANK_UP', 'RANK_DOWN', 'SKIP', 'PURCHASE_INTENT']),
}),
func: async ({ userId, productId, action }) => {
await client.companion.createInteractions({
requestBody: { userId, productId, action },
});
return `Recorded ${action} for product ${productId}`;
},
});