LangGraph Binding

TrikHub provides first-class LangChain/LangGraph integration. Convert triks to LangChain tools with one function call.

Quick Start

import { loadLangChainTriks } from '@trikhub/gateway/langchain'; import { ChatOpenAI } from '@langchain/openai'; // Load triks and create tools const { tools } = await loadLangChainTriks(); // Bind to model const model = new ChatOpenAI().bindTools(tools); // Use in your chain const response = await model.invoke([ { role: 'user', content: 'Search for AI articles' } ]);

Using Passthrough Content

The recommended way to integrate with LangGraph is to use an onPassthrough callback to handle content that should bypass the agent.

To prevent prompt injection, passthrough content should be handled separately and kept outside of the main Agent’s history.

import { loadLangChainTriks } from '@trikhub/gateway/langchain'; let lastPassthroughContent = ''; const { tools, gateway, loadedTriks } = await loadLangChainTriks({ // Handle passthrough content onPassthrough: (content) => { lastPassthroughContent = content; }, }); const model = new ChatOpenAI().bindTools(tools); // ... // Regular model invocation. Make sure to reset `lastPassthroughContent` on each new cycle // ... if (lastPassthroughContent) { console.log('Delivering directly to user:', lastPassthroughContent); } const assistantMessage = result.messages[result.messages.length - 1]; console.log(`Assistant response: ${assistantMessage.content}\n`);

Options

OptionTypeDescription
onPassthrough / on_passthrough(content) => voidCallback for passthrough content
debugbooleanEnable debug logging

Advanced: Manual Tool Creation

For more control, use createLangChainTools / create_langchain_tools directly:

import { TrikGateway } from '@trikhub/gateway'; import { createLangChainTools } from '@trikhub/gateway/langchain'; const gateway = new TrikGateway(); await gateway.loadTriksFromConfig(); // Manual session management const sessions = new Map<string, string>(); const tools = createLangChainTools(gateway, { getSessionId: (trikId) => sessions.get(trikId), setSessionId: (trikId, sessionId) => sessions.set(trikId, sessionId), onPassthrough: (content) => console.log(content), debug: true, });

Tool Naming

Trik actions become LangChain tools with normalized names:

Trik ActionLangChain Tool Name
@demo/article-search:searchdemo_article_search__search

To parse tool names back:

import { parseToolName } from '@trikhub/gateway/langchain'; const { trikId, actionName } = parseToolName('demo_article_search__search'); // trikId: '@demo/article-search' // actionName: 'search'

Next Steps