Skip to content

Commit efdfa00

Browse files
cbornetmdrxy
andauthored
chore(langchain): add ruff rules ARG (#32110)
See https://docs.astral.sh/ruff/rules/#flake8-unused-arguments-arg Co-authored-by: Mason Daugherty <[email protected]>
1 parent a2ad5ac commit efdfa00

File tree

79 files changed

+241
-62
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+241
-62
lines changed

libs/langchain/langchain/agents/agent.py

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,15 @@ def input_keys(self) -> list[str]:
116116
def return_stopped_response(
117117
self,
118118
early_stopping_method: str,
119-
intermediate_steps: list[tuple[AgentAction, str]],
120-
**kwargs: Any,
119+
intermediate_steps: list[tuple[AgentAction, str]], # noqa: ARG002
120+
**_: Any,
121121
) -> AgentFinish:
122122
"""Return response when agent has been stopped due to max iterations.
123123
124124
Args:
125125
early_stopping_method: Method to use for early stopping.
126126
intermediate_steps: Steps the LLM has taken to date,
127127
along with observations.
128-
**kwargs: User inputs.
129128
130129
Returns:
131130
AgentFinish: Agent finish object.
@@ -168,6 +167,7 @@ def _agent_type(self) -> str:
168167
"""Return Identifier of an agent type."""
169168
raise NotImplementedError
170169

170+
@override
171171
def dict(self, **kwargs: Any) -> builtins.dict:
172172
"""Return dictionary representation of agent.
173173
@@ -289,16 +289,15 @@ def input_keys(self) -> list[str]:
289289
def return_stopped_response(
290290
self,
291291
early_stopping_method: str,
292-
intermediate_steps: list[tuple[AgentAction, str]],
293-
**kwargs: Any,
292+
intermediate_steps: list[tuple[AgentAction, str]], # noqa: ARG002
293+
**_: Any,
294294
) -> AgentFinish:
295295
"""Return response when agent has been stopped due to max iterations.
296296
297297
Args:
298298
early_stopping_method: Method to use for early stopping.
299299
intermediate_steps: Steps the LLM has taken to date,
300300
along with observations.
301-
**kwargs: User inputs.
302301
303302
Returns:
304303
AgentFinish: Agent finish object.
@@ -317,6 +316,7 @@ def _agent_type(self) -> str:
317316
"""Return Identifier of an agent type."""
318317
raise NotImplementedError
319318

319+
@override
320320
def dict(self, **kwargs: Any) -> builtins.dict:
321321
"""Return dictionary representation of agent."""
322322
_dict = super().model_dump()
@@ -651,6 +651,7 @@ def input_keys(self) -> list[str]:
651651
"""
652652
return list(set(self.llm_chain.input_keys) - {"intermediate_steps"})
653653

654+
@override
654655
def dict(self, **kwargs: Any) -> builtins.dict:
655656
"""Return dictionary representation of agent."""
656657
_dict = super().dict()
@@ -735,6 +736,7 @@ class Agent(BaseSingleActionAgent):
735736
allowed_tools: Optional[list[str]] = None
736737
"""Allowed tools for the agent. If None, all tools are allowed."""
737738

739+
@override
738740
def dict(self, **kwargs: Any) -> builtins.dict:
739741
"""Return dictionary representation of agent."""
740742
_dict = super().dict()
@@ -750,18 +752,6 @@ def return_values(self) -> list[str]:
750752
"""Return values of the agent."""
751753
return ["output"]
752754

753-
def _fix_text(self, text: str) -> str:
754-
"""Fix the text.
755-
756-
Args:
757-
text: Text to fix.
758-
759-
Returns:
760-
str: Fixed text.
761-
"""
762-
msg = "fix_text not implemented for this agent."
763-
raise ValueError(msg)
764-
765755
@property
766756
def _stop(self) -> list[str]:
767757
return [
@@ -1021,13 +1011,15 @@ class ExceptionTool(BaseTool):
10211011
description: str = "Exception tool"
10221012
"""Description of the tool."""
10231013

1014+
@override
10241015
def _run(
10251016
self,
10261017
query: str,
10271018
run_manager: Optional[CallbackManagerForToolRun] = None,
10281019
) -> str:
10291020
return query
10301021

1022+
@override
10311023
async def _arun(
10321024
self,
10331025
query: str,
@@ -1188,6 +1180,7 @@ def _action_agent(self) -> Union[BaseSingleActionAgent, BaseMultiActionAgent]:
11881180
return cast("RunnableAgentType", self.agent)
11891181
return self.agent
11901182

1183+
@override
11911184
def save(self, file_path: Union[Path, str]) -> None:
11921185
"""Raise error - saving not supported for Agent Executors.
11931186
@@ -1218,7 +1211,7 @@ def iter(
12181211
callbacks: Callbacks = None,
12191212
*,
12201213
include_run_info: bool = False,
1221-
async_: bool = False, # arg kept for backwards compat, but ignored
1214+
async_: bool = False, # noqa: ARG002 arg kept for backwards compat, but ignored
12221215
) -> AgentExecutorIterator:
12231216
"""Enables iteration over steps taken to reach final output.
12241217

libs/langchain/langchain/agents/chat/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
)
1414
from langchain_core.tools import BaseTool
1515
from pydantic import Field
16+
from typing_extensions import override
1617

1718
from langchain._api.deprecation import AGENT_DEPRECATION_WARNING
1819
from langchain.agents.agent import Agent, AgentOutputParser
@@ -65,6 +66,7 @@ def _construct_scratchpad(
6566
return agent_scratchpad
6667

6768
@classmethod
69+
@override
6870
def _get_default_output_parser(cls, **kwargs: Any) -> AgentOutputParser:
6971
return ChatOutputParser()
7072

libs/langchain/langchain/agents/conversational/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from langchain_core.prompts import PromptTemplate
1212
from langchain_core.tools import BaseTool
1313
from pydantic import Field
14+
from typing_extensions import override
1415

1516
from langchain._api.deprecation import AGENT_DEPRECATION_WARNING
1617
from langchain.agents.agent import Agent, AgentOutputParser
@@ -35,6 +36,7 @@ class ConversationalAgent(Agent):
3536
"""Output parser for the agent."""
3637

3738
@classmethod
39+
@override
3840
def _get_default_output_parser(
3941
cls,
4042
ai_prefix: str = "AI",

libs/langchain/langchain/agents/conversational_chat/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
)
2121
from langchain_core.tools import BaseTool
2222
from pydantic import Field
23+
from typing_extensions import override
2324

2425
from langchain.agents.agent import Agent, AgentOutputParser
2526
from langchain.agents.conversational_chat.output_parser import ConvoOutputParser
@@ -42,6 +43,7 @@ class ConversationalChatAgent(Agent):
4243
"""Template for the tool response."""
4344

4445
@classmethod
46+
@override
4547
def _get_default_output_parser(cls, **kwargs: Any) -> AgentOutputParser:
4648
return ConvoOutputParser()
4749

libs/langchain/langchain/agents/mrkl/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from langchain_core.tools import BaseTool, Tool
1313
from langchain_core.tools.render import render_text_description
1414
from pydantic import Field
15+
from typing_extensions import override
1516

1617
from langchain._api.deprecation import AGENT_DEPRECATION_WARNING
1718
from langchain.agents.agent import Agent, AgentExecutor, AgentOutputParser
@@ -51,6 +52,7 @@ class ZeroShotAgent(Agent):
5152
output_parser: AgentOutputParser = Field(default_factory=MRKLOutputParser)
5253

5354
@classmethod
55+
@override
5456
def _get_default_output_parser(cls, **kwargs: Any) -> AgentOutputParser:
5557
return MRKLOutputParser()
5658

libs/langchain/langchain/agents/openai_functions_agent/agent_token_buffer_memory.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from langchain_core.language_models import BaseLanguageModel
66
from langchain_core.messages import BaseMessage, get_buffer_string
7+
from typing_extensions import override
78

89
from langchain.agents.format_scratchpad import (
910
format_to_openai_function_messages,
@@ -55,6 +56,7 @@ def memory_variables(self) -> list[str]:
5556
"""
5657
return [self.memory_key]
5758

59+
@override
5860
def load_memory_variables(self, inputs: dict[str, Any]) -> dict[str, Any]:
5961
"""Return history buffer.
6062

libs/langchain/langchain/agents/react/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from langchain_core.prompts import BasePromptTemplate
1212
from langchain_core.tools import BaseTool, Tool
1313
from pydantic import Field
14+
from typing_extensions import override
1415

1516
from langchain._api.deprecation import AGENT_DEPRECATION_WARNING
1617
from langchain.agents.agent import Agent, AgentExecutor, AgentOutputParser
@@ -38,6 +39,7 @@ class ReActDocstoreAgent(Agent):
3839
output_parser: AgentOutputParser = Field(default_factory=ReActOutputParser)
3940

4041
@classmethod
42+
@override
4143
def _get_default_output_parser(cls, **kwargs: Any) -> AgentOutputParser:
4244
return ReActOutputParser()
4345

@@ -47,6 +49,7 @@ def _agent_type(self) -> str:
4749
return AgentType.REACT_DOCSTORE
4850

4951
@classmethod
52+
@override
5053
def create_prompt(cls, tools: Sequence[BaseTool]) -> BasePromptTemplate:
5154
"""Return default prompt."""
5255
return WIKI_PROMPT
@@ -141,6 +144,7 @@ class ReActTextWorldAgent(ReActDocstoreAgent):
141144
"""Agent for the ReAct TextWorld chain."""
142145

143146
@classmethod
147+
@override
144148
def create_prompt(cls, tools: Sequence[BaseTool]) -> BasePromptTemplate:
145149
"""Return default prompt."""
146150
return TEXTWORLD_PROMPT

libs/langchain/langchain/agents/self_ask_with_search/base.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from langchain_core.runnables import Runnable, RunnablePassthrough
1212
from langchain_core.tools import BaseTool, Tool
1313
from pydantic import Field
14+
from typing_extensions import override
1415

1516
from langchain.agents.agent import Agent, AgentExecutor, AgentOutputParser
1617
from langchain.agents.agent_types import AgentType
@@ -32,6 +33,7 @@ class SelfAskWithSearchAgent(Agent):
3233
output_parser: AgentOutputParser = Field(default_factory=SelfAskOutputParser)
3334

3435
@classmethod
36+
@override
3537
def _get_default_output_parser(cls, **kwargs: Any) -> AgentOutputParser:
3638
return SelfAskOutputParser()
3739

@@ -41,6 +43,7 @@ def _agent_type(self) -> str:
4143
return AgentType.SELF_ASK_WITH_SEARCH
4244

4345
@classmethod
46+
@override
4447
def create_prompt(cls, tools: Sequence[BaseTool]) -> BasePromptTemplate:
4548
"""Prompt does not depend on tools."""
4649
return PROMPT

libs/langchain/langchain/agents/structured_chat/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def _validate_tools(cls, tools: Sequence[BaseTool]) -> None:
7171
pass
7272

7373
@classmethod
74+
@override
7475
def _get_default_output_parser(
7576
cls,
7677
llm: Optional[BaseLanguageModel] = None,

libs/langchain/langchain/agents/tools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
CallbackManagerForToolRun,
88
)
99
from langchain_core.tools import BaseTool, tool
10+
from typing_extensions import override
1011

1112

1213
class InvalidTool(BaseTool):
@@ -17,6 +18,7 @@ class InvalidTool(BaseTool):
1718
description: str = "Called when tool name is invalid. Suggests valid tool names."
1819
"""Description of the tool."""
1920

21+
@override
2022
def _run(
2123
self,
2224
requested_tool_name: str,
@@ -30,6 +32,7 @@ def _run(
3032
f"try one of [{available_tool_names_str}]."
3133
)
3234

35+
@override
3336
async def _arun(
3437
self,
3538
requested_tool_name: str,

0 commit comments

Comments
 (0)