Quickstart

LangChain

Use Bluebag with LangChain agents.

Bluebag ships native support for LangChain. Here's how to get started:

1. Install dependencies

npm install @bluebag/langchain langchain @langchain/openai

Peer dependency

@bluebag/langchain requires @langchain/core ^0.3.0 as a peer dependency.

2. Add your API key

Set BLUEBAG_API_KEY in your environment (see API Keys).

3. Create a LangChain agent

import { createAgent } from "langchain";
import { HumanMessage } from "@langchain/core/messages";
import { Bluebag } from "@bluebag/langchain";
import { tool } from "@langchain/core/tools";
import { z } from "zod";

const apiKey = process.env.BLUEBAG_API_KEY;
if (!apiKey) {
  throw new Error("Missing BLUEBAG_API_KEY");
}

// Create the Bluebag client
const bluebag = new Bluebag({ apiKey });

// Your custom tool
const getWeather = tool(
  ({ city }) => `It's always sunny in ${city}!`,
  {
    name: "get_weather",
    description: "Get the weather for a city",
    schema: z.object({ city: z.string() }),
  }
);

// Enhance your config - Bluebag merges in tools, messages, and system prompt
const config = await bluebag.enhance({
  model: "openai:gpt-4o",
  tools: [getWeather],
  systemMessage: "You are a helpful assistant.",
  messages: [new HumanMessage("Create a Python script that calculates fibonacci numbers")],
});

// Create a LangChain agent
const agent = createAgent({
  model: config.model,
  tools: config.tools,
  systemPrompt: config.systemMessage,
});

// Run the agent
const result = await agent.invoke({
  messages: config.messages,
});

console.log(result.messages.at(-1)?.content);

File handling

When you pass messages to enhance(), Bluebag automatically uploads any file attachments to the sandbox and adds text references for the agent.

4. Configure session options

Use activeSkills to scope which Skills can run, and stableId to keep per-user session context across calls:

const bluebag = new Bluebag({
  apiKey,
  activeSkills: ["pdf-processing"],
  stableId: "demo-user-123",
});

const config = await bluebag.enhance({
  model: "openai:gpt-4o",
  messages: [new HumanMessage("Hello from Bluebag.")],
});

On this page