langchain 0.2.13__py3-none-any.whl → 0.2.15__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 (50) hide show
  1. langchain/_api/module_import.py +2 -2
  2. langchain/agents/__init__.py +4 -3
  3. langchain/agents/agent.py +40 -23
  4. langchain/agents/agent_iterator.py +2 -2
  5. langchain/agents/agent_toolkits/__init__.py +1 -1
  6. langchain/agents/agent_toolkits/vectorstore/toolkit.py +2 -1
  7. langchain/agents/agent_types.py +2 -2
  8. langchain/agents/chat/base.py +1 -1
  9. langchain/agents/conversational/base.py +1 -1
  10. langchain/agents/conversational_chat/base.py +1 -1
  11. langchain/agents/initialize.py +1 -1
  12. langchain/agents/json_chat/base.py +1 -1
  13. langchain/agents/loading.py +2 -2
  14. langchain/agents/mrkl/base.py +3 -3
  15. langchain/agents/openai_assistant/base.py +11 -15
  16. langchain/agents/openai_functions_agent/base.py +1 -1
  17. langchain/agents/openai_functions_multi_agent/base.py +1 -1
  18. langchain/agents/react/agent.py +1 -1
  19. langchain/agents/react/base.py +4 -4
  20. langchain/agents/self_ask_with_search/base.py +2 -2
  21. langchain/agents/structured_chat/base.py +3 -2
  22. langchain/agents/tools.py +2 -2
  23. langchain/agents/xml/base.py +2 -2
  24. langchain/chains/base.py +5 -5
  25. langchain/chains/combine_documents/base.py +4 -4
  26. langchain/chains/combine_documents/stuff.py +1 -1
  27. langchain/chains/constitutional_ai/base.py +144 -1
  28. langchain/chains/conversation/base.py +1 -1
  29. langchain/chains/conversational_retrieval/base.py +1 -1
  30. langchain/chains/flare/base.py +42 -69
  31. langchain/chains/hyde/base.py +18 -8
  32. langchain/chains/llm_math/base.py +118 -1
  33. langchain/chains/natbot/base.py +24 -10
  34. langchain/chains/openai_functions/base.py +2 -2
  35. langchain/chains/openai_functions/extraction.py +2 -2
  36. langchain/chains/openai_tools/extraction.py +1 -1
  37. langchain/chains/query_constructor/parser.py +23 -0
  38. langchain/chains/structured_output/base.py +2 -2
  39. langchain/retrievers/document_compressors/chain_extract.py +19 -10
  40. langchain/retrievers/document_compressors/chain_filter.py +27 -10
  41. langchain/retrievers/document_compressors/cohere_rerank.py +1 -1
  42. langchain/retrievers/re_phraser.py +7 -7
  43. langchain/tools/__init__.py +14 -5
  44. langchain/tools/render.py +0 -2
  45. langchain/tools/retriever.py +0 -4
  46. {langchain-0.2.13.dist-info → langchain-0.2.15.dist-info}/METADATA +2 -2
  47. {langchain-0.2.13.dist-info → langchain-0.2.15.dist-info}/RECORD +50 -50
  48. {langchain-0.2.13.dist-info → langchain-0.2.15.dist-info}/LICENSE +0 -0
  49. {langchain-0.2.13.dist-info → langchain-0.2.15.dist-info}/WHEEL +0 -0
  50. {langchain-0.2.13.dist-info → langchain-0.2.15.dist-info}/entry_points.txt +0 -0
