- Notifications
You must be signed in to change notification settings - Fork19.9k
feat(core): add as_message_state and to_message_state utilities with tests#34089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Conversation
CodSpeed Performance ReportMerging#34089 willnot alter performanceComparing
|
davicaetano commentedNov 24, 2025
Thanks for the effort here. Just for context: the intended workflow is usually to discuss the problem and the proposed approach in the issue before jumping into an implementation. I already have a working implementation locally and was waiting for feedback or approval from the maintainers on the design direction before opening my PR. To keep the conversation structured, it would be best to move the technical discussion back to the issue so we can align on the expected behavior and API before finalizing any implementation. |
Description
This PR introduces two new utility helpers,
as_message_stateandto_message_state,to normalize LangChain
BaseMessageobjects into a consistent message-state format.These helpers simplify handling of different return types from LLM calls (e.g.,
strings, lists, AIMessage, SystemMessage, dict forms, etc.) and ensure that
message state is returned in a structured list format.
Additionally, this PR includes accompanying unit tests validating conversions
across all supported message types.
Key additions
as_message_stateandto_message_stateutility functionsAIMessage,HumanMessage,SystemMessagestrBaseMessagelistof mixed message objectsdictcontaining amessageskeyIssue
Fixes#34061 (message normalization utilities discussion)
Dependencies
None