neurotrace.core.adapters.langchain_adapter
¶
neurotrace.core.adapters.langchain_adapter
¶
LangChain Adapter Module.
This module provides adapter functions for converting between neurotrace's internal Message format and LangChain's message formats. It handles bidirectional conversion between neurotrace Messages and LangChain's HumanMessage/AIMessage types.
from_langchain_message(msg, role=None)
¶
Convert a LangChain message to a neurotrace Message.
This function transforms a LangChain message into neurotrace's Message format, with automatic role detection based on the message type or an optional explicit role override.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
msg
|
BaseMessage
|
The LangChain message to convert. |
required |
role
|
Optional[str]
|
Explicitly specify the role to use. If None, role is detected from the message type. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
Message |
Message
|
A neurotrace Message with: - role determined by message type or override - content from the original message |
Example
lc_msg = HumanMessage(content="Hello") msg = from_langchain_message(lc_msg) print(msg.role) # "user" print(msg.content) # "Hello"