langchain 0.3.22__py3-none-any.whl → 0.3.24__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. langchain/_api/module_import.py +3 -3
  2. langchain/agents/agent.py +104 -109
  3. langchain/agents/agent_iterator.py +11 -15
  4. langchain/agents/agent_toolkits/conversational_retrieval/openai_functions.py +2 -2
  5. langchain/agents/agent_toolkits/vectorstore/base.py +3 -3
  6. langchain/agents/agent_toolkits/vectorstore/toolkit.py +4 -6
  7. langchain/agents/chat/base.py +7 -6
  8. langchain/agents/chat/output_parser.py +2 -1
  9. langchain/agents/conversational/base.py +5 -4
  10. langchain/agents/conversational_chat/base.py +9 -8
  11. langchain/agents/format_scratchpad/log.py +1 -3
  12. langchain/agents/format_scratchpad/log_to_messages.py +3 -5
  13. langchain/agents/format_scratchpad/openai_functions.py +4 -4
  14. langchain/agents/format_scratchpad/tools.py +3 -3
  15. langchain/agents/format_scratchpad/xml.py +1 -3
  16. langchain/agents/initialize.py +2 -1
  17. langchain/agents/json_chat/base.py +3 -2
  18. langchain/agents/loading.py +5 -5
  19. langchain/agents/mrkl/base.py +6 -5
  20. langchain/agents/openai_assistant/base.py +13 -17
  21. langchain/agents/openai_functions_agent/agent_token_buffer_memory.py +6 -6
  22. langchain/agents/openai_functions_agent/base.py +13 -12
  23. langchain/agents/openai_functions_multi_agent/base.py +15 -14
  24. langchain/agents/openai_tools/base.py +2 -1
  25. langchain/agents/output_parsers/openai_functions.py +2 -2
  26. langchain/agents/output_parsers/openai_tools.py +6 -6
  27. langchain/agents/output_parsers/react_json_single_input.py +2 -1
  28. langchain/agents/output_parsers/self_ask.py +2 -1
  29. langchain/agents/output_parsers/tools.py +7 -7
  30. langchain/agents/react/agent.py +3 -2
  31. langchain/agents/react/base.py +4 -3
  32. langchain/agents/schema.py +3 -3
  33. langchain/agents/self_ask_with_search/base.py +2 -1
  34. langchain/agents/structured_chat/base.py +9 -8
  35. langchain/agents/structured_chat/output_parser.py +2 -1
  36. langchain/agents/tool_calling_agent/base.py +3 -2
  37. langchain/agents/tools.py +4 -4
  38. langchain/agents/types.py +3 -3
  39. langchain/agents/utils.py +1 -1
  40. langchain/agents/xml/base.py +7 -6
  41. langchain/callbacks/streaming_aiter.py +3 -2
  42. langchain/callbacks/streaming_aiter_final_only.py +3 -3
  43. langchain/callbacks/streaming_stdout_final_only.py +3 -3
  44. langchain/chains/api/base.py +11 -12
  45. langchain/chains/base.py +47 -50
  46. langchain/chains/combine_documents/base.py +23 -23
  47. langchain/chains/combine_documents/map_reduce.py +12 -12
  48. langchain/chains/combine_documents/map_rerank.py +16 -15
  49. langchain/chains/combine_documents/reduce.py +17 -17
  50. langchain/chains/combine_documents/refine.py +12 -12
  51. langchain/chains/combine_documents/stuff.py +10 -10
  52. langchain/chains/constitutional_ai/base.py +9 -9
  53. langchain/chains/conversation/base.py +2 -4
  54. langchain/chains/conversational_retrieval/base.py +30 -30
  55. langchain/chains/elasticsearch_database/base.py +13 -13
  56. langchain/chains/example_generator.py +1 -3
  57. langchain/chains/flare/base.py +13 -12
  58. langchain/chains/flare/prompts.py +2 -4
  59. langchain/chains/hyde/base.py +8 -8
  60. langchain/chains/llm.py +31 -30
  61. langchain/chains/llm_checker/base.py +6 -6
  62. langchain/chains/llm_math/base.py +10 -10
  63. langchain/chains/llm_summarization_checker/base.py +6 -6
  64. langchain/chains/loading.py +12 -14
  65. langchain/chains/mapreduce.py +7 -6
  66. langchain/chains/moderation.py +8 -8
  67. langchain/chains/natbot/base.py +6 -6
  68. langchain/chains/openai_functions/base.py +8 -10
  69. langchain/chains/openai_functions/citation_fuzzy_match.py +4 -4
  70. langchain/chains/openai_functions/extraction.py +3 -3
  71. langchain/chains/openai_functions/openapi.py +12 -12
  72. langchain/chains/openai_functions/qa_with_structure.py +4 -4
  73. langchain/chains/openai_functions/utils.py +2 -2
  74. langchain/chains/openai_tools/extraction.py +2 -2
  75. langchain/chains/prompt_selector.py +3 -3
  76. langchain/chains/qa_generation/base.py +5 -5
  77. langchain/chains/qa_with_sources/base.py +21 -21
  78. langchain/chains/qa_with_sources/loading.py +2 -1
  79. langchain/chains/qa_with_sources/retrieval.py +6 -6
  80. langchain/chains/qa_with_sources/vector_db.py +8 -8
  81. langchain/chains/query_constructor/base.py +4 -3
  82. langchain/chains/query_constructor/parser.py +5 -4
  83. langchain/chains/question_answering/chain.py +3 -2
  84. langchain/chains/retrieval.py +2 -2
  85. langchain/chains/retrieval_qa/base.py +16 -16
  86. langchain/chains/router/base.py +12 -11
  87. langchain/chains/router/embedding_router.py +12 -11
  88. langchain/chains/router/llm_router.py +12 -12
  89. langchain/chains/router/multi_prompt.py +3 -3
  90. langchain/chains/router/multi_retrieval_qa.py +5 -4
  91. langchain/chains/sequential.py +18 -18
  92. langchain/chains/sql_database/query.py +4 -4
  93. langchain/chains/structured_output/base.py +14 -13
  94. langchain/chains/summarize/chain.py +4 -3
  95. langchain/chains/transform.py +12 -11
  96. langchain/chat_models/base.py +34 -31
  97. langchain/embeddings/__init__.py +1 -1
  98. langchain/embeddings/base.py +4 -4
  99. langchain/embeddings/cache.py +19 -18
  100. langchain/evaluation/agents/trajectory_eval_chain.py +16 -19
  101. langchain/evaluation/comparison/eval_chain.py +10 -10
  102. langchain/evaluation/criteria/eval_chain.py +11 -10
  103. langchain/evaluation/embedding_distance/base.py +21 -21
  104. langchain/evaluation/exact_match/base.py +3 -3
  105. langchain/evaluation/loading.py +7 -8
  106. langchain/evaluation/qa/eval_chain.py +7 -6
  107. langchain/evaluation/regex_match/base.py +3 -3
  108. langchain/evaluation/schema.py +6 -5
  109. langchain/evaluation/scoring/eval_chain.py +9 -9
  110. langchain/evaluation/string_distance/base.py +23 -23
  111. langchain/hub.py +2 -1
  112. langchain/indexes/_sql_record_manager.py +8 -7
  113. langchain/indexes/vectorstore.py +11 -11
  114. langchain/llms/__init__.py +3 -3
  115. langchain/memory/buffer.py +13 -13
  116. langchain/memory/buffer_window.py +5 -5
  117. langchain/memory/chat_memory.py +5 -5
  118. langchain/memory/combined.py +10 -10
  119. langchain/memory/entity.py +8 -7
  120. langchain/memory/readonly.py +4 -4
  121. langchain/memory/simple.py +5 -5
  122. langchain/memory/summary.py +8 -8
  123. langchain/memory/summary_buffer.py +11 -11
  124. langchain/memory/token_buffer.py +5 -5
  125. langchain/memory/utils.py +2 -2
  126. langchain/memory/vectorstore.py +15 -14
  127. langchain/memory/vectorstore_token_buffer_memory.py +7 -7
  128. langchain/model_laboratory.py +4 -3
  129. langchain/output_parsers/combining.py +5 -5
  130. langchain/output_parsers/datetime.py +1 -2
  131. langchain/output_parsers/enum.py +4 -5
  132. langchain/output_parsers/pandas_dataframe.py +5 -5
  133. langchain/output_parsers/regex.py +4 -4
  134. langchain/output_parsers/regex_dict.py +4 -4
  135. langchain/output_parsers/retry.py +2 -2
  136. langchain/output_parsers/structured.py +5 -5
  137. langchain/output_parsers/yaml.py +3 -3
  138. langchain/pydantic_v1/__init__.py +1 -6
  139. langchain/pydantic_v1/dataclasses.py +1 -5
  140. langchain/pydantic_v1/main.py +1 -5
  141. langchain/retrievers/contextual_compression.py +3 -3
  142. langchain/retrievers/document_compressors/base.py +3 -2
  143. langchain/retrievers/document_compressors/chain_extract.py +4 -3
  144. langchain/retrievers/document_compressors/chain_filter.py +3 -2
  145. langchain/retrievers/document_compressors/cohere_rerank.py +4 -3
  146. langchain/retrievers/document_compressors/cross_encoder.py +1 -2
  147. langchain/retrievers/document_compressors/cross_encoder_rerank.py +2 -1
  148. langchain/retrievers/document_compressors/embeddings_filter.py +3 -2
  149. langchain/retrievers/document_compressors/listwise_rerank.py +6 -5
  150. langchain/retrievers/ensemble.py +15 -19
  151. langchain/retrievers/merger_retriever.py +7 -12
  152. langchain/retrievers/multi_query.py +14 -13
  153. langchain/retrievers/multi_vector.py +4 -4
  154. langchain/retrievers/parent_document_retriever.py +9 -8
  155. langchain/retrievers/re_phraser.py +2 -3
  156. langchain/retrievers/self_query/base.py +13 -12
  157. langchain/retrievers/time_weighted_retriever.py +14 -14
  158. langchain/runnables/openai_functions.py +4 -3
  159. langchain/smith/evaluation/config.py +7 -6
  160. langchain/smith/evaluation/progress.py +3 -2
  161. langchain/smith/evaluation/runner_utils.py +58 -61
  162. langchain/smith/evaluation/string_run_evaluator.py +29 -29
  163. langchain/storage/encoder_backed.py +7 -11
  164. langchain/storage/file_system.py +5 -4
  165. {langchain-0.3.22.dist-info → langchain-0.3.24.dist-info}/METADATA +5 -3
  166. {langchain-0.3.22.dist-info → langchain-0.3.24.dist-info}/RECORD +169 -169
  167. {langchain-0.3.22.dist-info → langchain-0.3.24.dist-info}/WHEEL +1 -1
  168. langchain-0.3.24.dist-info/entry_points.txt +4 -0
  169. langchain-0.3.22.dist-info/entry_points.txt +0 -5
  170. {langchain-0.3.22.dist-info → langchain-0.3.24.dist-info}/licenses/LICENSE +0 -0
