
Product
Introducing Webhook Events for Pull Request Scans
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
@composio/langchain
Advanced tools
The LangChain provider for Composio SDK, providing seamless integration with LangChain's ecosystem and tools.
The LangChain provider for Composio SDK, providing seamless integration with LangChain's ecosystem and tools.
npm install @composio/core @composio/langchain @langchain/core @langchain/openai
# or
yarn add @composio/core @composio/langchain @langchain/core @langchain/openai
# or
pnpm add @composio/core @composio/langchain @langchain/core @langchain/openai
Required environment variables:
COMPOSIO_API_KEY
: Your Composio API keyOPENAI_API_KEY
: Your OpenAI API key (or other LLM provider's key)Optional environment variables:
LANGCHAIN_TRACING_V2
: Enable LangChain tracing (set to "true")LANGCHAIN_ENDPOINT
: Custom LangChain API endpointLANGCHAIN_API_KEY
: Your LangChain API key (for hosted services)import { Composio } from '@composio/core';
import { LangChainProvider } from '@composio/langchain';
// Initialize Composio with LangChain provider
const composio = new Composio({
apiKey: 'your-composio-api-key',
provider: new LangChainProvider(),
});
// Get available tools
const tools = await composio.tools.get('user123', {
toolkits: ['gmail', 'googlecalendar'],
limit: 10,
});
// Get tools with version control
const versionedTools = await composio.tools.get('user123', {
toolkits: ['gmail'],
toolkitVersions: { gmail: '20250909_00' },
});
// Get a specific tool
const sendEmailTool = await composio.tools.get('user123', 'GMAIL_SEND_EMAIL');
Check out our complete example implementations:
import { Composio } from '@composio/core';
import { LangChainProvider } from '@composio/langchain';
import { ChatPromptTemplate } from '@langchain/core/prompts';
import { StringOutputParser } from '@langchain/core/output_parsers';
import { ChatOpenAI } from '@langchain/openai';
const composio = new Composio({
apiKey: process.env.COMPOSIO_API_KEY,
provider: new LangChainProvider(),
});
// Get tools for the chain
const tools = await composio.tools.get('user123', {
toolkits: ['gmail'],
limit: 10,
});
const model = new ChatOpenAI({
modelName: 'gpt-4',
streaming: true,
});
const prompt = ChatPromptTemplate.fromTemplate('Tell me a joke about {topic}');
const parser = new StringOutputParser();
const chain = prompt.pipe(model).pipe(parser);
// Stream the response
const stream = await chain.stream({
topic: 'programming',
});
for await (const chunk of stream) {
console.log(chunk);
}
import { Composio } from '@composio/core';
import { LangChainProvider } from '@composio/langchain';
import { ChatPromptTemplate } from '@langchain/core/prompts';
import { JsonOutputParser } from '@langchain/core/output_parsers';
import { ChatOpenAI } from '@langchain/openai';
const composio = new Composio({
apiKey: process.env.COMPOSIO_API_KEY,
provider: new LangChainProvider(),
});
// Get tools for the chain
const tools = await composio.tools.get('user123', {
toolkits: ['gmail'],
});
const model = new ChatOpenAI({
modelName: 'gpt-4',
streaming: true,
});
const chain = model.pipe(new JsonOutputParser());
const eventStream = await chain.streamEvents(
`Output a list of the countries france, spain and japan and their populations in JSON format.`,
{ version: 'v2' }
);
for await (const event of eventStream) {
const eventType = event.event;
if (eventType === 'on_chat_model_stream') {
console.log(`Chat model chunk: ${event.data.chunk.content}`);
} else if (eventType === 'on_parser_stream') {
console.log(`Parser chunk: ${JSON.stringify(event.data.chunk)}`);
}
}
The LangChain provider can be configured with various options:
const provider = new LangChainProvider({
// Default model configuration
model: new ChatOpenAI({
modelName: 'gpt-4',
streaming: true,
}),
// Custom execution modifiers
modifiers: {
beforeExecute: params => {
// Transform parameters before execution
return params;
},
afterExecute: response => {
// Transform response after execution
return response;
},
},
// Enable tracing
tracing: true,
});
The LangChainProvider
class extends BaseComposioProvider
and provides LangChain-specific functionality.
executeToolCall(tool: Tool): Promise<string>
Executes a LangChain tool call and returns the result.
const result = await provider.executeToolCall(tool);
We welcome contributions! Please see our Contributing Guide for more details.
ISC License
For support, please visit our Documentation or join our Discord Community.
FAQs
The LangChain provider for Composio SDK, providing seamless integration with LangChain's ecosystem and tools.
The npm package @composio/langchain receives a total of 1,172 weekly downloads. As such, @composio/langchain popularity was classified as popular.
We found that @composio/langchain demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Add real-time Socket webhook events to your workflows to automatically receive pull request scan results and security alerts in real time.
Research
The Socket Threat Research Team uncovered malicious NuGet packages typosquatting the popular Nethereum project to steal wallet keys.
Product
A single platform for static analysis, secrets detection, container scanning, and CVE checks—built on trusted open source tools, ready to run out of the box.