LangChain Integration
Use Cognipeer Console as a LangChain chat model, and capture LangChain runs as Cognipeer tracing sessions. These helpers are exported from the package root.
import {
CognipeerLangChainChatModel,
CognipeerTracingCallbackHandler,
createCognipeerAgentTracing,
createCognipeerTracingMiddleware,
} from '@cognipeer/console-sdk';Requires
@langchain/coreas a peer dependency.
Chat model
CognipeerLangChainChatModel is a drop-in BaseChatModel that proxies to Console chat completions, so it works anywhere a LangChain chat model does (chains, agents, LCEL).
import { CognipeerLangChainChatModel } from '@cognipeer/console-sdk';
import { HumanMessage } from '@langchain/core/messages';
const model = new CognipeerLangChainChatModel({
model: 'gpt-4o-mini',
client: { apiKey: process.env.COGNIPEER_API_KEY! },
temperature: 0.2,
});
const res = await model.invoke([new HumanMessage('Summarize LangChain in one line.')]);
console.log(res.content);Constructor params (CognipeerLangChainChatModelParams):
| Param | Type | Description |
|---|---|---|
model | string | Target model key on Console (required) |
client | ConsoleClient | ConsoleClientOptions | An SDK client or options to build one (required) |
temperature, topP, maxTokens, presencePenalty, frequencyPenalty, toolChoice | — | Defaults applied when a call omits them |
Streaming (model.stream(...)) and tool calls are supported through the standard LangChain interfaces.
Tracing callback handler
CognipeerTracingCallbackHandler converts LangChain run events into a Cognipeer tracing session. Attach it via the callbacks array.
import { CognipeerTracingCallbackHandler } from '@cognipeer/console-sdk';
const tracer = new CognipeerTracingCallbackHandler({
client: { apiKey: process.env.COGNIPEER_API_KEY! },
agent: { name: 'support-agent' },
threadId: 'conversation_42',
autoFlush: true,
});
await chain.invoke(input, { callbacks: [tracer] });Options (CognipeerTracingCallbackOptions):
| Option | Description |
|---|---|
client | SDK client or options (required) |
sessionId | Session id (autogenerated if omitted) |
threadId | Groups multiple sessions into one thread |
agent | Agent descriptor stored with the session |
summary, config | Initial summary / config blob stored on the session |
autoFlush | Flush events on chain/tool completion |
debug, logger | Verbose logging hooks |
Helpers
createCognipeerAgentTracing(options)— returns a binding that wires a tracing handler to an agent run with the same options as above.createCognipeerTracingMiddleware(...)— produces middleware for frameworks that take middleware rather than a callbacks array.
const tracing = createCognipeerAgentTracing({
client: { apiKey: process.env.COGNIPEER_API_KEY! },
agent: { name: 'support-agent' },
});For graph-based agents see the LangGraph integration; for vendor-neutral spans see OpenTelemetry.