LangChain Setup

Connect LangChain to Genten

Send events from your Python agents to Genten and chat with them directly from the dashboard.

Python 3.8+
pip (package manager)
Genten running on port 3001
~15 minutes
Phase 1Register
Phase 2Connect
Phase 3Chat
⚠️
Before you begin: Make sure Genten is running. Start it with npm run dev from your project root and open http://localhost:3001 in your browser to confirm it's up.
1

Register your LangChain agent

Create a Genten identity for your Python agent so it can send events and chat.

In Genten, click Connect Agent in the sidebar

Select LangChain from the framework options

Connect an Agent screen showing framework options: OpenClaw, n8n, LangChain, Generic

Select LangChain from the four framework options.

Name and configure your agent

Give your agent a nickname, pick the model it uses, and choose an accent color. If you plan to chat with this agent from the dashboard (covered in Step 4), enter a Webhook URL now.

ℹ️
What's the Webhook URL? This is the address where your Python agent listens for incoming chat messages from Genten. If you're following this guide, use http://localhost:5001/agent. You'll set up the listener in Step 4. If you only want one-way event monitoring (no chat), leave this blank.

Click Register My Agent

Connect an Agent step 2 showing nickname, model dropdown, webhook URL field, and color selector

Fill in the nickname, model, optional webhook URL, and accent color. Then click Register My Agent.

Save your credentials

After clicking Register My Agent you'll see your credentials screen. All four values are shown here. Click Download Setup Info to save them as a file, or copy them individually.

Agent registered screen showing Connection Address, API Key, Agent ID, and Reply Address

Your credentials screen. Copy the API Key and Agent ID, or click Download Setup Info to save everything as a file. Your values will look different from this screenshot.

After registration you'll see four values. Copy the API Key and Agent ID and store them somewhere safe. You can also click Download Setup Info to save them as a file. If you ever need them again, go to My Agents → click your agent → the Connection Details section shows everything except the full API key. If you lose the API key, go to the agent detail page and click Rotate API Key to generate a new one.

FieldWhat it isWhen you need it
Connection AddressThe URL your agent sends events toStep 3 (sending events)
API KeyYour agent's password for authenticating with GentenEvery API call (Steps 3 and 4)
Agent IDYour agent's unique identifier, needed for chat repliesStep 4 (two-way chat)
Reply AddressThe full URL your agent sends chat replies toStep 4 (two-way chat)
💡
Continue to Setup Instructions -- click this button to see the next wizard screen with pre-filled code snippets using your actual credentials. You can use these as a quick reference or follow this guide for a more detailed walkthrough.
Setup instructions screen showing pre-filled code snippets with the agent credentials

The setup instructions screen has your credentials pre-filled in the code snippets. Click Finish Setup when done.

⚠️
Download your credentials now for safekeeping, or access them anytime from your agent's detail page.
Agent registered. You now have the credentials to connect your Python code to Genten.
Phase 1Register
Phase 2Connect
Phase 3Chat
2

Set up your Python environment

Install the packages your agent needs to talk to Genten.

Check if Python is installed

First, confirm Python is available on your machine. Open your terminal and run:

python3 --version

You should see something like Python 3.11.4. Any version 3.8 or higher is fine.

💡
Don't see a version number? Python isn't installed. You'll need Homebrew to install it. First check if Homebrew is installed:
brew --version

If Homebrew is installed you'll see something like Homebrew 4.2.0. If you see command not found: brew, install Homebrew first. Go to brew.sh or run this command — it will take a few minutes:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once Homebrew is installed, install Python:

brew install python3

This will take a few minutes. Once complete, re-run python3 --version to confirm it installed correctly.

Create a virtual environment

A virtual environment keeps your Python packages isolated to this project so they don't conflict with other Python projects on your machine. Without it, every package you install goes into your system Python — over time this causes version conflicts that are painful to debug. Always use a virtual environment.

Think of it like this: your system Python is a shared kitchen. A virtual environment is your own private kitchen where you control exactly what's in it.

First, navigate to your project folder. Run pwd inside your folder to get your exact path:

pwd

Your output will look something like this — copy it, you'll need it:

/Users/yourname/Desktop/your-project-langchain

Navigate to your folder (replace the path with your own pwd output):

cd /YOUR/PATH/HERE

Create the virtual environment:

python3 -m venv your-project-env

Activate it:

source your-project-env/bin/activate

Once activated, your terminal prompt will change to show (your-project-env) at the start. This confirms the virtual environment is active:

# Before activation:
username@computername your-project-langchain %

