Function: init()
Prefactor TypeScript SDK / @prefactor/packages/langchain / init
Function: init()
Section titled “Function: init()”init(
config?):AgentMiddleware
Defined in: packages/langchain/src/init.ts:105
Initialize the Prefactor SDK and return middleware for LangChain.js
This is the main entry point for the SDK. Call this function to create a middleware instance that you can pass to your LangChain.js agents.
Parameters
Section titled “Parameters”config?
Section titled “config?”Partial<{ }>
Optional configuration object
Returns
Section titled “Returns”AgentMiddleware
PrefactorMiddleware instance to use with LangChain.js agents
Example
Section titled “Example”import { init } from '@prefactor/langchain';import { createAgent } from 'langchain';
// Initialize with HTTP transportconst middleware = init({ transportType: 'http', httpConfig: { apiUrl: 'https://app.prefactorai.com', apiToken: process.env.PREFACTOR_API_TOKEN!, agentIdentifier: 'my-langchain-agent', },});
// Or configure HTTP transportconst middleware = init({ transportType: 'http', httpConfig: { apiUrl: 'https://app.prefactorai.com', apiToken: process.env.PREFACTOR_API_TOKEN!, agentIdentifier: 'my-langchain-agent', // Required agentId: 'legacy-agent-id', // Optional legacy identifier }});
const agent = createAgent({ model: 'claude-sonnet-4-5-20250929', tools: [myTool], middleware: [middleware],});