langchain/agents/agent.py CHANGED
@@ -3,21 +3,17 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import asyncio
6
+ import builtins
6
7
  import json
7
8
  import logging
8
9
  import time
9
10
  from abc import abstractmethod
11
+ from collections.abc import AsyncIterator, Iterator, Sequence
10
12
  from pathlib import Path
11
13
  from typing import (
12
14
  Any,
13
- AsyncIterator,
14
15
  Callable,
15
- Dict,
16
- Iterator,
17
- List,
18
16
  Optional,
19
- Sequence,
20
- Tuple,
21
17
  Union,
22
18
  cast,
23
19
  )
@@ -62,17 +58,17 @@ class BaseSingleActionAgent(BaseModel):
62
58
  """Base Single Action Agent class."""
63
59
 
64
60
  @property
65
- def return_values(self) -> List[str]:
61
+ def return_values(self) -> list[str]:
66
62
  """Return values of the agent."""
67
63
  return ["output"]
68
64
 
69
- def get_allowed_tools(self) -> Optional[List[str]]:
65
+ def get_allowed_tools(self) -> Optional[list[str]]:
70
66
  return None
71
67
 
72
68
  @abstractmethod
73
69
  def plan(
74
70
  self,
75
- intermediate_steps: List[Tuple[AgentAction, str]],
71
+ intermediate_steps: list[tuple[AgentAction, str]],
76
72
  callbacks: Callbacks = None,
77
73
  **kwargs: Any,
78
74
  ) -> Union[AgentAction, AgentFinish]:
