-
Notifications
You must be signed in to change notification settings - Fork 20.5k
refactor(core): eagerly validate trim_messages arguments
#34585
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 our terms of service and privacy 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?
refactor(core): eagerly validate trim_messages arguments
#34585
Conversation
Merging this PR will not alter performance
|
dc05a73 to
a25057c
Compare
ddf588b to
f3255c5
Compare
f3255c5 to
3fd9376
Compare
trim_messages arguments
|
Hi , just a gentle bump on this. I've rebased on the latest main to ensure there are no conflicts with the recent 100+ commits, and verified the linting passes. |
PR Title
refactor(core): eagerly validate trim_messages arguments
PR Description
This PR refactors
trim_messagesin langchain-core to validate its arguments (specificallytoken_counter,strategy,start_on, andinclude_system) eagerly at initialization time, rather than lazily when the returnedRunnableis invoked.Motivation
Previously,
trim_messageswas decorated with@_runnable_support, which deferred argument validation until the returnedRunnablewas actually invoked. This caused errors to surface late in the execution flow, making debugging harder.This refactor removes the decorator and manually constructs a
RunnableLambda, enabling fail-fast behavior by validating inputs immediately and improving developer experience.Changes
@_runnable_supportdecorator fromtrim_messages.token_counterstrategyandtoken_counterstart_on,include_system).messages=Nonecase to return aRunnableLambdaafter validation, preserving original behavior.test_trim_messages_bad_token_counterintest_utils.pyto expect an eagerValueError.Related Issues
libs/core/langchain_core/messages/utils.py.Checklist
(
libs/core/tests/unit_tests/messages/test_utils.py)test_trim_messages_bad_token_counterto assert eager validation.