Skip to content

Commit 37b593e

Browse files
committed
chore(langchain): add ruff rules D
1 parent f896bcd commit 37b593e

File tree

143 files changed

+784
-701
lines changed

Some content is hidden

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

143 files changed

+784
-701
lines changed

libs/langchain/langchain/agents/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
"""
2-
**Agent** is a class that uses an LLM to choose a sequence of actions to take.
1+
"""**Agent** is a class that uses an LLM to choose a sequence of actions to take.
32
43
In Chains, a sequence of actions is hardcoded. In Agents,
54
a language model is used as a reasoning engine to determine which actions

libs/langchain/langchain/agents/agent.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,6 @@ def save(self, file_path: Union[Path, str]) -> None:
366366

367367
def tool_run_logging_kwargs(self) -> builtins.dict:
368368
"""Return logging kwargs for tool run."""
369-
370369
return {}
371370

372371

@@ -1807,7 +1806,6 @@ async def astream(
18071806
Yields:
18081807
AddableDict: Addable dictionary.
18091808
"""
1810-
18111809
config = ensure_config(config)
18121810
iterator = AgentExecutorIterator(
18131811
self,

libs/langchain/langchain/agents/agent_iterator.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ def __init__(
5555
include_run_info: bool = False,
5656
yield_actions: bool = False,
5757
):
58-
"""
58+
"""Initialize the AgentExecutorIterator.
59+
5960
Initialize the AgentExecutorIterator with the given AgentExecutor,
6061
inputs, and optional callbacks.
6162
@@ -129,7 +130,8 @@ def color_mapping(self) -> dict[str, str]:
129130
)
130131

131132
def reset(self) -> None:
132-
"""
133+
"""Reset the iterator to its initial state.
134+
133135
Reset the iterator to its initial state, clearing intermediate steps,
134136
iterations, and time elapsed.
135137
"""
@@ -141,9 +143,7 @@ def reset(self) -> None:
141143
self.start_time = time.time()
142144

143145
def update_iterations(self) -> None:
144-
"""
145-
Increment the number of iterations and update the time elapsed.
146-
"""
146+
"""Increment the number of iterations and update the time elapsed."""
147147
self.iterations += 1
148148
self.time_elapsed = time.time() - self.start_time
149149
logger.debug(
@@ -242,9 +242,10 @@ def __iter__(self: AgentExecutorIterator) -> Iterator[AddableDict]:
242242
yield self._stop(run_manager)
243243

244244
async def __aiter__(self) -> AsyncIterator[AddableDict]:
245-
"""
245+
"""Create an async iterator for the AgentExecutor.
246+
246247
N.B. __aiter__ must be a normal method, so need to initialize async run manager
247-
on first __anext__ call where we can await it
248+
on first __anext__ call where we can await it.
248249
"""
249250
logger.debug("Initialising AgentExecutorIterator (async)")
250251
self.reset()
@@ -326,7 +327,8 @@ def _process_next_step_output(
326327
next_step_output: Union[AgentFinish, list[tuple[AgentAction, str]]],
327328
run_manager: CallbackManagerForChainRun,
328329
) -> AddableDict:
329-
"""
330+
"""Process the output of the next step.
331+
330332
Process the output of the next step,
331333
handling AgentFinish and tool return cases.
332334
"""
@@ -354,7 +356,8 @@ async def _aprocess_next_step_output(
354356
next_step_output: Union[AgentFinish, list[tuple[AgentAction, str]]],
355357
run_manager: AsyncCallbackManagerForChainRun,
356358
) -> AddableDict:
357-
"""
359+
"""Process the output of the next async step.
360+
358361
Process the output of the next async step,
359362
handling AgentFinish and tool return cases.
360363
"""
@@ -378,7 +381,8 @@ async def _aprocess_next_step_output(
378381
return AddableDict(intermediate_step=next_step_output)
379382

380383
def _stop(self, run_manager: CallbackManagerForChainRun) -> AddableDict:
381-
"""
384+
"""Stop the iterator.
385+
382386
Stop the iterator and raise a StopIteration exception with the stopped response.
383387
"""
384388
logger.warning("Stopping agent prematurely due to triggering stop condition")
@@ -391,7 +395,8 @@ def _stop(self, run_manager: CallbackManagerForChainRun) -> AddableDict:
391395
return self._return(output, run_manager=run_manager)
392396

393397
async def _astop(self, run_manager: AsyncCallbackManagerForChainRun) -> AddableDict:
394-
"""
398+
"""Stop the async iterator.
399+
395400
Stop the async iterator and raise a StopAsyncIteration exception with
396401
the stopped response.
397402
"""
@@ -408,9 +413,7 @@ def _return(
408413
output: AgentFinish,
409414
run_manager: CallbackManagerForChainRun,
410415
) -> AddableDict:
411-
"""
412-
Return the final output of the iterator.
413-
"""
416+
"""Return the final output of the iterator."""
414417
returned_output = self.agent_executor._return( # noqa: SLF001
415418
output,
416419
self.intermediate_steps,
@@ -425,9 +428,7 @@ async def _areturn(
425428
output: AgentFinish,
426429
run_manager: AsyncCallbackManagerForChainRun,
427430
) -> AddableDict:
428-
"""
429-
Return the final output of the async iterator.
430-
"""
431+
"""Return the final output of the async iterator."""
431432
returned_output = await self.agent_executor._areturn( # noqa: SLF001
432433
output,
433434
self.intermediate_steps,

libs/langchain/langchain/agents/agent_toolkits/conversational_retrieval/openai_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ def create_conversational_retrieval_agent(
5151
defaults to False.
5252
max_token_limit: The max number of tokens to keep around in memory.
5353
Defaults to 2000.
54+
**kwargs: Additional keyword arguments to pass to the AgentExecutor.
5455
5556
Returns:
5657
An agent executor initialized appropriately
5758
"""
58-
5959
if remember_intermediate_steps:
6060
memory: BaseMemory = AgentTokenBufferMemory(
6161
memory_key=memory_key,

libs/langchain/langchain/agents/agent_toolkits/csv/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
def __getattr__(name: str) -> Any:
88
"""Get attr name."""
9-
109
if name == "create_csv_agent":
1110
# Get directory of langchain package
1211
HERE = Path(__file__).parents[3]
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
"""NASA Toolkit"""
1+
"""NASA Toolkit."""

libs/langchain/langchain/agents/agent_toolkits/pandas/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
def __getattr__(name: str) -> Any:
88
"""Get attr name."""
9-
109
if name == "create_pandas_dataframe_agent":
1110
# Get directory of langchain package
1211
HERE = Path(__file__).parents[3]

libs/langchain/langchain/agents/agent_toolkits/python/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
def __getattr__(name: str) -> Any:
88
"""Get attr name."""
9-
109
if name == "create_python_agent":
1110
# Get directory of langchain package
1211
HERE = Path(__file__).parents[3]

libs/langchain/langchain/agents/agent_toolkits/spark/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
def __getattr__(name: str) -> Any:
88
"""Get attr name."""
9-
109
if name == "create_spark_dataframe_agent":
1110
# Get directory of langchain package
1211
HERE = Path(__file__).parents[3]

libs/langchain/langchain/agents/agent_toolkits/xorbits/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
def __getattr__(name: str) -> Any:
88
"""Get attr name."""
9-
109
if name == "create_xorbits_agent":
1110
# Get directory of langchain package
1211
HERE = Path(__file__).parents[3]

0 commit comments

Comments
 (0)