@@ -91,7 +87,7 @@ class BaseSingleActionAgent(BaseModel):
91
87
  @abstractmethod
92
88
  async def aplan(
93
89
  self,
94
- intermediate_steps: List[Tuple[AgentAction, str]],
90
+ intermediate_steps: list[tuple[AgentAction, str]],
95
91
  callbacks: Callbacks = None,
96
92
  **kwargs: Any,
97
93
  ) -> Union[AgentAction, AgentFinish]:
@@ -109,7 +105,7 @@ class BaseSingleActionAgent(BaseModel):
109
105
 
110
106
  @property
111
107
  @abstractmethod
112
- def input_keys(self) -> List[str]:
108
+ def input_keys(self) -> list[str]:
113
109
  """Return the input keys.
114
110
 
115
111
  :meta private:
@@ -118,7 +114,7 @@ class BaseSingleActionAgent(BaseModel):
118
114
  def return_stopped_response(
119
115
  self,
120
116
  early_stopping_method: str,
121
- intermediate_steps: List[Tuple[AgentAction, str]],
117
+ intermediate_steps: list[tuple[AgentAction, str]],
122
118
  **kwargs: Any,
123
119
  ) -> AgentFinish:
124
120
  """Return response when agent has been stopped due to max iterations.
@@ -171,7 +167,7 @@ class BaseSingleActionAgent(BaseModel):
171
167
  """Return Identifier of an agent type."""
172
168
  raise NotImplementedError
173
169
 
174
- def dict(self, **kwargs: Any) -> Dict:
170
+ def dict(self, **kwargs: Any) -> builtins.dict:
175
171
  """Return dictionary representation of agent.
176
172
 
177
173
  Returns:
@@ -223,7 +219,7 @@ class BaseSingleActionAgent(BaseModel):
223
219
  else:
224
220
  raise ValueError(f"{save_path} must be json or yaml")
225
221
 
226
- def tool_run_logging_kwargs(self) -> Dict:
222
+ def tool_run_logging_kwargs(self) -> builtins.dict:
227
223
  """Return logging kwargs for tool run."""
228
224
  return {}
229
225
 
@@ -232,11 +228,11 @@ class BaseMultiActionAgent(BaseModel):
232
228
  """Base Multi Action Agent class."""
233
229
 
234
230
  @property
235
- def return_values(self) -> List[str]:
231
+ def return_values(self) -> list[str]:
236
232
  """Return values of the agent."""
237
233
  return ["output"]
238
234
 
239
- def get_allowed_tools(self) -> Optional[List[str]]:
235
+ def get_allowed_tools(self) -> Optional[list[str]]:
240
236
  """Get allowed tools.
241
237
 
242
238
  Returns:
@@ -247,10 +243,10 @@ class BaseMultiActionAgent(BaseModel):
247
243
  @abstractmethod
248
244
  def plan(
249
245
  self,
250
- intermediate_steps: List[Tuple[AgentAction, str]],
246
+ intermediate_steps: list[tuple[AgentAction, str]],
251
247
  callbacks: Callbacks = None,
252
248
  **kwargs: Any,
253
- ) -> Union[List[AgentAction], AgentFinish]:
249
+ ) -> Union[list[AgentAction], AgentFinish]:
254
250
  """Given input, decided what to do.
255
251
 
256
252
  Args:
@@ -266,10 +262,10 @@ class BaseMultiActionAgent(BaseModel):
266
262
  @abstractmethod
267
263
  async def aplan(
268
264
  self,
269
- intermediate_steps: List[Tuple[AgentAction, str]],
265
+ intermediate_steps: list[tuple[AgentAction, str]],
270
266
  callbacks: Callbacks = None,
271
267
  **kwargs: Any,
272
- ) -> Union[List[AgentAction], AgentFinish]:
268
+ ) -> Union[list[AgentAction], AgentFinish]:
273
269
  """Async given input, decided what to do.
274
270
 
275
271
  Args:
@@ -284,7 +280,7 @@ class BaseMultiActionAgent(BaseModel):
284
280
 
285
281
  @property
286
282
  @abstractmethod
287
- def input_keys(self) -> List[str]:
283
+ def input_keys(self) -> list[str]:
288
284
  """Return the input keys.
289
285
 
290
286
  :meta private:
@@ -293,7 +289,7 @@ class BaseMultiActionAgent(BaseModel):
293
289
  def return_stopped_response(
294
290
  self,
295
291
  early_stopping_method: str,
296
- intermediate_steps: List[Tuple[AgentAction, str]],
292
+ intermediate_steps: list[tuple[AgentAction, str]],
297
293
  **kwargs: Any,
298
294
  ) -> AgentFinish:
299
295
  """Return response when agent has been stopped due to max iterations.