@@ -92,7 +92,7 @@ def create_importer(
92
92
  warn_deprecated(
93
93
  since="0.1",
94
94
  pending=False,
95
- removal="0.4",
95
+ removal="1.0",
96
96
  message=(
97
97
  f"Importing {name} from {package} is deprecated. "
98
98
  f"Please replace deprecated imports:\n\n"
@@ -124,7 +124,7 @@ def create_importer(
124
124
  warn_deprecated(
125
125
  since="0.1",
126
126
  pending=False,
127
- removal="0.4",
127
+ removal="1.0",
128
128
  message=(
129
129
  f"Importing {name} from {package} is deprecated. "
130
130
  f"Please replace deprecated imports:\n\n"
@@ -33,7 +33,8 @@ from pathlib import Path
33
33
  from typing import TYPE_CHECKING, Any
34
34
 
35
35
  from langchain_core._api.path import as_import_path
36
- from langchain_core.tools import Tool, tool
36
+ from langchain_core.tools import Tool
37
+ from langchain_core.tools.convert import tool
37
38
 
38
39
  from langchain._api import create_importer
39
40
  from langchain.agents.agent import (
@@ -152,7 +153,6 @@ __all__ = [
152
153
  "ReActTextWorldAgent",
153
154
  "SelfAskWithSearchChain",
154
155
  "StructuredChatAgent",
155
- "Tool",
156
156
  "ZeroShotAgent",
157
157
  "create_json_agent",
158
158
  "create_openapi_agent",
@@ -167,7 +167,6 @@ __all__ = [
167
167
  "load_agent",
168
168
  "load_huggingface_tool",
169
169
  "load_tools",
170
- "tool",
171
170
  "XMLAgent",
172
171
  "create_openai_functions_agent",
173
172
  "create_xml_agent",
@@ -177,4 +176,6 @@ __all__ = [
177
176
  "create_json_chat_agent",
178
177
  "create_structured_chat_agent",
179
178
  "create_tool_calling_agent",
179
+ "Tool",
180
+ "tool",
180
181
  ]
langchain/agents/agent.py CHANGED
@@ -19,6 +19,7 @@ from typing import (
19
19
  Sequence,
20
20
  Tuple,
21
21
  Union,
22
+ cast,
22
23
  )
23
24
 
24
25
  import yaml
@@ -629,11 +630,11 @@ class RunnableMultiActionAgent(BaseMultiActionAgent):
629
630
 
630
631
  @deprecated(
631
632
  "0.1.0",
632
- alternative=(
633
+ message=(
633
634
  "Use new agent constructor methods like create_react_agent, create_json_agent, "
634
635
  "create_structured_chat_agent, etc."
635
636
  ),
636
- removal="0.3.0",
637
+ removal="1.0",
637
638
  )
638
639
  class LLMSingleActionAgent(BaseSingleActionAgent):
639
640
  """Base class for single action agents."""
@@ -720,11 +721,11 @@ class LLMSingleActionAgent(BaseSingleActionAgent):
720
721
 
721
722
  @deprecated(
722
723
  "0.1.0",
723
- alternative=(
724
+ message=(
724
725
  "Use new agent constructor methods like create_react_agent, create_json_agent, "
725
726
  "create_structured_chat_agent, etc."
726
727
  ),
727
- removal="0.3.0",
728
+ removal="1.0",
728
729
  )
729
730
  class Agent(BaseSingleActionAgent):
730
731
  """Agent that calls the language model and deciding the action.
@@ -1042,12 +1043,13 @@ class ExceptionTool(BaseTool):
1042
1043
 
1043
1044
 
1044
1045
  NextStepOutput = List[Union[AgentFinish, AgentAction, AgentStep]]
1046
+ RunnableAgentType = Union[RunnableAgent, RunnableMultiActionAgent]
1045
1047
 
1046
1048
 
1047
1049
  class AgentExecutor(Chain):
1048
1050
  """Agent that is using tools."""
1049
1051
 
1050
- agent: Union[BaseSingleActionAgent, BaseMultiActionAgent]
1052
+ agent: Union[BaseSingleActionAgent, BaseMultiActionAgent, Runnable]
1051
1053
  """The agent to run for creating a plan and determining actions
1052
1054
  to take at each step of the execution loop."""
1053
1055
  tools: Sequence[BaseTool]
@@ -1095,7 +1097,7 @@ class AgentExecutor(Chain):
1095
1097
  @classmethod
1096
1098
  def from_agent_and_tools(
1097
1099
  cls,
1098
- agent: Union[BaseSingleActionAgent, BaseMultiActionAgent],
1100
+ agent: Union[BaseSingleActionAgent, BaseMultiActionAgent, Runnable],
1099
1101
  tools: Sequence[BaseTool],
1100
1102
  callbacks: Callbacks = None,
1101
1103
  **kwargs: Any,
@@ -1172,6 +1174,21 @@ class AgentExecutor(Chain):
1172
1174
  )
1173
1175
  return values
1174
1176
 
1177
+ @property
1178
+ def _action_agent(self) -> Union[BaseSingleActionAgent, BaseMultiActionAgent]:
1179
+ """Type cast self.agent.
1180
+
1181
+ The .agent attribute type includes Runnable, but is converted to one of
1182
+ RunnableAgentType in the validate_runnable_agent root_validator.
1183
+
1184
+ To support instantiating with a Runnable, here we explicitly cast the type
1185
+ to reflect the changes made in the root_validator.
1186
+ """
1187
+ if isinstance(self.agent, Runnable):
1188
+ return cast(RunnableAgentType, self.agent)
1189
+ else:
1190
+ return self.agent
1191
+
1175
1192
  def save(self, file_path: Union[Path, str]) -> None:
1176
1193
  """Raise error - saving not supported for Agent Executors.
1177
1194
 
@@ -1193,7 +1210,7 @@ class AgentExecutor(Chain):
1193
1210
  Args:
1194
1211
  file_path: Path to save to.
1195
1212
  """
1196
- return self.agent.save(file_path)
1213
+ return self._action_agent.save(file_path)
1197
1214
 
1198
1215
  def iter(
1199
1216
  self,
@@ -1228,7 +1245,7 @@ class AgentExecutor(Chain):
1228
1245
 
1229
1246
  :meta private:
1230
1247
  """
1231
- return self.agent.input_keys
1248
+ return self._action_agent.input_keys
1232
1249
 
1233
1250
  @property
1234
1251
  def output_keys(self) -> List[str]:
@@ -1237,9 +1254,9 @@ class AgentExecutor(Chain):
1237
1254
  :meta private:
1238
1255
  """
1239
1256
  if self.return_intermediate_steps:
1240
- return self.agent.return_values + ["intermediate_steps"]
1257
+ return self._action_agent.return_values + ["intermediate_steps"]
1241
1258
  else:
1242
- return self.agent.return_values
1259
+ return self._action_agent.return_values
1243
1260
 
1244
1261
  def lookup_tool(self, name: str) -> BaseTool:
1245
1262
  """Lookup tool by name.
@@ -1339,7 +1356,7 @@ class AgentExecutor(Chain):
1339
1356
  intermediate_steps = self._prepare_intermediate_steps(intermediate_steps)
1340
1357
 
1341
1358
  # Call the LLM to see what to do.
1342
- output = self.agent.plan(
1359
+ output = self._action_agent.plan(
1343
1360
  intermediate_steps,
1344
1361
  callbacks=run_manager.get_child() if run_manager else None,
1345
1362
  **inputs,
@@ -1372,7 +1389,7 @@ class AgentExecutor(Chain):
1372
1389
  output = AgentAction("_Exception", observation, text)
1373
1390
  if run_manager:
1374
1391
  run_manager.on_agent_action(output, color="green")
1375
- tool_run_kwargs = self.agent.tool_run_logging_kwargs()
1392
+ tool_run_kwargs = self._action_agent.tool_run_logging_kwargs()
1376
1393
  observation = ExceptionTool().run(
1377
1394
  output.tool_input,
1378
1395
  verbose=self.verbose,
@@ -1414,7 +1431,7 @@ class AgentExecutor(Chain):
1414
1431
  tool = name_to_tool_map[agent_action.tool]
1415
1432
  return_direct = tool.return_direct
1416
1433
  color = color_mapping[agent_action.tool]
1417
- tool_run_kwargs = self.agent.tool_run_logging_kwargs()
1434
+ tool_run_kwargs = self._action_agent.tool_run_logging_kwargs()
1418
1435
  if return_direct:
1419
1436
  tool_run_kwargs["llm_prefix"] = ""
1420
1437
  # We then call the tool on the tool input to get an observation
@@ -1426,7 +1443,7 @@ class AgentExecutor(Chain):
1426
1443
  **tool_run_kwargs,
1427
1444
  )
1428
1445
  else:
1429
- tool_run_kwargs = self.agent.tool_run_logging_kwargs()
1446
+ tool_run_kwargs = self._action_agent.tool_run_logging_kwargs()
1430
1447
  observation = InvalidTool().run(
1431
1448
  {
1432
1449
  "requested_tool_name": agent_action.tool,
@@ -1476,7 +1493,7 @@ class AgentExecutor(Chain):
1476
1493
  intermediate_steps = self._prepare_intermediate_steps(intermediate_steps)
1477
1494
 
1478
1495
  # Call the LLM to see what to do.
1479
- output = await self.agent.aplan(
1496
+ output = await self._action_agent.aplan(
1480
1497
  intermediate_steps,
1481
1498
  callbacks=run_manager.get_child() if run_manager else None,
1482
1499
  **inputs,
@@ -1507,7 +1524,7 @@ class AgentExecutor(Chain):
1507
1524
  else:
1508
1525
  raise ValueError("Got unexpected type of `handle_parsing_errors`")
1509
1526
  output = AgentAction("_Exception", observation, text)
1510
- tool_run_kwargs = self.agent.tool_run_logging_kwargs()
1527
+ tool_run_kwargs = self._action_agent.tool_run_logging_kwargs()
1511
1528
  observation = await ExceptionTool().arun(
1512
1529
  output.tool_input,
1513
1530
  verbose=self.verbose,
@@ -1561,7 +1578,7 @@ class AgentExecutor(Chain):
1561
1578
  tool = name_to_tool_map[agent_action.tool]
1562
1579
  return_direct = tool.return_direct
1563
1580
  color = color_mapping[agent_action.tool]
1564
- tool_run_kwargs = self.agent.tool_run_logging_kwargs()
1581
+ tool_run_kwargs = self._action_agent.tool_run_logging_kwargs()
1565
1582
  if return_direct:
1566
1583
  tool_run_kwargs["llm_prefix"] = ""
1567
1584
  # We then call the tool on the tool input to get an observation
@@ -1573,7 +1590,7 @@ class AgentExecutor(Chain):
1573
1590
  **tool_run_kwargs,
1574
1591
  )
1575
1592
  else:
1576
- tool_run_kwargs = self.agent.tool_run_logging_kwargs()
1593
+ tool_run_kwargs = self._action_agent.tool_run_logging_kwargs()
1577
1594
  observation = await InvalidTool().arun(
1578
1595
  {
1579
1596
  "requested_tool_name": agent_action.tool,
@@ -1628,7 +1645,7 @@ class AgentExecutor(Chain):
1628
1645
  )
1629
1646
  iterations += 1
1630
1647
  time_elapsed = time.time() - start_time
1631
- output = self.agent.return_stopped_response(
1648
+ output = self._action_agent.return_stopped_response(
1632
1649
  self.early_stopping_method, intermediate_steps, **inputs
1633
1650
  )
1634
1651
  return self._return(output, intermediate_steps, run_manager=run_manager)
@@ -1680,7 +1697,7 @@ class AgentExecutor(Chain):
1680
1697
 
1681
1698
  iterations += 1
1682
1699
  time_elapsed = time.time() - start_time
1683
- output = self.agent.return_stopped_response(
1700
+ output = self._action_agent.return_stopped_response(
1684
1701
  self.early_stopping_method, intermediate_steps, **inputs
1685
1702
  )
1686
1703
  return await self._areturn(
@@ -1688,7 +1705,7 @@ class AgentExecutor(Chain):
1688
1705
  )
1689
1706
  except (TimeoutError, asyncio.TimeoutError):
1690
1707
  # stop early when interrupted by the async timeout
1691
- output = self.agent.return_stopped_response(
1708
+ output = self._action_agent.return_stopped_response(
1692
1709
  self.early_stopping_method, intermediate_steps, **inputs
1693
1710
  )
1694
1711
  return await self._areturn(
@@ -1702,8 +1719,8 @@ class AgentExecutor(Chain):
1702
1719
  agent_action, observation = next_step_output
1703
1720
  name_to_tool_map = {tool.name: tool for tool in self.tools}
1704
1721
  return_value_key = "output"
1705
- if len(self.agent.return_values) > 0:
1706
- return_value_key = self.agent.return_values[0]
1722
+ if len(self._action_agent.return_values) > 0:
1723
+ return_value_key = self._action_agent.return_values[0]
1707
1724
  # Invalid tools won't be in the map, so we return False.
1708
1725
  if agent_action.tool in name_to_tool_map:
1709
1726
  if name_to_tool_map[agent_action.tool].return_direct:
@@ -371,7 +371,7 @@ class AgentExecutorIterator:
371
371
  """
372
372
  logger.warning("Stopping agent prematurely due to triggering stop condition")
373
373
  # this manually constructs agent finish with output key
374
- output = self.agent_executor.agent.return_stopped_response(
374
+ output = self.agent_executor._action_agent.return_stopped_response(
375
375
  self.agent_executor.early_stopping_method,
376
376
  self.intermediate_steps,
377
377
  **self.inputs,
@@ -384,7 +384,7 @@ class AgentExecutorIterator:
384
384
  the stopped response.
385
385
  """
386
386
  logger.warning("Stopping agent prematurely due to triggering stop condition")
387
- output = self.agent_executor.agent.return_stopped_response(
387
+ output = self.agent_executor._action_agent.return_stopped_response(
388
388
  self.agent_executor.early_stopping_method,
389
389
  self.intermediate_steps,
390
390
  **self.inputs,
@@ -18,6 +18,7 @@ from pathlib import Path
18
18
  from typing import TYPE_CHECKING, Any
19
19
 
20
20
  from langchain_core._api.path import as_import_path
21
+ from langchain_core.tools.retriever import create_retriever_tool
21
22
 
22
23
  from langchain._api import create_importer
23
24
  from langchain.agents.agent_toolkits.conversational_retrieval.openai_functions import (
@@ -32,7 +33,6 @@ from langchain.agents.agent_toolkits.vectorstore.toolkit import (
32
33
  VectorStoreRouterToolkit,
33
34
  VectorStoreToolkit,
34
35
  )
35
- from langchain.tools.retriever import create_retriever_tool
36
36
 
37
37
  if TYPE_CHECKING:
38
38
  from langchain_community.agent_toolkits.ainetwork.toolkit import AINetworkToolkit
@@ -4,7 +4,8 @@ from typing import List
4
4
 
5
5
  from langchain_core.language_models import BaseLanguageModel
6
6
  from langchain_core.pydantic_v1 import BaseModel, Field
7
- from langchain_core.tools import BaseTool, BaseToolkit
7
+ from langchain_core.tools import BaseTool
8
+ from langchain_core.tools.base import BaseToolkit
8
9
  from langchain_core.vectorstores import VectorStore
9
10
 
10
11
 
@@ -7,11 +7,11 @@ from langchain_core._api import deprecated
7
7
 
8
8
  @deprecated(
9
9
  "0.1.0",
10
- alternative=(
10
+ message=(
11
11
  "Use new agent constructor methods like create_react_agent, create_json_agent, "
12
12
  "create_structured_chat_agent, etc."
13
13
  ),
14
- removal="0.3.0",
14
+ removal="1.0",
15
15
  )
16
16
  class AgentType(str, Enum):
17
17
  """An enum for agent types.
@@ -25,7 +25,7 @@ from langchain.agents.utils import validate_tools_single_input
25
25
  from langchain.chains.llm import LLMChain
26
26
 
27
27
 
28
- @deprecated("0.1.0", alternative="create_react_agent", removal="0.3.0")
28
+ @deprecated("0.1.0", alternative="create_react_agent", removal="1.0")
29
29
  class ChatAgent(Agent):
30
30
  """Chat Agent."""
31
31
 
@@ -19,7 +19,7 @@ from langchain.agents.utils import validate_tools_single_input
19
19
  from langchain.chains import LLMChain
20
20
 
21
21
 
22
- @deprecated("0.1.0", alternative="create_react_agent", removal="0.3.0")
22
+ @deprecated("0.1.0", alternative="create_react_agent", removal="1.0")
23
23
  class ConversationalAgent(Agent):
24
24
  """An agent that holds a conversation in addition to using tools."""
25
25
 
@@ -31,7 +31,7 @@ from langchain.agents.utils import validate_tools_single_input
31
31
  from langchain.chains import LLMChain
32
32
 
33
33
 
34
- @deprecated("0.1.0", alternative="create_json_chat_agent", removal="0.3.0")
34
+ @deprecated("0.1.0", alternative="create_json_chat_agent", removal="1.0")
35
35
  class ConversationalChatAgent(Agent):
36
36
  """An agent designed to hold a conversation in addition to using tools."""
37
37
 
@@ -18,7 +18,7 @@ from langchain.agents.loading import AGENT_TO_CLASS, load_agent
18
18
  "Use new agent constructor methods like create_react_agent, create_json_agent, "
19
19
  "create_structured_chat_agent, etc."
20
20
  ),
21
- removal="0.3.0",
21
+ removal="1.0",
22
22
  )
23
23
  def initialize_agent(
24
24
  tools: Sequence[BaseTool],
@@ -4,11 +4,11 @@ from langchain_core.language_models import BaseLanguageModel
4
4
  from langchain_core.prompts.chat import ChatPromptTemplate
5
5
  from langchain_core.runnables import Runnable, RunnablePassthrough
6
6
  from langchain_core.tools import BaseTool
7
+ from langchain_core.tools.render import ToolsRenderer, render_text_description
7
8
 
8
9
  from langchain.agents.format_scratchpad import format_log_to_messages
9
10
  from langchain.agents.json_chat.prompt import TEMPLATE_TOOL_RESPONSE
10
11
  from langchain.agents.output_parsers import JSONAgentOutputParser
11
- from langchain.tools.render import ToolsRenderer, render_text_description
12
12
 
13
13
 
14
14
  def create_json_chat_agent(
@@ -31,7 +31,7 @@ def _load_agent_from_tools(
31
31
  return agent_cls.from_llm_and_tools(llm, tools, **combined_config)
32
32
 
33
33
 
34
- @deprecated("0.1.0", removal="0.3.0")
34
+ @deprecated("0.1.0", removal="1.0")
35
35
  def load_agent_from_config(
36
36
  config: dict,
37
37
  llm: Optional[BaseLanguageModel] = None,
@@ -90,7 +90,7 @@ def load_agent_from_config(
90
90
  return agent_cls(**combined_config) # type: ignore
91
91
 
92
92
 
93
- @deprecated("0.1.0", removal="0.3.0")
93
+ @deprecated("0.1.0", removal="1.0")
94
94
  def load_agent(
95
95
  path: Union[str, Path], **kwargs: Any
96
96
  ) -> Union[BaseSingleActionAgent, BaseMultiActionAgent]:
@@ -10,6 +10,7 @@ from langchain_core.language_models import BaseLanguageModel
10
10
  from langchain_core.prompts import PromptTemplate
11
11
  from langchain_core.pydantic_v1 import Field
12
12
  from langchain_core.tools import BaseTool, Tool
13
+ from langchain_core.tools.render import render_text_description
13
14
 
14
15
  from langchain.agents.agent import Agent, AgentExecutor, AgentOutputParser
15
16
  from langchain.agents.agent_types import AgentType
@@ -17,7 +18,6 @@ from langchain.agents.mrkl.output_parser import MRKLOutputParser
17
18
  from langchain.agents.mrkl.prompt import FORMAT_INSTRUCTIONS, PREFIX, SUFFIX
18
19
  from langchain.agents.utils import validate_tools_single_input
19
20
  from langchain.chains import LLMChain
20
- from langchain.tools.render import render_text_description
21
21
 
22
22
 
23
23
  class ChainConfig(NamedTuple):
@@ -34,7 +34,7 @@ class ChainConfig(NamedTuple):
34
34
  action_description: str
35
35
 
36
36
 
37
- @deprecated("0.1.0", alternative="create_react_agent", removal="0.3.0")
37
+ @deprecated("0.1.0", alternative="create_react_agent", removal="1.0")
38
38
  class ZeroShotAgent(Agent):
39
39
  """Agent for the MRKL chain.
40
40
 
@@ -168,7 +168,7 @@ class ZeroShotAgent(Agent):
168
168
  super()._validate_tools(tools)
169
169
 
170
170
 
171
- @deprecated("0.1.0", removal="0.3.0")
171
+ @deprecated("0.1.0", removal="1.0")
172
172
  class MRKLChain(AgentExecutor):
173
173
  """Chain that implements the MRKL system."""
174
174
 
@@ -272,7 +272,6 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
272
272
  instructions=instructions,
273
273
  tools=[_get_assistants_tool(tool) for tool in tools], # type: ignore
274
274
  model=model,
275
- file_ids=kwargs.get("file_ids"),
276
275
  )
277
276
  return cls(assistant_id=assistant.id, client=client, **kwargs)
278
277
 
@@ -287,7 +286,6 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
287
286
  thread_id: Existing thread to use.
288
287
  run_id: Existing run to use. Should only be supplied when providing
289
288
  the tool output for a required action after an initial invocation.
290
- file_ids: File ids to include in new run. Used for retrieval.
291
289
  message_metadata: Metadata to associate with new message.
292
290
  thread_metadata: Metadata to associate with new thread. Only relevant
293
291
  when new thread being created.
@@ -327,7 +325,6 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
327
325
  {
328
326
  "role": "user",
329
327
  "content": input["content"],
330
- "file_ids": input.get("file_ids", []),
331
328
  "metadata": input.get("message_metadata"),
332
329
  }
333
330
  ],
@@ -340,7 +337,6 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
340
337
  input["thread_id"],
341
338
  content=input["content"],
342
339
  role="user",
343
- file_ids=input.get("file_ids", []),
344
340
  metadata=input.get("message_metadata"),
345
341
  )
346
342
  run = self._create_run(input)
@@ -394,7 +390,6 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
394
390
  instructions=instructions,
395
391
  tools=openai_tools, # type: ignore
396
392
  model=model,
397
- file_ids=kwargs.get("file_ids"),
398
393
  )
399
394
  return cls(assistant_id=assistant.id, async_client=async_client, **kwargs)
400
395
 
@@ -409,7 +404,6 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
409
404
  thread_id: Existing thread to use.
410
405
  run_id: Existing run to use. Should only be supplied when providing
411
406
  the tool output for a required action after an initial invocation.
412
- file_ids: File ids to include in new run. Used for retrieval.
413
407
  message_metadata: Metadata to associate with a new message.
414
408
  thread_metadata: Metadata to associate with new thread. Only relevant
415
409
  when a new thread is created.
@@ -439,7 +433,7 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
439
433
  try:
440
434
  # Being run within AgentExecutor and there are tool outputs to submit.
441
435
  if self.as_agent and input.get("intermediate_steps"):
442
- tool_outputs = self._parse_intermediate_steps(
436
+ tool_outputs = await self._aparse_intermediate_steps(
443
437
  input["intermediate_steps"]
444
438
  )
445
439
  run = await self.async_client.beta.threads.runs.submit_tool_outputs(
@@ -452,7 +446,6 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
452
446
  {
453
447
  "role": "user",
454
448
  "content": input["content"],
455
- "file_ids": input.get("file_ids", []),
456
449
  "metadata": input.get("message_metadata"),
457
450
  }
458
451
  ],
@@ -465,7 +458,6 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
465
458
  input["thread_id"],
466
459
  content=input["content"],
467
460
  role="user",
468
- file_ids=input.get("file_ids", []),
469
461
  metadata=input.get("message_metadata"),
470
462
  )
471
463
  run = await self._acreate_run(input)
@@ -493,9 +485,11 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
493
485
  ) -> dict:
494
486
  last_action, last_output = intermediate_steps[-1]
495
487
  run = self._wait_for_run(last_action.run_id, last_action.thread_id)
496
- required_tool_call_ids = {
497
- tc.id for tc in run.required_action.submit_tool_outputs.tool_calls
498
- }
488
+ required_tool_call_ids = set()
489
+ if run.required_action:
490
+ required_tool_call_ids = {
491
+ tc.id for tc in run.required_action.submit_tool_outputs.tool_calls
492
+ }
499
493
  tool_outputs = [
500
494
  {"output": str(output), "tool_call_id": action.tool_call_id}
501
495
  for action, output in intermediate_steps
@@ -621,9 +615,11 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
621
615
  ) -> dict:
622
616
  last_action, last_output = intermediate_steps[-1]
623
617
  run = await self._wait_for_run(last_action.run_id, last_action.thread_id)
624
- required_tool_call_ids = {
625
- tc.id for tc in run.required_action.submit_tool_outputs.tool_calls
626
- }
618
+ required_tool_call_ids = set()
619
+ if run.required_action:
620
+ required_tool_call_ids = {
621
+ tc.id for tc in run.required_action.submit_tool_outputs.tool_calls
622
+ }
627
623
  tool_outputs = [
628
624
  {"output": str(output), "tool_call_id": action.tool_call_id}
629
625
  for action, output in intermediate_steps
@@ -31,7 +31,7 @@ from langchain.agents.output_parsers.openai_functions import (
31
31
  )
32
32
 
33
33
 
34
- @deprecated("0.1.0", alternative="create_openai_functions_agent", removal="0.3.0")
34
+ @deprecated("0.1.0", alternative="create_openai_functions_agent", removal="1.0")
35
35
  class OpenAIFunctionsAgent(BaseSingleActionAgent):
36
36
  """An Agent driven by OpenAIs function powered API.
37
37
 
@@ -94,7 +94,7 @@ def _parse_ai_message(message: BaseMessage) -> Union[List[AgentAction], AgentFin
94
94
  )
95
95
 
96
96
 
97
- @deprecated("0.1.0", alternative="create_openai_tools_agent", removal="0.3.0")
97
+ @deprecated("0.1.0", alternative="create_openai_tools_agent", removal="1.0")
98
98
  class OpenAIMultiFunctionsAgent(BaseMultiActionAgent):
99
99
  """Agent driven by OpenAIs function powered API.
100
100
 
@@ -6,11 +6,11 @@ from langchain_core.language_models import BaseLanguageModel
6
6
  from langchain_core.prompts import BasePromptTemplate
7
7
  from langchain_core.runnables import Runnable, RunnablePassthrough
8
8
  from langchain_core.tools import BaseTool
9
+ from langchain_core.tools.render import ToolsRenderer, render_text_description
9
10
 
10
11
  from langchain.agents import AgentOutputParser
11
12
  from langchain.agents.format_scratchpad import format_log_to_str
12
13
  from langchain.agents.output_parsers import ReActSingleInputOutputParser
13
- from langchain.tools.render import ToolsRenderer, render_text_description
14
14
 
15
15
 
16
16
  def create_react_agent(
@@ -22,7 +22,7 @@ if TYPE_CHECKING:
22
22
  from langchain_community.docstore.base import Docstore
23
23
 
24
24
 
25
- @deprecated("0.1.0", removal="0.3.0")
25
+ @deprecated("0.1.0", removal="1.0")
26
26
  class ReActDocstoreAgent(Agent):
27
27
  """Agent for the ReAct chain."""
28
28
 
@@ -69,7 +69,7 @@ class ReActDocstoreAgent(Agent):
69
69
  return "Thought:"
70
70
 
71
71
 
72
- @deprecated("0.1.0", removal="0.3.0")
72
+ @deprecated("0.1.0", removal="1.0")
73
73
  class DocstoreExplorer:
74
74
  """Class to assist with exploration of a document store."""
75
75
 
@@ -119,7 +119,7 @@ class DocstoreExplorer:
119
119
  return self.document.page_content.split("\n\n")
120
120
 
121
121
 
122
- @deprecated("0.1.0", removal="0.3.0")
122
+ @deprecated("0.1.0", removal="1.0")
123
123
  class ReActTextWorldAgent(ReActDocstoreAgent):
124
124
  """Agent for the ReAct TextWorld chain."""
125
125
 
@@ -139,7 +139,7 @@ class ReActTextWorldAgent(ReActDocstoreAgent):
139
139
  raise ValueError(f"Tool name should be Play, got {tool_names}")
140
140
 
141
141
 
142
- @deprecated("0.1.0", removal="0.3.0")
142
+ @deprecated("0.1.0", removal="1.0")
143
143
  class ReActChain(AgentExecutor):
144
144
  """[Deprecated] Chain that implements the ReAct paper."""
145
145
 
@@ -24,7 +24,7 @@ if TYPE_CHECKING:
24
24
  from langchain_community.utilities.serpapi import SerpAPIWrapper
25
25
 
26
26
 
27
- @deprecated("0.1.0", alternative="create_self_ask_with_search", removal="0.3.0")
27
+ @deprecated("0.1.0", alternative="create_self_ask_with_search", removal="1.0")
28
28
  class SelfAskWithSearchAgent(Agent):
29
29
  """Agent for the self-ask-with-search paper."""
30
30
 
@@ -67,7 +67,7 @@ class SelfAskWithSearchAgent(Agent):
67
67
  return ""
68
68
 
69
69
 
70
- @deprecated("0.1.0", removal="0.3.0")
70
+ @deprecated("0.1.0", removal="1.0")
71
71
  class SelfAskWithSearchChain(AgentExecutor):
72
72
  """[Deprecated] Chain that does self-ask with search."""
73
73
 
@@ -14,6 +14,7 @@ from langchain_core.prompts.chat import (
14
14
  from langchain_core.pydantic_v1 import Field
15
15
  from langchain_core.runnables import Runnable, RunnablePassthrough
16
16
  from langchain_core.tools import BaseTool
17
+ from langchain_core.tools.render import ToolsRenderer
17
18
 
18
19
  from langchain.agents.agent import Agent, AgentOutputParser
19
20
  from langchain.agents.format_scratchpad import format_log_to_str
@@ -23,12 +24,12 @@ from langchain.agents.structured_chat.output_parser import (
23
24
  )
24
25
  from langchain.agents.structured_chat.prompt import FORMAT_INSTRUCTIONS, PREFIX, SUFFIX
25
26
  from langchain.chains.llm import LLMChain
26
- from langchain.tools.render import ToolsRenderer, render_text_description_and_args
27
+ from langchain.tools.render import render_text_description_and_args
27
28
 
28
29
  HUMAN_MESSAGE_TEMPLATE = "{input}\n\n{agent_scratchpad}"
29
30
 
30
31
 
31
- @deprecated("0.1.0", alternative="create_structured_chat_agent", removal="0.3.0")
32
+ @deprecated("0.1.0", alternative="create_structured_chat_agent", removal="1.0")
32
33
  class StructuredChatAgent(Agent):
33
34
  """Structured Chat Agent."""
34
35