The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
chore(langchain): select ALL rules with exclusions (#31930)
Christophe Bornet1563099f3f49
diff --git a/libs/langchain/langchain/agents/agent.py b/libs/langchain/langchain/agents/agent.pyindex 941f4bc494..acae0280bf 100644--- a/libs/langchain/langchain/agents/agent.py+++ b/libs/langchain/langchain/agents/agent.py@@ -1551,7 +1551,7 @@ class AgentExecutor(Chain):],)- # TODO This could yield each result as it becomes available+ # TODO: This could yield each result as it becomes availablefor chunk in result:yield chunkdiff --git a/libs/langchain/langchain/agents/agent_toolkits/amadeus/__init__.py b/libs/langchain/langchain/agents/agent_toolkits/amadeus/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/libs/langchain/langchain/agents/loading.py b/libs/langchain/langchain/agents/loading.pyindex 2dcdd1c171..59e6e95607 100644--- a/libs/langchain/langchain/agents/loading.py+++ b/libs/langchain/langchain/agents/loading.py@@ -14,7 +14,7 @@ from langchain.agents.agent import BaseMultiActionAgent, BaseSingleActionAgentfrom langchain.agents.types import AGENT_TO_CLASSfrom langchain.chains.loading import load_chain, load_chain_from_config-logger = logging.getLogger(__file__)+logger = logging.getLogger(__name__)URL_BASE = "https://raw.githubusercontent.com/hwchase17/langchain-hub/master/agents/"diff --git a/libs/langchain/langchain/agents/openai_functions_multi_agent/base.py b/libs/langchain/langchain/agents/openai_functions_multi_agent/base.pyindex 5f9c06a269..a32bb2e503 100644--- a/libs/langchain/langchain/agents/openai_functions_multi_agent/base.py+++ b/libs/langchain/langchain/agents/openai_functions_multi_agent/base.py@@ -72,7 +72,7 @@ def _parse_ai_message(message: BaseMessage) -> Union[list[AgentAction], AgentFindel _tool_input["action_name"]function_name = tool_schema["action_name"]- # HACK HACK HACK:+ # A hack here:# The code that encodes tool input into Open AI uses a special variable# name called `__arg1` to handle old style tools that do not expose a# schema and expect a single string argument as an input.diff --git a/libs/langchain/langchain/agents/output_parsers/openai_functions.py b/libs/langchain/langchain/agents/output_parsers/openai_functions.pyindex e452d8d604..f762dd6bb0 100644--- a/libs/langchain/langchain/agents/output_parsers/openai_functions.py+++ b/libs/langchain/langchain/agents/output_parsers/openai_functions.py@@ -55,7 +55,7 @@ class OpenAIFunctionsAgentOutputParser(AgentOutputParser):)raise OutputParserException(msg) from e- # HACK HACK HACK:+ # A hack here:# The code that encodes tool input into Open AI uses a special variable# name called `__arg1` to handle old style tools that do not expose a# schema and expect a single string argument as an input.diff --git a/libs/langchain/langchain/agents/output_parsers/tools.py b/libs/langchain/langchain/agents/output_parsers/tools.pyindex 10ebd3c3df..b7ec8a47aa 100644--- a/libs/langchain/langchain/agents/output_parsers/tools.py+++ b/libs/langchain/langchain/agents/output_parsers/tools.py@@ -56,7 +56,7 @@ def parse_ai_message_to_tool_action()raise OutputParserException(msg) from efor tool_call in tool_calls:- # HACK HACK HACK:+ # A hack here:# The code that encodes tool input into Open AI uses a special variable# name called `__arg1` to handle old style tools that do not expose a# schema and expect a single string argument as an input.diff --git a/libs/langchain/langchain/callbacks/streaming_aiter.py b/libs/langchain/langchain/callbacks/streaming_aiter.pyindex 96cf78fd83..f5f2ba43e6 100644--- a/libs/langchain/langchain/callbacks/streaming_aiter.py+++ b/libs/langchain/langchain/callbacks/streaming_aiter.py@@ -8,7 +8,7 @@ from langchain_core.callbacks import AsyncCallbackHandlerfrom langchain_core.outputs import LLMResultfrom typing_extensions import override-# TODO If used by two LLM runs in parallel this won't work as expected+# TODO: If used by two LLM runs in parallel this won't work as expectedclass AsyncIteratorCallbackHandler(AsyncCallbackHandler):@@ -51,7 +51,7 @@ class AsyncIteratorCallbackHandler(AsyncCallbackHandler):async def on_llm_error(self, error: BaseException, **kwargs: Any) -> None:self.done.set()- # TODO implement the other methods+ # TODO: implement the other methodsasync def aiter(self) -> AsyncIterator[str]:"""Asynchronous iterator that yields tokens."""diff --git a/libs/langchain/langchain/chains/natbot/crawler.py b/libs/langchain/langchain/chains/natbot/crawler.pyindex f42fc1c0e0..d7e8fa2a42 100644--- a/libs/langchain/langchain/chains/natbot/crawler.py+++ b/libs/langchain/langchain/chains/natbot/crawler.py@@ -1,3 +1,4 @@+import loggingimport timefrom sys import platformfrom typing import (@@ -11,6 +12,8 @@ from typing import (if TYPE_CHECKING:from playwright.sync_api import Browser, CDPSession, Page+logger = logging.getLogger(__name__)+black_listed_elements: set[str] = {"html","head",@@ -298,7 +301,7 @@ class Crawler:try:cursor = layout_node_index.index(index)- # TODO replace this with proper cursoring, ignoring the fact this is+ # TODO: replace this with proper cursoring, ignoring the fact this is# O(n^2) for the momentexcept ValueError:continuediff --git a/libs/langchain/langchain/chat_models/base.py b/libs/langchain/langchain/chat_models/base.pyindex 2f8b46bcb5..dec9cd9e7a 100644--- a/libs/langchain/langchain/chat_models/base.py+++ b/libs/langchain/langchain/chat_models/base.py@@ -535,12 +535,6 @@ def _check_pkg(pkg: str, *, pkg_kebab: Optional[str] = None) -> None:raise ImportError(msg)-def _remove_prefix(s: str, prefix: str) -> str:- if s.startswith(prefix):- s = s[len(prefix) :]- return s--_DECLARATIVE_METHODS = ("bind_tools", "with_structured_output")@@ -608,7 +602,7 @@ class _ConfigurableModel(Runnable[LanguageModelInput, Any]):def _model_params(self, config: Optional[RunnableConfig]) -> dict:config = ensure_config(config)model_params = {- _remove_prefix(k, self._config_prefix): v+ k.removeprefix(self._config_prefix): vfor k, v in config.get("configurable", {}).items()if k.startswith(self._config_prefix)}@@ -630,7 +624,7 @@ class _ConfigurableModel(Runnable[LanguageModelInput, Any]):remaining_config["configurable"] = {k: vfor k, v in config.get("configurable", {}).items()- if _remove_prefix(k, self._config_prefix) not in model_params+ if k.removeprefix(self._config_prefix) not in model_params}queued_declarative_operations = list(self._queued_declarative_operations)if remaining_config:diff --git a/libs/langchain/pyproject.toml b/libs/langchain/pyproject.tomlindex 1b96744cba..cdf0add955 100644--- a/libs/langchain/pyproject.toml+++ b/libs/langchain/pyproject.toml@@ -143,70 +143,42 @@ ignore-regex = ".*(Stati Uniti|Tense=Pres).*"ignore-words-list = "momento,collison,ned,foor,reworkd,parth,whats,aapply,mysogyny,unsecure,damon,crate,aadd,symbl,precesses,accademia,nin"[tool.ruff.lint]-select = [- "A", # flake8-builtins- "ARG", # flake8-unused-arguments- "ASYNC", # flake8-async- "B", # flake8-bugbear- "C4", # flake8-comprehensions- "COM", # flake8-commas- "D1", # pydocstyle: missing docstring- "DTZ", # flake8-datetimez- "E", # pycodestyle error- "EM", # flake8-errmsg- "F", # pyflakes- "FA", # flake8-future-annotations- "FBT", # flake8-boolean-trap- "FLY", # flake8-flynt- "G", # flake8-logging-format- "I", # isort- "ICN", # flake8-import-conventions- "INT", # flake8-gettext- "ISC", # isort-comprehensions- "PERF", # flake8-perf- "PGH", # pygrep-hooks- "PIE", # flake8-pie- "PL", # pylint- "PT", # flake8-pytest-style- "PTH", # flake8-use-pathlib- "PYI", # flake8-pyi- "Q", # flake8-quotes- "RET", # flake8-return- "RSE", # flake8-rst-docstrings- "RUF", # ruff- "S", # flake8-bandit- "SIM", # flake8-simplify- "SLF", # flake8-self- "SLOT", # flake8-slots- "T10", # flake8-debugger- "T20", # flake8-print- "TC", # flake8-type-checking- "TID", # flake8-tidy-imports- "TRY", # tryceratops- "UP", # pyupgrade- "W", # pycodestyle warning- "YTT", # flake8-2020-]+select = [ "ALL",]ignore = [+ "C90", # McCabe complexity"COM812", # Messes with the formatter- "ISC001", # Messes with the formatter+ "FIX002", # Line contains TODO"PERF203", # Rarely useful- "PLR09", # Too many something (args, statements, etc)- "S112", # Rarely useful+ "PLR09", # Too many something (arg, statements, etc)"RUF012", # Doesn't play well with Pydantic"TC001", # Doesn't play well with Pydantic"TC002", # Doesn't play well with Pydantic"TC003", # Doesn't play well with Pydantic- "UP007", # pyupgrade: non-pep604-annotation-union+ "TD002", # Missing author in TODO+ "TD003", # Missing issue link in TODO# TODO rules+ "ANN401",+ "BLE","D100", # pydocstyle: missing docstring in public module"D104", # pydocstyle: missing docstring in public package+ "D2",+ "D3",+ "D4",+ "ERA",+ "N","PLC0415", # pylint: import-outside-top-level"TRY301", # tryceratops: raise-within-try]-unfixable = ["B028"] # People should intentionally tune the stacklevel+unfixable = [+ "B028", # People should intentionally tune the stacklevel+ "PLW1510", # People should intentionally set the check argument+]+flake8-annotations.allow-star-arg-any = true+flake8-annotations.mypy-init-return = true+flake8-type-checking.runtime-evaluated-base-classes = ["pydantic.BaseModel","langchain_core.load.serializable.Serializable","langchain_core.runnables.base.RunnableSerializable"]+pep8-naming.classmethod-decorators = [ "classmethod", "langchain_core.utils.pydantic.pre_init", "pydantic.field_validator", "pydantic.v1.root_validator",]pydocstyle.convention = "google"pyupgrade.keep-runtime-typing = true@@ -218,6 +190,13 @@ pyupgrade.keep-runtime-typing = true"SLF001", # Private member access in tests"PLR2004", # Magic value comparisons]+"tests/integration_tests/examples/*.py" = [+ "INP001", # Not a package+ "EXE001", # Only examples+]+"scripts/*.py" = [+ "INP001", # Not a package+]"langchain/chains/constitutional_ai/principles.py" = ["E501", # Line too long]diff --git a/libs/langchain/tests/integration_tests/evaluation/embedding_distance/__init__.py b/libs/langchain/tests/integration_tests/evaluation/embedding_distance/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/libs/langchain/tests/unit_tests/_api/__init__.py b/libs/langchain/tests/unit_tests/_api/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/libs/langchain/tests/unit_tests/agents/test_agent_iterator.py b/libs/langchain/tests/unit_tests/agents/test_agent_iterator.pyindex b061604312..faef1a4f21 100644--- a/libs/langchain/tests/unit_tests/agents/test_agent_iterator.py+++ b/libs/langchain/tests/unit_tests/agents/test_agent_iterator.py@@ -229,8 +229,8 @@ def test_agent_iterator_properties_and_setters() -> None:assert isinstance(agent_iter, AgentExecutorIterator)assert isinstance(agent_iter.inputs, dict)- assert isinstance(agent_iter.callbacks, type(None))- assert isinstance(agent_iter.tags, type(None))+ assert agent_iter.callbacks is None+ assert agent_iter.tags is Noneassert isinstance(agent_iter.agent_executor, AgentExecutor)agent_iter.inputs = "New input" # type: ignore[assignment]diff --git a/libs/langchain/tests/unit_tests/chains/test_hyde.py b/libs/langchain/tests/unit_tests/chains/test_hyde.pyindex ac9894c004..231c31d5c6 100644--- a/libs/langchain/tests/unit_tests/chains/test_hyde.py+++ b/libs/langchain/tests/unit_tests/chains/test_hyde.py@@ -22,12 +22,12 @@ class FakeEmbeddings(Embeddings):@overridedef embed_documents(self, texts: list[str]) -> list[list[float]]:"""Return random floats."""- return [list(np.random.uniform(0, 1, 10)) for _ in range(10)]+ return [list(np.random.default_rng().uniform(0, 1, 10)) for _ in range(10)]@overridedef embed_query(self, text: str) -> list[float]:"""Return random floats."""- return list(np.random.uniform(0, 1, 10))+ return list(np.random.default_rng().uniform(0, 1, 10))class FakeLLM(BaseLLM):diff --git a/libs/langchain/tests/unit_tests/evaluation/regex_match/__init__.py b/libs/langchain/tests/unit_tests/evaluation/regex_match/__init__.pynew file mode 100644index 0000000000..e69de29bb2