@@ -323,7 +319,7 @@ class BaseMultiActionAgent(BaseModel):
323
319
  """Return Identifier of an agent type."""
324
320
  raise NotImplementedError
325
321
 
326
- def dict(self, **kwargs: Any) -> Dict:
322
+ def dict(self, **kwargs: Any) -> builtins.dict:
327
323
  """Return dictionary representation of agent."""
328
324
  _dict = super().model_dump()
329
325
  try:
@@ -371,7 +367,7 @@ class BaseMultiActionAgent(BaseModel):
371
367
  else:
372
368
  raise ValueError(f"{save_path} must be json or yaml")
373
369
 
374
- def tool_run_logging_kwargs(self) -> Dict:
370
+ def tool_run_logging_kwargs(self) -> builtins.dict:
375
371
  """Return logging kwargs for tool run."""
376
372
 
377
373
  return {}
@@ -386,7 +382,7 @@ class AgentOutputParser(BaseOutputParser[Union[AgentAction, AgentFinish]]):
386
382
 
387
383
 
388
384
  class MultiActionAgentOutputParser(
389
- BaseOutputParser[Union[List[AgentAction], AgentFinish]]
385
+ BaseOutputParser[Union[list[AgentAction], AgentFinish]]
390
386
  ):
391
387
  """Base class for parsing agent output into agent actions/finish.
392
388
 
@@ -394,7 +390,7 @@ class MultiActionAgentOutputParser(
394
390
  """
395
391
 
396
392
  @abstractmethod
397
- def parse(self, text: str) -> Union[List[AgentAction], AgentFinish]:
393
+ def parse(self, text: str) -> Union[list[AgentAction], AgentFinish]:
398
394
  """Parse text into agent actions/finish.
399
395
 
400
396
  Args:
@@ -411,8 +407,8 @@ class RunnableAgent(BaseSingleActionAgent):
411
407
 
412
408
  runnable: Runnable[dict, Union[AgentAction, AgentFinish]]
413
409
  """Runnable to call to get agent action."""
414
- input_keys_arg: List[str] = []
415
- return_keys_arg: List[str] = []
410
+ input_keys_arg: list[str] = []
411
+ return_keys_arg: list[str] = []
416
412
  stream_runnable: bool = True
417
413
  """Whether to stream from the runnable or not.
418
414
 
@@ -427,18 +423,18 @@ class RunnableAgent(BaseSingleActionAgent):
427
423
  )
428
424
 
429
425
  @property
430
- def return_values(self) -> List[str]:
426
+ def return_values(self) -> list[str]:
431
427
  """Return values of the agent."""
432
428
  return self.return_keys_arg
433
429
 
434
430
  @property
435
- def input_keys(self) -> List[str]:
431
+ def input_keys(self) -> list[str]:
436
432
  """Return the input keys."""
437
433
  return self.input_keys_arg
438
434
 
439
435
  def plan(
440
436
  self,
441
- intermediate_steps: List[Tuple[AgentAction, str]],
437
+ intermediate_steps: list[tuple[AgentAction, str]],
442
438
  callbacks: Callbacks = None,
443
439
  **kwargs: Any,
444
440
  ) -> Union[AgentAction, AgentFinish]:
@@ -474,7 +470,7 @@ class RunnableAgent(BaseSingleActionAgent):
474
470
 
