Here’s how to use Suada as a tool in your LangChain agent:
Copy
import { SuadaClient } from '@suada/node';import { ChatOpenAI } from 'langchain/chat_models/openai';import { initializeAgentExecutorWithOptions } from 'langchain/agents';// Initialize Suada clientconst suada = new SuadaClient({ apiKey: process.env.SUADA_API_KEY});// Create Suada tool for LangChainconst suadaTool = suada.createTool({ name: 'business_analyst', description: 'Use this tool to analyze business data and get insights. Input should be a specific business question.', externalUserIdentifier: 'user_123' // Your user's identifier});// Initialize LLMconst model = new ChatOpenAI({ temperature: 0, modelName: 'gpt-4', openAIApiKey: process.env.OPENAI_API_KEY});// Create agentconst executor = await initializeAgentExecutorWithOptions( [suadaTool], model, { agentType: "openai-functions", verbose: true });// Use the agentconst result = await executor.run( "What were our top performing products last month, and what insights can you provide about their performance?");