Skip to Content
JavaScriptCreate AgentsCreate Langchain Agents

LangChain Integration

import { ChatAnthropic } from "@langchain/anthropic"; import { ChatPromptTemplate } from "@langchain/core/prompts"; import { createToolCallingAgent } from "langchain/agents"; import { AgentExecutor } from "langchain/agents"; import { LangChainAdapter } from "@reacter/openapitools"; // Initialize the language model const llm = new ChatAnthropic({ model: "claude-3-7-sonnet-20250219", apiKey: "your-anthropic-api-key", verbose: true, }); // Initialize the adapter const adapter = new LangChainAdapter( "your OpenAPI Tools Apikey - https://openapitools.com/dashboard/settings", { autoRefreshCount: 50, } ); // Define the prompt template const prompt = ChatPromptTemplate.fromMessages([ ["system", "You are a helpful assistant"], ["placeholder", "{chat_history}"], ["human", "{input}"], ["placeholder", "{agent_scratchpad}"], ]); // Get tools in LangChain format const tools = await adapter.getLangChainTools(); // Get specific tools // const tools = await adapter.getLangChainTools(["generate-otp", {"name": "get-orders", "version": "prod"}]); // Create a LangChain agent with tools const agent = createToolCallingAgent({ llm, tools, prompt, }); // Set up the agent executor const agentExecutor = new AgentExecutor({ agent, tools, }); // Use the agent const response = await agentExecutor.invoke({ input: "Can you generate an OTP for me?", }); console.log(response);
Last updated on