Skip to main content
Runnable example in examples/langchain/, a GPT-powered chat agent with approvals, selections, and forms via WebSocket.

Overview

Placet integrates with LangChain as a human-in-the-loop tool. Your LangChain agent receives messages in real-time via WebSocket and can send replies, request approvals, present selections, or ask the user to fill in forms, all rendered natively in the Placet UI. The agent uses four tools: Blocking tools wait for the user’s response via a WebSocket review:responded event (up to 5 minutes).

Message Helper

All tools post messages through the same helper:

Tools

send_message

Fire-and-forget: sends a message and returns immediately:

ask_approval

Shows Approve / Reject buttons. Blocks until the user clicks one:

ask_selection

Presents a list of options for the user to pick from:

ask_form

Shows a form with input fields:

Waiting for Reviews via WebSocket

The blocking tools above call wait_review(), which uses a threading.Event that gets set when the WebSocket delivers the review:responded event for the corresponding message:
The WebSocket handler fills _review_results and signals the event:
This avoids HTTP long-polling entirely. Reviews resolve in real-time over the same WebSocket connection.

Agent

Wire the tools into a ChatGPT agent with explicit instructions to always use tools (the agent’s plain-text output is not visible to the user):

WebSocket Connection

The agent connects via Socket.IO, subscribes to its channel, and dispatches incoming user messages to the LangChain executor:

WebSocket Authentication

Placet WebSocket supports API key authentication for agents. Pass your API key directly in the connection’s auth object: