launchdarkly-ai-langchain-messages
LangChain handler for launchdarkly-ai-server using LangChain chat models (langchain-core). Works with any BaseChatModel — defaults to ChatOpenAI. Runs a manual tool-call loop using LangChain's bind_tools API.
provides_for: ['*', 'messages'] — matches any flag variation where meta.mode is "messages" and no more-specific handler is registered. LangChain is a framework adapter, not a provider: it routes through langchain-anthropic, langchain-openai, and others at runtime based on config.provider.name. Use '*' so that flags configured with provider.name = "Anthropic" or "OpenAI" are automatically handled without requiring a separate native handler.
Installation
pip install launchdarkly-ai-server launchdarkly-ai-langchain-messages
The default model is ChatOpenAI, so set OPENAI_API_KEY unless you pass a custom BaseChatModel.
Usage
With the default model (ChatOpenAI)
import asyncio
from launchdarkly_ai_server import config, shutdown
from launchdarkly_ai_langchain_messages import create_langchain_messages_handler
async def main():
result = await config(
key="my-ai-config-flag",
handler=create_langchain_messages_handler(),
).invoke("What is feature flagging?", {"kind": "user", "key": "user-123"})
print(result.response)
await shutdown()
asyncio.run(main())
With a custom BaseChatModel
from langchain_anthropic import ChatAnthropic
from launchdarkly_ai_langchain_messages import create_langchain_messages_handler
handler = create_langchain_messages_handler(ChatAnthropic(model="claude-opus-4-5"))
Convenience wrapper
import asyncio
from launchdarkly_ai_langchain_messages import langchain_messages
async def main():
user_input = "What is feature flagging?"
result = await langchain_messages(
user_input,
{"kind": "user", "key": "user-123"},
{"key": "my-ai-config-flag"},
variables={"user_input": user_input},
)
print(result.response)
asyncio.run(main())
How It Works
- Uses the system prompt and conversation history defined in your LaunchDarkly flag config.
- Template placeholders (
{{variable}}) in the prompt are substituted usingvariablesbefore the call. - If tools are defined in the flag config, binds them to the model and executes them as requested, feeding results back until the model produces a final response.
- Emits an OTel span and LaunchDarkly telemetry for every call.
Choosing Between langchain-agents and langchain-messages
langchain-agents |
langchain-messages |
|
|---|---|---|
| Orchestration | LangGraph StateGraph |
Manual tool loop |
| Reasoning style | ReAct (reason + act cycles) | Single invoke per tool round-trip |
| Best for | Complex multi-step reasoning | Straightforward tool calls |
Environment Variables
| Variable | Description |
|---|---|
OPENAI_API_KEY |
Required when using the default ChatOpenAI model |
LD_SDK_KEY |
LaunchDarkly server-side SDK key |
LD_SERVICE_NAME |
OTel service.name resource attribute (default: python-sdk) |
LD_ENVIRONMENT |
deployment.environment attribute attached to telemetry |
OTEL_EXPORTER_OTLP_ENDPOINT |
OTLP endpoint override (default: LaunchDarkly Observability backend) |
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file launchdarkly_ai_langchain_messages-0.1.4.tar.gz.
File metadata
- Download URL: launchdarkly_ai_langchain_messages-0.1.4.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd5a308efc4017b0d28bbbcc3139ae8a35455fbcba629dc54e347cbfe8f8e276
|
|
| MD5 |
44912aa2c09e9376095ca93fb8a5b064
|
|
| BLAKE2b-256 |
9f80367dd293dce58dfd1c2f3e2a1e3e4cfe10d48b71824160039ebd1d34d066
|
File details
Details for the file launchdarkly_ai_langchain_messages-0.1.4-py3-none-any.whl.
File metadata
- Download URL: launchdarkly_ai_langchain_messages-0.1.4-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42c18c6785fa9d395c615ec7453523960031ec4132023d9b0818bc49248d61f4
|
|
| MD5 |
688a00d2b37b9cd882ad6545d5f1c91e
|
|
| BLAKE2b-256 |
48d4cf33560d0426b3c52ef247e0314f1ead94bafcb9d7051a20cab517c6d4c9
|