475
471
  async def aplan(
476
472
  self,
477
- intermediate_steps: List[Tuple[AgentAction, str]],
473
+ intermediate_steps: list[tuple[AgentAction, str]],
478
474
  callbacks: Callbacks = None,
479
475
  **kwargs: Any,
480
476
  ) -> Union[
@@ -518,10 +514,10 @@ class RunnableAgent(BaseSingleActionAgent):
518
514
  class RunnableMultiActionAgent(BaseMultiActionAgent):
519
515
  """Agent powered by Runnables."""
520
516
 
521
- runnable: Runnable[dict, Union[List[AgentAction], AgentFinish]]
517
+ runnable: Runnable[dict, Union[list[AgentAction], AgentFinish]]
522
518
  """Runnable to call to get agent actions."""
523
- input_keys_arg: List[str] = []
524
- return_keys_arg: List[str] = []
519
+ input_keys_arg: list[str] = []
520
+ return_keys_arg: list[str] = []
525
521
  stream_runnable: bool = True
526
522
  """Whether to stream from the runnable or not.
527
523
 
@@ -536,12 +532,12 @@ class RunnableMultiActionAgent(BaseMultiActionAgent):
536
532
  )
537
533
 
538
534
  @property
539
- def return_values(self) -> List[str]:
535
+ def return_values(self) -> list[str]:
540
536
  """Return values of the agent."""
541
537
  return self.return_keys_arg
542
538
 
543
539
  @property
544
- def input_keys(self) -> List[str]:
540
+ def input_keys(self) -> list[str]:
545
541
  """Return the input keys.
546
542
 
547
543
  Returns:
@@ -551,11 +547,11 @@ class RunnableMultiActionAgent(BaseMultiActionAgent):
551
547
 
552
548
  def plan(
553
549
  self,
554
- intermediate_steps: List[Tuple[AgentAction, str]],
550
+ intermediate_steps: list[tuple[AgentAction, str]],
555
551
  callbacks: Callbacks = None,
556
552
  **kwargs: Any,
557
553
  ) -> Union[
558
- List[AgentAction],
554
+ list[AgentAction],
559
555
  AgentFinish,
560
556
  ]:
561
557
  """Based on past history and current inputs, decide what to do.
@@ -590,11 +586,11 @@ class RunnableMultiActionAgent(BaseMultiActionAgent):
590
586
 
591
587
  async def aplan(
592
588
  self,
593
- intermediate_steps: List[Tuple[AgentAction, str]],
589
+ intermediate_steps: list[tuple[AgentAction, str]],
594
590
  callbacks: Callbacks = None,
595
591
  **kwargs: Any,
596
592
  ) -> Union[
597
- List[AgentAction],
593
+ list[AgentAction],
598
594
  AgentFinish,
599
595
  ]:
600
596
  """Async based on past history and current inputs, decide what to do.
@@ -644,11 +640,11 @@ class LLMSingleActionAgent(BaseSingleActionAgent):
644
640
  """LLMChain to use for agent."""
645
641
  output_parser: AgentOutputParser
646
642
  """Output parser to use for agent."""
647
- stop: List[str]
643
+ stop: list[str]
648
644
  """List of strings to stop on."""
649
645
 
650
646
  @property
651
- def input_keys(self) -> List[str]:
647
+ def input_keys(self) -> list[str]:
652
648
  """Return the input keys.
653
649
 
654
650
  Returns:
@@ -656,7 +652,7 @@ class LLMSingleActionAgent(BaseSingleActionAgent):
656
652
  """
657
653
  return list(set(self.llm_chain.input_keys) - {"intermediate_steps"})
658
654
 
659
- def dict(self, **kwargs: Any) -> Dict:
655
+ def dict(self, **kwargs: Any) -> builtins.dict:
660
656
  """Return dictionary representation of agent."""
661
657
  _dict = super().dict()
662
658
  del _dict["output_parser"]
@@ -664,7 +660,7 @@ class LLMSingleActionAgent(BaseSingleActionAgent):
664
660
 
665
661
  def plan(
666
662
  self,
667
- intermediate_steps: List[Tuple[AgentAction, str]],
663
+ intermediate_steps: list[tuple[AgentAction, str]],
668
664
  callbacks: Callbacks = None,
669
665
  **kwargs: Any,
670
666
  ) -> Union[AgentAction, AgentFinish]:
@@ -689,7 +685,7 @@ class LLMSingleActionAgent(BaseSingleActionAgent):
689
685
 
690
686
  async def aplan(
691
687
  self,
692
- intermediate_steps: List[Tuple[AgentAction, str]],
688
+ intermediate_steps: list[tuple[AgentAction, str]],
693
689
  callbacks: Callbacks = None,
694
690
  **kwargs: Any,
695
691
  ) -> Union[AgentAction, AgentFinish]:
@@ -712,7 +708,7 @@ class LLMSingleActionAgent(BaseSingleActionAgent):
712
708
  )
713
709
  return self.output_parser.parse(output)
714
710
 
715
- def tool_run_logging_kwargs(self) -> Dict:
711
+ def tool_run_logging_kwargs(self) -> builtins.dict:
716
712
  """Return logging kwargs for tool run."""
717
713
  return {
718
714
  "llm_prefix": "",
@@ -737,21 +733,21 @@ class Agent(BaseSingleActionAgent):
737
733
  """LLMChain to use for agent."""
738
734
  output_parser: AgentOutputParser
739
735
  """Output parser to use for agent."""
740
- allowed_tools: Optional[List[str]] = None
736
+ allowed_tools: Optional[list[str]] = None
741
737
  """Allowed tools for the agent. If None, all tools are allowed."""
742
738
 
743
- def dict(self, **kwargs: Any) -> Dict:
739
+ def dict(self, **kwargs: Any) -> builtins.dict:
744
740
  """Return dictionary representation of agent."""
745
741
  _dict = super().dict()
746
742
  del _dict["output_parser"]
747
743
  return _dict
748
744
 
749
- def get_allowed_tools(self) -> Optional[List[str]]:
745
+ def get_allowed_tools(self) -> Optional[list[str]]:
750
746
  """Get allowed tools."""
751
747
  return self.allowed_tools
752
748
 
753
749
  @property
754
- def return_values(self) -> List[str]:
750
+ def return_values(self) -> list[str]:
755
751
  """Return values of the agent."""
756
752
  return ["output"]
757
753
 
@@ -767,15 +763,15 @@ class Agent(BaseSingleActionAgent):
767
763
  raise ValueError("fix_text not implemented for this agent.")
768
764
 
769
765
  @property
770
- def _stop(self) -> List[str]:
766
+ def _stop(self) -> list[str]:
771
767
  return [
772
768
  f"\n{self.observation_prefix.rstrip()}",
773
769
  f"\n\t{self.observation_prefix.rstrip()}",
774
770
  ]
775
771
 
776
772
  def _construct_scratchpad(
777
- self, intermediate_steps: List[Tuple[AgentAction, str]]
778
- ) -> Union[str, List[BaseMessage]]:
773
+ self, intermediate_steps: list[tuple[AgentAction, str]]
774
+ ) -> Union[str, list[BaseMessage]]:
779
775
  """Construct the scratchpad that lets the agent continue its thought process."""
780
776
  thoughts = ""
781
777
  for action, observation in intermediate_steps:
@@ -785,7 +781,7 @@ class Agent(BaseSingleActionAgent):
785
781
 
786
782
  def plan(
787
783
  self,
788
- intermediate_steps: List[Tuple[AgentAction, str]],
784
+ intermediate_steps: list[tuple[AgentAction, str]],
789
785
  callbacks: Callbacks = None,
790
786
  **kwargs: Any,
791
787
  ) -> Union[AgentAction, AgentFinish]:
@@ -806,7 +802,7 @@ class Agent(BaseSingleActionAgent):
806
802
 