# After activation:
(your-project-env) username@computername your-project-langchain %
⚠️
Always activate your virtual environment before working on this project. Run source your-project-env/bin/activate every time you open a new terminal session. If you don't see (your-project-env) in your prompt, you're not inside the virtual environment.

Install required packages

pip3 install requests flask

requests sends events and chat replies to Genten. flask receives chat messages from the dashboard (Step 4). If you only want one-way event monitoring, skip flask.

💡
Already using LangChain? You likely have requests installed already. Just add flask if you want two-way chat.

After running the install command you'll see output like this — Python is downloading and installing the packages:

Collecting requests
  Downloading requests-2.32.5-py3-none-any.whl (64 kB)
Collecting flask
  Downloading flask-3.1.3-py3-none-any.whl (103 kB)
...
Successfully installed blinker-1.9.0 certifi-2026.2.25 flask-3.1.3 requests-2.32.5 ...
WARNING: You are using pip version 21.2.4; however, version 26.0.1 is available.

The Collecting and Downloading lines are normal. Look for Successfully installed at the end — that's your confirmation. Your terminal should still show (your-project-env) prefacing the prompt when done.

ℹ️
You may see warnings after install — messages about PATH or pip version upgrades. These are safely ignorable and won't affect anything in this guide. As long as you see Successfully installed at the end, you're good.
3

Send events to Genten

Your agent tells Genten what it's doing by posting events to the ingest endpoint.

Create your test script

First, create a folder for your LangChain project files and navigate into it. You can put this anywhere on your machine — Desktop, your code folder, wherever you keep projects. Choose your own path:

mkdir /YOUR/PATH/HERE/your-project-langchain
cd /YOUR/PATH/HERE/your-project-langchain

Not sure what path to use? Navigate to where you want the folder in Finder, open a terminal there, and run pwd to get your exact path. For example:

/Users/yourname/Desktop

So your command would be:

mkdir /Users/yourname/Desktop/your-project-langchain
cd /Users/yourname/Desktop/your-project-langchain

Create the test file:

touch langchain_test.py

Open the folder in Finder so you can open the file in your code editor:

open .

Double-click langchain_test.py in Finder to open it in VS Code or your preferred editor. Then paste in the script below. Replace YOUR_API_KEY with the key from Step 1:

import requests

DASHBOARD_URL = "http://localhost:3001"
API_KEY = "YOUR_API_KEY"

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

# Send a chain_start event
r1 = requests.post(
    f"{DASHBOARD_URL}/api/ingest/langchain",
    headers=headers,
    json={
        "event": "chain_start",
        "message": "Smoke test chain started"
    }
)
print(f"chain_start: {r1.status_code} {r1.text}")

# Send a chain_end event with cost
r2 = requests.post(
    f"{DASHBOARD_URL}/api/ingest/langchain",
    headers=headers,
    json={
        "event": "chain_end",
        "message": "Smoke test chain finished",
        "cost": 0.0012
    }
)
print(f"chain_end:   {r2.status_code} {r2.text}")

Run the script:

python3 langchain_test.py

You should see output like this. Mac users on Python 3.9 may see a NotOpenSSLWarning at the top — it's harmless, ignore it:

# Mac Python 3.9 users may see this warning -- safely ignore it:
# NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+...

chain_start: 200 {"ok":true,"eventType":"start"}
chain_end:   200 {"ok":true,"eventType":"log"}

Both lines returning 200 means the connection is working. If you see anything other than 200, check the Troubleshooting section.

Open Activity Feed in Genten to see your events

You should see "Smoke test chain started" and "Smoke test chain finished" with the $0.0012 cost.

Activity Feed showing two test events from Langchain Agent

Both test events visible in Activity Feed with agent name, event type tag, message, and timestamp. If you see these, Step 3 is complete.

Available event types

EventWhat it means
chain_startA LangChain chain has started executing
chain_endA chain finished executing
llm_startAn LLM call has started
llm_endAn LLM call completed
tool_startA tool is being invoked
tool_endA tool invocation completed
agent_actionThe agent is taking an action
agent_finishThe agent has completed its task

Payload format

FieldTypeRequiredDescription
eventstringYesOne of the event types above
messagestringYesDescription of what happened
costnumberNoCost in USD (e.g. 0.0012)
Event monitoring works. Your LangChain agent can now report activity and costs to Genten. To integrate into a real agent, use LangChain's BaseCallbackHandler to post events automatically during chain execution.
Phase 1Register
Phase 2Connect
Phase 3Chat
4

Set up two-way chat

Let users chat with your LangChain agent directly from the Genten dashboard.

Two-way chat requires two things: a Flask server that receives messages from Genten, and a reply call that sends responses back.

