Skip to content

Function: init()

Prefactor TypeScript SDK


Prefactor TypeScript SDK / @prefactor/packages/langchain / 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.

Partial<{ }>

Optional configuration object

AgentMiddleware

PrefactorMiddleware instance to use with LangChain.js agents

import { init } from '@prefactor/langchain';
import { createAgent } from 'langchain';
// Initialize with HTTP transport
const middleware = init({
transportType: 'http',
httpConfig: {
apiUrl: 'https://app.prefactorai.com',
apiToken: process.env.PREFACTOR_API_TOKEN!,
agentIdentifier: 'my-langchain-agent',
},
});
// Or configure HTTP transport
const 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],
});