Skip to main content

Connect a LangChain agent to Slack. Return a LangChainAgentConfig from onMessage; Novu invokes the agent and delivers the reply. The same handler works on other providers after you link them.

This guide uses Slack first and assumes an existing Node.js app.

Note

Starting from scratch? See Scaffold with the CLI.

Prerequisites#

  • A Novu account
  • Node.js 22+
  • An existing app with LangChain agent logic
  • A Slack workspace where you can install apps
  • An OPENAI_API_KEY or ANTHROPIC_API_KEY (or another LangChain provider key)

Connect an existing app#

Create the agent and connect Slack#

In the Novu dashboard:

  1. Go to Agents → Create agent.
  2. Under Custom code, pick LangChain.
  3. Set Agent name and Identifier (your code must use the same identifier).
  4. Select Slack, generate a Slack App Configuration Token, paste it, and finish the install / Allow flow.

Alternatively run npx novu connect, choose LangChain and Slack, and skip creating a starter project when prompted. Screenshots: Create a Slack app.

Install packages#

Add to .env.local:

Add the handler#

Create app/novu/agents/<your-identifier>.ts. Match agent('...') to the dashboard Identifier.

Export from app/novu/agents/index.ts:

Returning { model, system } is a LangChainAgentConfig. Novu calls createAgent().invoke() and posts the final text. Novu maps ctx.history on this path.

On Next.js, add LangChain packages to serverExternalPackages for Turbopack. See Next.js and Turbopack.

Add the bridge route#

For Express, Hono, and other servers, see Connecting your app.

Run locally and message Slack#

DM or @mention the bot in Slack. The reply should come from your LangChain handler in the same thread.

Tool approval#

Gate a tool with needsApproval:

See Tool approval and the LangChain reference.

Scaffold with the CLI#

Choose LangChain, authenticate the model, connect Slack, and accept the starter project. Then run npm run dev:novu.

For an existing codebase, use Connect an existing app instead.

FAQ#

Which channels work with a LangChain agent?

Slack, Microsoft Teams, WhatsApp, Telegram, and email. See Channels overview.

Does Novu run LangChain for me?

When you return a LangChainAgentConfig, Novu invokes createAgent() with your model, system prompt, and tools, then posts the final text.

Where is the adapter API documented?

LangChain reference: tool approval, custom invoke, and onError.

I get "Cannot find module as expression is too dynamic"

Turbopack cannot resolve LangChain dynamic provider imports for model strings. Add LangChain packages to serverExternalPackages in next.config.mjs. See Next.js and Turbopack.

Set this up with an AI assistant#

Connect my LangChain agent to Slack with NovuOpen in Cursor

Connect a LangChain agent to Slack with Novu Connect#

Follow https://docs.novu.co/agents/get-started/langchain

Goal#

Add Novu bridge + LangChain config handler to this repo and connect Slack. Prefer the existing project over scaffolding a new one.

Rules#

ALWAYS:

  • Match agent('id') to the Novu dashboard agent Identifier
  • Return a LangChainAgentConfig so Novu can invoke the agent
  • Keep handlers channel-agnostic
  • Follow the project’s package manager and TypeScript conventions

NEVER:

  • Hardcode API keys
  • Rebuild conversation history manually when returning a config

Next steps#