How the chat flow works

  1. User sends a message in Genten's Agent Chat
  2. Genten POSTs the message to your agent's Webhook URL
  3. Your Flask server receives the message and processes it
  4. Your code POSTs the reply back to Genten's Reply Address
  5. The reply appears in the chat
Agent detail page showing Connection Details section with Incoming Webhook field filled in

Agent detail page showing the Incoming Webhook field pre-filled. Click Edit to change it at any time.

Agent detail page showing Incoming Webhook field in edit mode

Clicking Edit opens the webhook URL field for editing. Hit Save when done.

ℹ️

What is the webhook URL and why do you need it?

When someone sends a message to your LangChain agent from the Genten dashboard, Genten needs somewhere to deliver that message. The webhook URL is the address of your Flask server. Without it, Genten has nowhere to send the message and chat won't work.

If you only want one-way event monitoring (no chat), you don't need a webhook URL at all.

Setting it: If you entered http://localhost:5001/agent during registration in Step 1, you're already set. If you skipped it, go to My Agents → click your agent → find Incoming Webhook (for two-way chat) → click Edit → enter http://localhost:5001/agent → save.

Changing it later: You can edit the webhook URL anytime on the agent detail page. You'll need to update it when you move your Flask server to a different port or deploy it to a remote server (e.g. replacing localhost:5001 with your production URL).

Create the chat server

Create a new file in the same folder as your langchain_test.py:

touch langchain_chat.py

Open the folder in Finder:

open .

Double-click langchain_chat.py to open it in your editor. Copy only the code block below — do not copy any of the surrounding text. Replace YOUR_API_KEY and YOUR_AGENT_ID with your values from the agent detail page.

ℹ️
Where do I find my API Key and Agent ID? Go to My Agents → click your LangChain agent. The Connection Details section shows your Agent ID and API key preview. Use the Copy buttons to grab them.
from flask import Flask, request
import requests

app = Flask(__name__)

DASHBOARD_URL = "http://localhost:3001"
API_KEY = "YOUR_API_KEY"
AGENT_ID = "YOUR_AGENT_ID"

@app.route("/agent", methods=["POST"])
def handle_message():
    data = request.json
    user_message = data.get("text", "")
    print(f"Received: {user_message}")

    # Replace this with your actual LangChain logic
    reply_text = f"Echo: {user_message}"

    # Send the reply back to Genten
    requests.post(
        f"{DASHBOARD_URL}/api/chat/{AGENT_ID}/reply",
        headers={
            "Authorization": f"Bearer {API_KEY}",
            "Content-Type": "application/json"
        },
        json={"text": reply_text, "model": "langchain"}
    )
    print("Reply sent")
    return "", 204

if __name__ == "__main__":
    print("Agent listening on http://localhost:5001/agent")
    app.run(port=5001)
⚠️
Copy only the code block above — paste everything from from flask import Flask, request down to app.run(port=5001). Do not include any of the surrounding text from this guide.

This is an echo server — it proves the pipeline works. Once verified, replace the reply_text line with your real LangChain logic:

# Example: swap the echo with a real LLM call
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(model="gpt-4o")
result = llm.invoke(user_message)
reply_text = result.content
💡
Where do I find my Agent ID? It's on the credentials screen from Step 1 as its own copyable field. You can also find it on the agent detail page (My Agents → click your agent).
5

Test the chat

Start your Flask server and send a message from the Genten dashboard.

python3 langchain_chat.py

You should see this output — the "development server" warning is normal and expected for local use:

Agent listening on http://localhost:5001/agent
 * Serving Flask app 'langchain_chat'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production
deployment. Use a production WSGI server instead.
 * Running on http://127.0.0.1:5001
Press CTRL+C to quit
⚠️
Leave this terminal window open. Do not press CTRL+C. Your Flask server must stay running for chat to work. Open a new terminal window for any other commands.

Now go to Genten:

1 →

Click Agent Chat in the sidebar

2 →

Type @ in the message input to bring up the agent selector

3 →

Select your LangChain agent and send a message

Your Flask terminal should print Received: [your message] and Reply sent. The reply should appear in Genten chat within a second or two.

Genten Agent Chat showing a message sent to the LangChain agent and the echo reply

The echo reply confirms the full pipeline is working: Genten → Flask → Genten. Replace the echo logic with your real LangChain code to get AI responses.

Two-way chat works. Your LangChain agent can receive messages from the Genten dashboard and respond. Replace the echo logic with your actual chain or agent to get real AI responses.
!

Troubleshooting

