Skip to content

chore(core): improve typing of messages utils functions#34225

Merged
Mason Daugherty (mdrxy) merged 2 commits into
langchain-ai:masterfrom
cbornet:messages-utils-types
Dec 8, 2025
Merged

chore(core): improve typing of messages utils functions#34225
Mason Daugherty (mdrxy) merged 2 commits into
langchain-ai:masterfrom
cbornet:messages-utils-types

Conversation

@cbornet
Copy link
Copy Markdown
Collaborator

@cbornet Christophe Bornet (cbornet) commented Dec 5, 2025

With this we get the correct types for _runnable_support annotated functions.

  • return list[BaseMessage] when messages is not None
  • return Runnable when messages is None
  • typing of function args

@github-actions github-actions Bot added core `langchain-core` package issues & PRs infra PRs made that include chores, devops, repo meta changes labels Dec 5, 2025

# test explicitly excluding all tool calls
actual = filter_messages(messages, exclude_tool_calls={"1", "2"})
actual = filter_messages(messages, exclude_tool_calls=["1", "2"])
Copy link
Copy Markdown
Collaborator Author

@cbornet Christophe Bornet (cbornet) Dec 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It found some incorrect typing 😃

@github-actions github-actions Bot added infra PRs made that include chores, devops, repo meta changes and removed infra PRs made that include chores, devops, repo meta changes labels Dec 5, 2025
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Dec 5, 2025

CodSpeed Performance Report

Merging #34225 will not alter performance

Comparing cbornet:messages-utils-types (6b95a89) with master (80c3970)

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

Summary

✅ 13 untouched
⏩ 21 skipped1

Footnotes

  1. 21 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@github-actions github-actions Bot added infra PRs made that include chores, devops, repo meta changes and removed infra PRs made that include chores, devops, repo meta changes labels Dec 5, 2025
@github-actions github-actions Bot added infra PRs made that include chores, devops, repo meta changes and removed infra PRs made that include chores, devops, repo meta changes labels Dec 6, 2025

def test_trim_messages_bad_token_counter() -> None:
trimmer = trim_messages(max_tokens=10, token_counter={})
trimmer = trim_messages(max_tokens=10, token_counter={}) # type: ignore[call-overload]
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is now typing for _runnable_support annotated method args.

@github-actions github-actions Bot added langchain `langchain` package issues & PRs infra PRs made that include chores, devops, repo meta changes and removed infra PRs made that include chores, devops, repo meta changes labels Dec 6, 2025
@mdrxy Mason Daugherty (mdrxy) merged commit a64aee3 into langchain-ai:master Dec 8, 2025
88 checks passed
@cbornet Christophe Bornet (cbornet) deleted the messages-utils-types branch December 8, 2025 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core `langchain-core` package issues & PRs external infra PRs made that include chores, devops, repo meta changes langchain `langchain` package issues & PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants