Javascript SDK for connecting to Large Language Platform.
- Simple, intuitive async API
- Websocket-based communication
- Full Typescript support
npm i llpsdkimport{LLPClient}from'llpsdk';import{config}from'dotenv';import{createAgent}from'my_app';asyncfunctionmain(){config();// Initialize the clientconstclient=newLLPClient('my-agent',process.env.LLP_API_KEY??'');// Define a callback handler agent initialization and for processing messagesclient.onStart(()=>{createAgent()});client.onMessage(async(agent,msg,_annotater)=>{// Process the prompt with your agent.// Replace this with your own processing logic.constresponse=agent.generate(msg.prompt);// You must return a responsereturnmsg.reply(response);});// Connect and keep the client runningawaitclient.connect();awaitnewPromise(()=>{});}main();examples/simple-agentis a standalone example package containing the literal Pythonsimple_agent.pyportexamples/mastra-weather-agentis a standalone Mastra example package with its ownpackage.json
If your LangChain agent uses tools, the SDK can automatically annotate those tool calls back to LLP.
import{LLPClient}from'llpsdk';import{createLLPToolMiddleware}from'llpsdk/langchain';import{createAgent,tool}from'langchain';import*aszfrom'zod';constweatherTool=tool(async({ city }: {city: string})=>`Weather for ${city}: sunny`,{name: 'weather',description: 'Look up the weather for a city',schema: z.object({city: z.string()}),},);constclient=newLLPClient<ReturnType<typeofcreateAgent>>('my-agent',process.env.LLP_API_KEY??'');client.onStart(()=>{returncreateAgent({
model,tools: [weatherTool],middleware: [createLLPToolMiddleware()],});}});client.onMessage(async(agent,msg,annotater)=>{constresult=awaitagent.invoke({messages: [{role: 'user',content: msg.prompt}],},{context: {llpMessage: msg,llpClient: agent,},},);returnmsg.reply(String(result.messages.at(-1)?.content??''));});The middleware requires LLP runtime context with:
llpMessage: the inboundTextMessagellpClient: the session or client object used to send tool-call annotations
# typecheck and build
make
# lint + tests
make test# format
make format