ProblemWhy it happensHow to fix it
401 Unauthorized API key wrong or missing "Bearer " prefix Make sure your Authorization header is Bearer acc_your_key_here with a space between "Bearer" and the key. If you lost the key, go to agent detail and click Rotate API Key.
400 Invalid event Event name not in the allowed list Use one of: chain_start, chain_end, llm_start, llm_end, tool_start, tool_end, agent_action, agent_finish
400 Missing fields Both event and message are required Make sure your JSON body has both fields. cost is optional.
Chat message sent but no reply Webhook URL not set, or Flask server not running Check your agent has a webhook URL (My Agents → agent detail). Make sure Flask is running on the matching port. Check the Flask terminal for errors.
ModuleNotFoundError: requests requests not installed in your active Python env Run pip install requests. If using a virtual env, activate it first.
Events not in Activity Feed Kill switch may be active, or event sent before feed was open Check Settings for kill switch status. Open Activity Feed before sending events, or refresh after.
Agent shows "Idle" on My Agents Normal for agents not yet used Send an event or chat message. The agent will switch to an active state.
python3: command not found Python not installed on your machine Install via Homebrew: brew install python3. If you don't have Homebrew, install it first at brew.sh.
NotOpenSSLWarning on script run Mac Python 3.9 uses LibreSSL instead of OpenSSL Harmless warning — ignore it. Your events will still send correctly. Upgrading to Python 3.11+ via Homebrew will eliminate it.
pip: command not found On Mac, pip is often pip3 Use pip3 instead of pip for all install commands.
?

FAQ

Register a LangChain agent in Genten's Connect Agent wizard. You'll receive a Connection Address and API Key. Use these in your Python code to POST events to /api/ingest/langchain with a Bearer token in the Authorization header.

Yes — via the Flask webhook pattern covered in Steps 4 and 5. Genten sends messages to your webhook URL, your Python server processes them with your LangChain logic, and POSTs the reply back to Genten's reply endpoint. It works with any LangChain chain or agent.

Send events that match key moments in your chain execution: chain_start and chain_end for chain lifecycle, llm_start and llm_end for model calls, tool_start and tool_end for tool use. Include a cost field on LLM events for accurate spend tracking in Genten's Spending page.

The cleanest approach is to implement LangChain's BaseCallbackHandler and wire it into your chain — that way events fire automatically without manual calls in your business logic.

Yes, for two-way chat to work. If the Flask server isn't running when someone sends a message in Genten, the webhook call will fail and no reply will appear. For production use, run your Flask server as a persistent process using a tool like systemd, supervisor, or a Docker container. For local development, just keep the terminal open.

No — the webhook URL is only required for two-way chat. If you only want to monitor events and costs from your LangChain agent, you can skip it entirely. Just complete Steps 1–3 and ignore the chat setup in Steps 4 and 5.

Check three things in order: (1) Is your Flask server still running in the terminal? If you closed that window, restart it with python3 langchain_chat.py. (2) Is the webhook URL set on your agent? Go to My Agents → click your agent → check Incoming Webhook shows your URL, not "Not configured". (3) Does the webhook URL match the port your Flask server is running on?

Yes, this is a known display bug that does not affect functionality. Your message was only sent once and the agent only received it once. The agent reply is unaffected. This will be fixed in an upcoming release.

Yes. Complex chains and LLM calls can take 30–60 seconds depending on the model and what your chain is doing. Leave the chat open — the reply will appear when the chain completes. Don't send the message again thinking it didn't work.

Yes — go to My Agents → click your agent → find "Incoming Webhook (for two-way chat)" → click Edit. You'll need to update this when you move from local development to a production server.

The echo server in this guide has no memory — each message is handled in isolation. To add conversation history, store previous messages in your Flask app and pass them into your LangChain chain on each request. LangChain's ConversationBufferMemory is a good starting point for this.

For local development, it's fine as-is. For production, anyone who knows your webhook URL can POST to it and trigger your agent. Add request validation inside your Flask handler to verify payloads are coming from Genten — check for a known field or add a shared secret header to your requests.

Genten will attempt to deliver the message but get no response. The chat will appear to hang with no reply. Restart your Flask server with python3 langchain_chat.py and send the message again.

Yes. Change app.run(port=5001) to any available port, and update the Webhook URL in your agent's settings to match. Just make sure the URL you register in Genten matches the actual port your Flask server is listening on.

Setup Complete Checklist

LangChain agent registered in Genten with API key saved
Python 3.8+ confirmed installed
Virtual environment created and activated — (your-project-env) showing in terminal prompt
requests and flask installed inside virtual environment
Test events sent successfully (200 responses)
Events visible in Genten Activity Feed
Webhook URL configured on agent
Flask chat server running and receiving messages
Chat reply appears in Genten Agent Chat