> ## Documentation Index
> Fetch the complete documentation index at: https://docs.uselumina.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# LangChain Integration

> Integrate Lumina with LangChain

Integrate Lumina with LangChain applications.

***

## Installation

```bash theme={null}
npm install @uselumina/sdk langchain
```

***

## Basic Usage

```typescript theme={null}
import { initLumina } from '@uselumina/sdk';
import { ChatOpenAI } from 'langchain/chat_models/openai';
import { HumanMessage } from 'langchain/schema';

const lumina = initLumina({
  endpoint: 'http://localhost:9411/v1/traces',
  service_name: 'langchain-app',
});

const chat = new ChatOpenAI();

const response = await lumina.traceLLM(
  () => chat.call([new HumanMessage('Hello!')]),
  { name: 'langchain-chat', system: 'openai' }
);
```

***

## Chain Tracing

```typescript theme={null}
import { LLMChain } from 'langchain/chains';
import { PromptTemplate } from 'langchain/prompts';

const prompt = PromptTemplate.fromTemplate('Tell me about {topic}');
const chain = new LLMChain({ llm: chat, prompt });

await lumina.traceLLM(
  () => chain.call({ topic: 'AI' }),
  { name: 'langchain-chain', system: 'openai' }
);
```

***

## Agent Tracing

```typescript theme={null}
import { initializeAgentExecutorWithOptions } from 'langchain/agents';

const executor = await initializeAgentExecutorWithOptions(
  tools,
  chat,
  { agentType: 'chat-conversational-react-description' }
);

await lumina.trace('langchain-agent', async () => {
  return await lumina.traceLLM(
    () => executor.call({ input: 'What's the weather?' }),
    { name: 'agent-execution', system: 'openai' }
  );
});
```