807
803
  async def aplan(
808
804
  self,
809
- intermediate_steps: List[Tuple[AgentAction, str]],
805
+ intermediate_steps: list[tuple[AgentAction, str]],
810
806
  callbacks: Callbacks = None,
811
807
  **kwargs: Any,
812
808
  ) -> Union[AgentAction, AgentFinish]:
@@ -827,8 +823,8 @@ class Agent(BaseSingleActionAgent):
827
823
  return agent_output
828
824
 
829
825
  def get_full_inputs(
830
- self, intermediate_steps: List[Tuple[AgentAction, str]], **kwargs: Any
831
- ) -> Dict[str, Any]:
826
+ self, intermediate_steps: list[tuple[AgentAction, str]], **kwargs: Any
827
+ ) -> builtins.dict[str, Any]:
832
828
  """Create the full inputs for the LLMChain from intermediate steps.
833
829
 
834
830
  Args:
@@ -845,7 +841,7 @@ class Agent(BaseSingleActionAgent):
845
841
  return full_inputs
846
842
 
847
843
  @property
848
- def input_keys(self) -> List[str]:
844
+ def input_keys(self) -> list[str]:
849
845
  """Return the input keys.
850
846
 
851
847
  :meta private:
@@ -957,7 +953,7 @@ class Agent(BaseSingleActionAgent):
957
953
  def return_stopped_response(
958
954
  self,
959
955
  early_stopping_method: str,
960
- intermediate_steps: List[Tuple[AgentAction, str]],
956
+ intermediate_steps: list[tuple[AgentAction, str]],
961
957
  **kwargs: Any,
962
958
  ) -> AgentFinish:
963
959
  """Return response when agent has been stopped due to max iterations.
@@ -1009,7 +1005,7 @@ class Agent(BaseSingleActionAgent):
1009
1005
  f"got {early_stopping_method}"
1010
1006
  )
1011
1007
 
1012
- def tool_run_logging_kwargs(self) -> Dict:
1008
+ def tool_run_logging_kwargs(self) -> builtins.dict:
1013
1009
  """Return logging kwargs for tool run."""
1014
1010
  return {
1015
1011
  "llm_prefix": self.llm_prefix,
@@ -1017,7 +1013,7 @@ class Agent(BaseSingleActionAgent):
1017
1013
  }
1018
1014
 
1019
1015
 
1020
- class ExceptionTool(BaseTool): # type: ignore[override]
1016
+ class ExceptionTool(BaseTool):
1021
1017
  """Tool that just returns the query."""
1022
1018
 
1023
1019
  name: str = "_Exception"
@@ -1040,7 +1036,7 @@ class ExceptionTool(BaseTool): # type: ignore[override]
1040
1036
  return query
1041
1037
 
1042
1038
 
1043
- NextStepOutput = List[Union[AgentFinish, AgentAction, AgentStep]]
1039
+ NextStepOutput = list[Union[AgentFinish, AgentAction, AgentStep]]
1044
1040
  RunnableAgentType = Union[RunnableAgent, RunnableMultiActionAgent]
1045
1041
 
1046
1042
 
@@ -1086,7 +1082,7 @@ class AgentExecutor(Chain):
1086
1082
  as an observation.
1087
1083
  """
1088
1084
  trim_intermediate_steps: Union[
1089
- int, Callable[[List[Tuple[AgentAction, str]]], List[Tuple[AgentAction, str]]]
1085
+ int, Callable[[list[tuple[AgentAction, str]]], list[tuple[AgentAction, str]]]
1090
1086
  ] = -1
1091
1087
  """How to trim the intermediate steps before returning them.
1092
1088
  Defaults to -1, which means no trimming.
@@ -1133,7 +1129,7 @@ class AgentExecutor(Chain):
1133
1129
  """
1134
1130
  agent = self.agent
1135
1131
  tools = self.tools
1136
- allowed_tools = agent.get_allowed_tools() # type: ignore
1132
+ allowed_tools = agent.get_allowed_tools() # type: ignore[union-attr]
1137
1133
  if allowed_tools is not None:
1138
1134
  if set(allowed_tools) != set([tool.name for tool in tools]):
1139
1135
  raise ValueError(
@@ -1144,7 +1140,7 @@ class AgentExecutor(Chain):
1144
1140
 
1145
1141
  @model_validator(mode="before")
1146
1142
  @classmethod
1147
- def validate_runnable_agent(cls, values: Dict) -> Any:
1143
+ def validate_runnable_agent(cls, values: dict) -> Any:
1148
1144
  """Convert runnable to agent if passed in.
1149
1145
 
1150
1146
  Args:
@@ -1160,7 +1156,7 @@ class AgentExecutor(Chain):
1160
1156
  except Exception as _:
1161
1157
  multi_action = False
1162
1158
  else:
1163
- multi_action = output_type == Union[List[AgentAction], AgentFinish]
1159
+ multi_action = output_type == Union[list[AgentAction], AgentFinish]
1164
1160
 
1165
1161
  stream_runnable = values.pop("stream_runnable", True)
1166
1162
  if multi_action:
@@ -1239,7 +1235,7 @@ class AgentExecutor(Chain):
1239
1235
  )
1240
1236
 
1241
1237
  @property
1242
- def input_keys(self) -> List[str]:
1238
+ def input_keys(self) -> list[str]:
1243
1239
  """Return the input keys.
1244
1240
 
1245
1241
  :meta private:
@@ -1247,7 +1243,7 @@ class AgentExecutor(Chain):
1247
1243
  return self._action_agent.input_keys
1248
1244
 
1249
1245
  @property
1250
- def output_keys(self) -> List[str]:
1246
+ def output_keys(self) -> list[str]:
1251
1247
  """Return the singular output key.
1252
1248
 
1253
1249
  :meta private:
@@ -1284,7 +1280,7 @@ class AgentExecutor(Chain):
1284
1280
  output: AgentFinish,
1285
1281
  intermediate_steps: list,
1286
1282
  run_manager: Optional[CallbackManagerForChainRun] = None,
1287
- ) -> Dict[str, Any]:
1283
+ ) -> dict[str, Any]:
1288
1284
  if run_manager:
1289
1285
  run_manager.on_agent_finish(output, color="green", verbose=self.verbose)
1290
1286
  final_output = output.return_values
@@ -1297,7 +1293,7 @@ class AgentExecutor(Chain):
1297
1293
  output: AgentFinish,
1298
1294
  intermediate_steps: list,
1299
1295
  run_manager: Optional[AsyncCallbackManagerForChainRun] = None,
1300
- ) -> Dict[str, Any]:
1296
+ ) -> dict[str, Any]:
1301
1297
  if run_manager:
1302
1298
  await run_manager.on_agent_finish(
1303
1299
  output, color="green", verbose=self.verbose
@@ -1309,7 +1305,7 @@ class AgentExecutor(Chain):
1309
1305
 
1310
1306
  def _consume_next_step(
1311
1307
  self, values: NextStepOutput
1312
- ) -> Union[AgentFinish, List[Tuple[AgentAction, str]]]:
1308
+ ) -> Union[AgentFinish, list[tuple[AgentAction, str]]]:
1313
1309
  if isinstance(values[-1], AgentFinish):
1314
1310
  assert len(values) == 1
1315
1311
  return values[-1]
@@ -1320,12 +1316,12 @@ class AgentExecutor(Chain):
1320
1316
 
1321
1317
  def _take_next_step(
1322
1318
  self,
1323
- name_to_tool_map: Dict[str, BaseTool],
1324
- color_mapping: Dict[str, str],
1325
- inputs: Dict[str, str],
1326
- intermediate_steps: List[Tuple[AgentAction, str]],
1319
+ name_to_tool_map: dict[str, BaseTool],
1320
+ color_mapping: dict[str, str],
1321
+ inputs: dict[str, str],
1322
+ intermediate_steps: list[tuple[AgentAction, str]],
1327
1323
  run_manager: Optional[CallbackManagerForChainRun] = None,
1328
- ) -> Union[AgentFinish, List[Tuple[AgentAction, str]]]:
1324
+ ) -> Union[AgentFinish, list[tuple[AgentAction, str]]]:
1329
1325
  return self._consume_next_step(
1330
1326
  [
1331
1327
  a
@@ -1341,10 +1337,10 @@ class AgentExecutor(Chain):
1341
1337
 
1342
1338
  def _iter_next_step(
1343
1339
  self,
1344
- name_to_tool_map: Dict[str, BaseTool],
1345
- color_mapping: Dict[str, str],
1346
- inputs: Dict[str, str],
1347
- intermediate_steps: List[Tuple[AgentAction, str]],
1340
+ name_to_tool_map: dict[str, BaseTool],
1341
+ color_mapping: dict[str, str],
1342
+ inputs: dict[str, str],
1343
+ intermediate_steps: list[tuple[AgentAction, str]],
1348
1344
  run_manager: Optional[CallbackManagerForChainRun] = None,
1349
1345
  ) -> Iterator[Union[AgentFinish, AgentAction, AgentStep]]:
1350
1346
  """Take a single step in the thought-action-observation loop.
@@ -1404,7 +1400,7 @@ class AgentExecutor(Chain):
1404
1400
  yield output
1405
1401
  return
1406
1402
 
1407
- actions: List[AgentAction]
1403
+ actions: list[AgentAction]
1408
1404
  if isinstance(output, AgentAction):
1409
1405
  actions = [output]
1410
1406
  else:
@@ -1418,8 +1414,8 @@ class AgentExecutor(Chain):
1418
1414
 
1419
1415
  def _perform_agent_action(
1420
1416
  self,
1421
- name_to_tool_map: Dict[str, BaseTool],
1422
- color_mapping: Dict[str, str],
1417
+ name_to_tool_map: dict[str, BaseTool],
1418
+ color_mapping: dict[str, str],
1423
1419
  agent_action: AgentAction,
1424
1420
  run_manager: Optional[CallbackManagerForChainRun] = None,
1425
1421
  ) -> AgentStep:
@@ -1457,12 +1453,12 @@ class AgentExecutor(Chain):
1457
1453
 
1458
1454
  async def _atake_next_step(
1459
1455
  self,
1460
- name_to_tool_map: Dict[str, BaseTool],
1461
- color_mapping: Dict[str, str],
1462
- inputs: Dict[str, str],
1463
- intermediate_steps: List[Tuple[AgentAction, str]],
1456
+ name_to_tool_map: dict[str, BaseTool],
1457
+ color_mapping: dict[str, str],
1458
+ inputs: dict[str, str],
1459
+ intermediate_steps: list[tuple[AgentAction, str]],
1464
1460
  run_manager: Optional[AsyncCallbackManagerForChainRun] = None,
1465
- ) -> Union[AgentFinish, List[Tuple[AgentAction, str]]]:
1461
+ ) -> Union[AgentFinish, list[tuple[AgentAction, str]]]:
1466
1462
  return self._consume_next_step(
1467
1463
  [
1468
1464
  a
@@ -1478,10 +1474,10 @@ class AgentExecutor(Chain):
1478
1474
 
1479
1475
  async def _aiter_next_step(
1480
1476
  self,
1481
- name_to_tool_map: Dict[str, BaseTool],
1482
- color_mapping: Dict[str, str],
1483
- inputs: Dict[str, str],
1484
- intermediate_steps: List[Tuple[AgentAction, str]],
1477
+ name_to_tool_map: dict[str, BaseTool],
1478
+ color_mapping: dict[str, str],
1479
+ inputs: dict[str, str],
1480
+ intermediate_steps: list[tuple[AgentAction, str]],
1485
1481
  run_manager: Optional[AsyncCallbackManagerForChainRun] = None,
1486
1482
  ) -> AsyncIterator[Union[AgentFinish, AgentAction, AgentStep]]:
1487
1483
  """Take a single step in the thought-action-observation loop.
@@ -1539,7 +1535,7 @@ class AgentExecutor(Chain):
1539
1535
  yield output
1540
1536
  return
1541
1537
 
1542
- actions: List[AgentAction]
1538
+ actions: list[AgentAction]
1543
1539
  if isinstance(output, AgentAction):
1544
1540
  actions = [output]
1545
1541
  else:
@@ -1563,8 +1559,8 @@ class AgentExecutor(Chain):
1563
1559
 
1564
1560
  async def _aperform_agent_action(
1565
1561
  self,
1566
- name_to_tool_map: Dict[str, BaseTool],
1567
- color_mapping: Dict[str, str],
1562
+ name_to_tool_map: dict[str, BaseTool],
1563
+ color_mapping: dict[str, str],
1568
1564
  agent_action: AgentAction,
1569
1565
  run_manager: Optional[AsyncCallbackManagerForChainRun] = None,
1570
1566
  ) -> AgentStep:
@@ -1604,9 +1600,9 @@ class AgentExecutor(Chain):
1604
1600
 
1605
1601
  def _call(
1606
1602
  self,
1607
- inputs: Dict[str, str],
1603
+ inputs: dict[str, str],
1608
1604
  run_manager: Optional[CallbackManagerForChainRun] = None,
1609
- ) -> Dict[str, Any]:
1605
+ ) -> dict[str, Any]:
1610
1606
  """Run text through and get agent response."""
1611
1607
  # Construct a mapping of tool name to tool for easy lookup
1612
1608
  name_to_tool_map = {tool.name: tool for tool in self.tools}
@@ -1614,7 +1610,7 @@ class AgentExecutor(Chain):
1614
1610
  color_mapping = get_color_mapping(
1615
1611
  [tool.name for tool in self.tools], excluded_colors=["green", "red"]
1616
1612
  )
1617
- intermediate_steps: List[Tuple[AgentAction, str]] = []
1613
+ intermediate_steps: list[tuple[AgentAction, str]] = []
1618
1614
  # Let's start tracking the number of iterations and time elapsed
1619
1615
  iterations = 0
1620
1616
  time_elapsed = 0.0
@@ -1651,9 +1647,9 @@ class AgentExecutor(Chain):
1651
1647
 
1652
1648
  async def _acall(
1653
1649
  self,
1654
- inputs: Dict[str, str],
1650
+ inputs: dict[str, str],
1655
1651
  run_manager: Optional[AsyncCallbackManagerForChainRun] = None,
1656
- ) -> Dict[str, str]:
1652
+ ) -> dict[str, str]:
1657
1653
  """Async run text through and get agent response."""
1658
1654
  # Construct a mapping of tool name to tool for easy lookup
1659
1655
  name_to_tool_map = {tool.name: tool for tool in self.tools}
@@ -1661,7 +1657,7 @@ class AgentExecutor(Chain):
1661
1657
  color_mapping = get_color_mapping(
1662
1658
  [tool.name for tool in self.tools], excluded_colors=["green"]
1663
1659
  )
1664
- intermediate_steps: List[Tuple[AgentAction, str]] = []
1660
+ intermediate_steps: list[tuple[AgentAction, str]] = []
1665
1661
  # Let's start tracking the number of iterations and time elapsed
1666
1662
  iterations = 0
1667
1663
  time_elapsed = 0.0
@@ -1712,7 +1708,7 @@ class AgentExecutor(Chain):
1712
1708
  )
1713
1709
 
1714
1710
  def _get_tool_return(
1715
- self, next_step_output: Tuple[AgentAction, str]
1711
+ self, next_step_output: tuple[AgentAction, str]
1716
1712
  ) -> Optional[AgentFinish]:
1717
1713
  """Check if the tool is a returning tool."""
1718
1714
  agent_action, observation = next_step_output
@@ -1730,8 +1726,8 @@ class AgentExecutor(Chain):
1730
1726
  return None
1731
1727
 
1732
1728
  def _prepare_intermediate_steps(
1733
- self, intermediate_steps: List[Tuple[AgentAction, str]]
1734
- ) -> List[Tuple[AgentAction, str]]:
1729
+ self, intermediate_steps: list[tuple[AgentAction, str]]
1730
+ ) -> list[tuple[AgentAction, str]]:
1735
1731
  if (
1736
1732
  isinstance(self.trim_intermediate_steps, int)
1737
1733
  and self.trim_intermediate_steps > 0
@@ -1744,7 +1740,7 @@ class AgentExecutor(Chain):
1744
1740
 
1745
1741
  def stream(
1746
1742
  self,
1747
- input: Union[Dict[str, Any], Any],
1743
+ input: Union[dict[str, Any], Any],
1748
1744
  config: Optional[RunnableConfig] = None,
1749
1745
  **kwargs: Any,
1750
1746
  ) -> Iterator[AddableDict]:
@@ -1770,12 +1766,11 @@ class AgentExecutor(Chain):
1770
1766
  yield_actions=True,
1771
1767
  **kwargs,
1772
1768
  )
1773
- for step in iterator:
1774
- yield step
1769
+ yield from iterator
1775
1770
 
1776
1771
  async def astream(
1777
1772
  self,
1778
- input: Union[Dict[str, Any], Any],
1773
+ input: Union[dict[str, Any], Any],
1779
1774
  config: Optional[RunnableConfig] = None,
1780
1775
  **kwargs: Any,
1781
1776
  ) -> AsyncIterator[AddableDict]: