langchain 0.2.12__py3-none-any.whl → 0.2.14__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.
Potentially problematic release.
This version of langchain might be problematic. Click here for more details.
- langchain/_api/module_import.py +2 -2
- langchain/agents/__init__.py +4 -3
- langchain/agents/agent.py +7 -11
- langchain/agents/agent_toolkits/__init__.py +1 -1
- langchain/agents/agent_toolkits/vectorstore/base.py +114 -2
- langchain/agents/agent_toolkits/vectorstore/toolkit.py +2 -7
- langchain/agents/agent_types.py +1 -1
- langchain/agents/chat/base.py +1 -1
- langchain/agents/conversational/base.py +1 -1
- langchain/agents/conversational_chat/base.py +1 -1
- langchain/agents/initialize.py +2 -2
- langchain/agents/json_chat/base.py +1 -1
- langchain/agents/loading.py +4 -4
- langchain/agents/mrkl/base.py +4 -4
- langchain/agents/openai_assistant/base.py +2 -2
- langchain/agents/openai_functions_agent/base.py +2 -2
- langchain/agents/openai_functions_multi_agent/base.py +2 -2
- langchain/agents/react/agent.py +1 -1
- langchain/agents/react/base.py +4 -4
- langchain/agents/self_ask_with_search/base.py +2 -2
- langchain/agents/structured_chat/base.py +3 -2
- langchain/agents/tools.py +2 -2
- langchain/agents/xml/base.py +2 -2
- langchain/chains/__init__.py +1 -0
- langchain/chains/api/base.py +121 -1
- langchain/chains/base.py +5 -7
- langchain/chains/combine_documents/map_reduce.py +2 -4
- langchain/chains/combine_documents/map_rerank.py +4 -6
- langchain/chains/combine_documents/reduce.py +1 -4
- langchain/chains/combine_documents/refine.py +2 -4
- langchain/chains/combine_documents/stuff.py +12 -4
- langchain/chains/conversation/base.py +2 -4
- langchain/chains/conversational_retrieval/base.py +5 -7
- langchain/chains/elasticsearch_database/base.py +16 -20
- langchain/chains/example_generator.py +3 -4
- langchain/chains/flare/base.py +1 -1
- langchain/chains/hyde/base.py +1 -4
- langchain/chains/llm.py +2 -4
- langchain/chains/llm_checker/base.py +12 -4
- langchain/chains/llm_math/base.py +2 -4
- langchain/chains/llm_summarization_checker/base.py +12 -4
- langchain/chains/loading.py +17 -0
- langchain/chains/mapreduce.py +12 -4
- langchain/chains/natbot/base.py +2 -4
- langchain/chains/openai_functions/__init__.py +2 -0
- langchain/chains/openai_functions/base.py +2 -2
- langchain/chains/openai_functions/citation_fuzzy_match.py +54 -1
- langchain/chains/openai_functions/extraction.py +2 -2
- langchain/chains/openai_functions/openapi.py +88 -1
- langchain/chains/openai_functions/qa_with_structure.py +19 -0
- langchain/chains/openai_functions/tagging.py +81 -0
- langchain/chains/openai_tools/extraction.py +1 -1
- langchain/chains/qa_with_sources/base.py +21 -4
- langchain/chains/qa_with_sources/loading.py +16 -0
- langchain/chains/query_constructor/base.py +8 -2
- langchain/chains/query_constructor/schema.py +0 -2
- langchain/chains/question_answering/chain.py +15 -0
- langchain/chains/retrieval_qa/base.py +30 -6
- langchain/chains/router/base.py +1 -4
- langchain/chains/router/embedding_router.py +1 -4
- langchain/chains/router/llm_router.py +76 -1
- langchain/chains/router/multi_prompt.py +76 -1
- langchain/chains/sequential.py +3 -7
- langchain/chains/structured_output/base.py +3 -3
- langchain/chat_models/base.py +8 -10
- langchain/evaluation/agents/trajectory_eval_chain.py +2 -4
- langchain/evaluation/comparison/eval_chain.py +2 -4
- langchain/evaluation/criteria/eval_chain.py +2 -4
- langchain/evaluation/embedding_distance/base.py +0 -2
- langchain/evaluation/parsing/json_schema.py +1 -1
- langchain/evaluation/qa/eval_chain.py +2 -7
- langchain/evaluation/schema.py +8 -8
- langchain/evaluation/scoring/eval_chain.py +2 -4
- langchain/evaluation/string_distance/base.py +4 -4
- langchain/hub.py +60 -26
- langchain/indexes/vectorstore.py +3 -7
- langchain/memory/entity.py +0 -2
- langchain/memory/summary.py +9 -0
- langchain/output_parsers/retry.py +1 -1
- langchain/retrievers/contextual_compression.py +0 -2
- langchain/retrievers/document_compressors/base.py +0 -2
- langchain/retrievers/document_compressors/chain_filter.py +1 -1
- langchain/retrievers/document_compressors/cohere_rerank.py +3 -5
- langchain/retrievers/document_compressors/cross_encoder_rerank.py +1 -4
- langchain/retrievers/document_compressors/embeddings_filter.py +0 -2
- langchain/retrievers/document_compressors/listwise_rerank.py +1 -1
- langchain/retrievers/multi_query.py +4 -2
- langchain/retrievers/re_phraser.py +1 -1
- langchain/retrievers/self_query/base.py +1 -3
- langchain/retrievers/time_weighted_retriever.py +0 -2
- langchain/tools/__init__.py +14 -5
- langchain/tools/render.py +0 -2
- langchain/tools/retriever.py +0 -4
- {langchain-0.2.12.dist-info → langchain-0.2.14.dist-info}/METADATA +2 -2
- {langchain-0.2.12.dist-info → langchain-0.2.14.dist-info}/RECORD +98 -98
- {langchain-0.2.12.dist-info → langchain-0.2.14.dist-info}/LICENSE +0 -0
- {langchain-0.2.12.dist-info → langchain-0.2.14.dist-info}/WHEEL +0 -0
- {langchain-0.2.12.dist-info → langchain-0.2.14.dist-info}/entry_points.txt +0 -0
langchain/_api/module_import.py
CHANGED
|
@@ -92,7 +92,7 @@ def create_importer(
|
|
|
92
92
|
warn_deprecated(
|
|
93
93
|
since="0.1",
|
|
94
94
|
pending=False,
|
|
95
|
-
removal="0
|
|
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
|
|
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"
|
langchain/agents/__init__.py
CHANGED
|
@@ -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
|
|
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
|
@@ -156,7 +156,7 @@ class BaseSingleActionAgent(BaseModel):
|
|
|
156
156
|
llm: Language model to use.
|
|
157
157
|
tools: Tools to use.
|
|
158
158
|
callback_manager: Callback manager to use.
|
|
159
|
-
|
|
159
|
+
kwargs: Additional arguments.
|
|
160
160
|
|
|
161
161
|
Returns:
|
|
162
162
|
BaseSingleActionAgent: Agent object.
|
|
@@ -420,8 +420,6 @@ class RunnableAgent(BaseSingleActionAgent):
|
|
|
420
420
|
"""
|
|
421
421
|
|
|
422
422
|
class Config:
|
|
423
|
-
"""Configuration for this pydantic object."""
|
|
424
|
-
|
|
425
423
|
arbitrary_types_allowed = True
|
|
426
424
|
|
|
427
425
|
@property
|
|
@@ -530,8 +528,6 @@ class RunnableMultiActionAgent(BaseMultiActionAgent):
|
|
|
530
528
|
"""
|
|
531
529
|
|
|
532
530
|
class Config:
|
|
533
|
-
"""Configuration for this pydantic object."""
|
|
534
|
-
|
|
535
531
|
arbitrary_types_allowed = True
|
|
536
532
|
|
|
537
533
|
@property
|
|
@@ -637,7 +633,7 @@ class RunnableMultiActionAgent(BaseMultiActionAgent):
|
|
|
637
633
|
"Use new agent constructor methods like create_react_agent, create_json_agent, "
|
|
638
634
|
"create_structured_chat_agent, etc."
|
|
639
635
|
),
|
|
640
|
-
removal="
|
|
636
|
+
removal="1.0",
|
|
641
637
|
)
|
|
642
638
|
class LLMSingleActionAgent(BaseSingleActionAgent):
|
|
643
639
|
"""Base class for single action agents."""
|
|
@@ -728,7 +724,7 @@ class LLMSingleActionAgent(BaseSingleActionAgent):
|
|
|
728
724
|
"Use new agent constructor methods like create_react_agent, create_json_agent, "
|
|
729
725
|
"create_structured_chat_agent, etc."
|
|
730
726
|
),
|
|
731
|
-
removal="
|
|
727
|
+
removal="1.0",
|
|
732
728
|
)
|
|
733
729
|
class Agent(BaseSingleActionAgent):
|
|
734
730
|
"""Agent that calls the language model and deciding the action.
|
|
@@ -939,7 +935,7 @@ class Agent(BaseSingleActionAgent):
|
|
|
939
935
|
tools: Tools to use.
|
|
940
936
|
callback_manager: Callback manager to use.
|
|
941
937
|
output_parser: Output parser to use.
|
|
942
|
-
|
|
938
|
+
kwargs: Additional arguments.
|
|
943
939
|
|
|
944
940
|
Returns:
|
|
945
941
|
Agent: Agent object.
|
|
@@ -1110,7 +1106,7 @@ class AgentExecutor(Chain):
|
|
|
1110
1106
|
agent: Agent to use.
|
|
1111
1107
|
tools: Tools to use.
|
|
1112
1108
|
callbacks: Callbacks to use.
|
|
1113
|
-
|
|
1109
|
+
kwargs: Additional arguments.
|
|
1114
1110
|
|
|
1115
1111
|
Returns:
|
|
1116
1112
|
AgentExecutor: Agent executor object.
|
|
@@ -1741,7 +1737,7 @@ class AgentExecutor(Chain):
|
|
|
1741
1737
|
Args:
|
|
1742
1738
|
input: Input to the agent.
|
|
1743
1739
|
config: Config to use.
|
|
1744
|
-
|
|
1740
|
+
kwargs: Additional arguments.
|
|
1745
1741
|
|
|
1746
1742
|
Yields:
|
|
1747
1743
|
AddableDict: Addable dictionary.
|
|
@@ -1772,7 +1768,7 @@ class AgentExecutor(Chain):
|
|
|
1772
1768
|
Args:
|
|
1773
1769
|
input: Input to the agent.
|
|
1774
1770
|
config: Config to use.
|
|
1775
|
-
|
|
1771
|
+
kwargs: Additional arguments.
|
|
1776
1772
|
|
|
1777
1773
|
Yields:
|
|
1778
1774
|
AddableDict: Addable dictionary.
|
|
@@ -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
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
from typing import Any, Dict, Optional
|
|
4
4
|
|
|
5
|
+
from langchain_core._api import deprecated
|
|
5
6
|
from langchain_core.callbacks.base import BaseCallbackManager
|
|
6
7
|
from langchain_core.language_models import BaseLanguageModel
|
|
7
8
|
|
|
@@ -15,6 +16,16 @@ from langchain.agents.mrkl.base import ZeroShotAgent
|
|
|
15
16
|
from langchain.chains.llm import LLMChain
|
|
16
17
|
|
|
17
18
|
|
|
19
|
+
@deprecated(
|
|
20
|
+
since="0.2.13",
|
|
21
|
+
removal="1.0",
|
|
22
|
+
message=(
|
|
23
|
+
"See API reference for this function for a replacement implementation: "
|
|
24
|
+
"https://api.python.langchain.com/en/latest/agents/langchain.agents.agent_toolkits.vectorstore.base.create_vectorstore_agent.html " # noqa: E501
|
|
25
|
+
"Read more here on how to create agents that query vector stores: "
|
|
26
|
+
"https://python.langchain.com/v0.2/docs/how_to/qa_chat_history_how_to/#agents"
|
|
27
|
+
),
|
|
28
|
+
)
|
|
18
29
|
def create_vectorstore_agent(
|
|
19
30
|
llm: BaseLanguageModel,
|
|
20
31
|
toolkit: VectorStoreToolkit,
|
|
@@ -26,6 +37,44 @@ def create_vectorstore_agent(
|
|
|
26
37
|
) -> AgentExecutor:
|
|
27
38
|
"""Construct a VectorStore agent from an LLM and tools.
|
|
28
39
|
|
|
40
|
+
Note: this class is deprecated. See below for a replacement that uses tool
|
|
41
|
+
calling methods and LangGraph. Install LangGraph with:
|
|
42
|
+
|
|
43
|
+
.. code-block:: bash
|
|
44
|
+
|
|
45
|
+
pip install -U langgraph
|
|
46
|
+
|
|
47
|
+
.. code-block:: python
|
|
48
|
+
|
|
49
|
+
from langchain_core.tools import create_retriever_tool
|
|
50
|
+
from langchain_core.vectorstores import InMemoryVectorStore
|
|
51
|
+
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
|
|
52
|
+
from langgraph.prebuilt import create_react_agent
|
|
53
|
+
|
|
54
|
+
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
|
|
55
|
+
|
|
56
|
+
vector_store = InMemoryVectorStore.from_texts(
|
|
57
|
+
[
|
|
58
|
+
"Dogs are great companions, known for their loyalty and friendliness.",
|
|
59
|
+
"Cats are independent pets that often enjoy their own space.",
|
|
60
|
+
],
|
|
61
|
+
OpenAIEmbeddings(),
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
tool = create_retriever_tool(
|
|
65
|
+
vector_store.as_retriever(),
|
|
66
|
+
"pet_information_retriever",
|
|
67
|
+
"Fetches information about pets.",
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
agent = create_react_agent(llm, [tool])
|
|
71
|
+
|
|
72
|
+
for step in agent.stream(
|
|
73
|
+
{"messages": [("human", "What are dogs known for?")]},
|
|
74
|
+
stream_mode="values",
|
|
75
|
+
):
|
|
76
|
+
step["messages"][-1].pretty_print()
|
|
77
|
+
|
|
29
78
|
Args:
|
|
30
79
|
llm (BaseLanguageModel): LLM that will be used by the agent
|
|
31
80
|
toolkit (VectorStoreToolkit): Set of tools for the agent
|
|
@@ -33,7 +82,7 @@ def create_vectorstore_agent(
|
|
|
33
82
|
prefix (str, optional): The prefix prompt for the agent. If not provided uses default PREFIX.
|
|
34
83
|
verbose (bool, optional): If you want to see the content of the scratchpad. [ Defaults to False ]
|
|
35
84
|
agent_executor_kwargs (Optional[Dict[str, Any]], optional): If there is any other parameter you want to send to the agent. [ Defaults to None ]
|
|
36
|
-
|
|
85
|
+
kwargs: Additional named parameters to pass to the ZeroShotAgent.
|
|
37
86
|
|
|
38
87
|
Returns:
|
|
39
88
|
AgentExecutor: Returns a callable AgentExecutor object. Either you can call it or use run method with the query to get the response
|
|
@@ -56,6 +105,16 @@ def create_vectorstore_agent(
|
|
|
56
105
|
)
|
|
57
106
|
|
|
58
107
|
|
|
108
|
+
@deprecated(
|
|
109
|
+
since="0.2.13",
|
|
110
|
+
removal="1.0",
|
|
111
|
+
message=(
|
|
112
|
+
"See API reference for this function for a replacement implementation: "
|
|
113
|
+
"https://api.python.langchain.com/en/latest/agents/langchain.agents.agent_toolkits.vectorstore.base.create_vectorstore_router_agent.html " # noqa: E501
|
|
114
|
+
"Read more here on how to create agents that query vector stores: "
|
|
115
|
+
"https://python.langchain.com/v0.2/docs/how_to/qa_chat_history_how_to/#agents"
|
|
116
|
+
),
|
|
117
|
+
)
|
|
59
118
|
def create_vectorstore_router_agent(
|
|
60
119
|
llm: BaseLanguageModel,
|
|
61
120
|
toolkit: VectorStoreRouterToolkit,
|
|
@@ -67,6 +126,59 @@ def create_vectorstore_router_agent(
|
|
|
67
126
|
) -> AgentExecutor:
|
|
68
127
|
"""Construct a VectorStore router agent from an LLM and tools.
|
|
69
128
|
|
|
129
|
+
Note: this class is deprecated. See below for a replacement that uses tool
|
|
130
|
+
calling methods and LangGraph. Install LangGraph with:
|
|
131
|
+
|
|
132
|
+
.. code-block:: bash
|
|
133
|
+
|
|
134
|
+
pip install -U langgraph
|
|
135
|
+
|
|
136
|
+
.. code-block:: python
|
|
137
|
+
|
|
138
|
+
from langchain_core.tools import create_retriever_tool
|
|
139
|
+
from langchain_core.vectorstores import InMemoryVectorStore
|
|
140
|
+
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
|
|
141
|
+
from langgraph.prebuilt import create_react_agent
|
|
142
|
+
|
|
143
|
+
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
|
|
144
|
+
|
|
145
|
+
pet_vector_store = InMemoryVectorStore.from_texts(
|
|
146
|
+
[
|
|
147
|
+
"Dogs are great companions, known for their loyalty and friendliness.",
|
|
148
|
+
"Cats are independent pets that often enjoy their own space.",
|
|
149
|
+
],
|
|
150
|
+
OpenAIEmbeddings(),
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
food_vector_store = InMemoryVectorStore.from_texts(
|
|
154
|
+
[
|
|
155
|
+
"Carrots are orange and delicious.",
|
|
156
|
+
"Apples are red and delicious.",
|
|
157
|
+
],
|
|
158
|
+
OpenAIEmbeddings(),
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
tools = [
|
|
162
|
+
create_retriever_tool(
|
|
163
|
+
pet_vector_store.as_retriever(),
|
|
164
|
+
"pet_information_retriever",
|
|
165
|
+
"Fetches information about pets.",
|
|
166
|
+
),
|
|
167
|
+
create_retriever_tool(
|
|
168
|
+
food_vector_store.as_retriever(),
|
|
169
|
+
"food_information_retriever",
|
|
170
|
+
"Fetches information about food.",
|
|
171
|
+
)
|
|
172
|
+
]
|
|
173
|
+
|
|
174
|
+
agent = create_react_agent(llm, tools)
|
|
175
|
+
|
|
176
|
+
for step in agent.stream(
|
|
177
|
+
{"messages": [("human", "Tell me about carrots.")]},
|
|
178
|
+
stream_mode="values",
|
|
179
|
+
):
|
|
180
|
+
step["messages"][-1].pretty_print()
|
|
181
|
+
|
|
70
182
|
Args:
|
|
71
183
|
llm (BaseLanguageModel): LLM that will be used by the agent
|
|
72
184
|
toolkit (VectorStoreRouterToolkit): Set of tools for the agent which have routing capability with multiple vector stores
|
|
@@ -74,7 +186,7 @@ def create_vectorstore_router_agent(
|
|
|
74
186
|
prefix (str, optional): The prefix prompt for the router agent. If not provided uses default ROUTER_PREFIX.
|
|
75
187
|
verbose (bool, optional): If you want to see the content of the scratchpad. [ Defaults to False ]
|
|
76
188
|
agent_executor_kwargs (Optional[Dict[str, Any]], optional): If there is any other parameter you want to send to the agent. [ Defaults to None ]
|
|
77
|
-
|
|
189
|
+
kwargs: Additional named parameters to pass to the ZeroShotAgent.
|
|
78
190
|
|
|
79
191
|
Returns:
|
|
80
192
|
AgentExecutor: Returns a callable AgentExecutor object. Either you can call it or use run method with the query to get the response.
|
|
@@ -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
|
|
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
|
|
|
@@ -16,8 +17,6 @@ class VectorStoreInfo(BaseModel):
|
|
|
16
17
|
description: str
|
|
17
18
|
|
|
18
19
|
class Config:
|
|
19
|
-
"""Configuration for this pydantic object."""
|
|
20
|
-
|
|
21
20
|
arbitrary_types_allowed = True
|
|
22
21
|
|
|
23
22
|
|
|
@@ -28,8 +27,6 @@ class VectorStoreToolkit(BaseToolkit):
|
|
|
28
27
|
llm: BaseLanguageModel
|
|
29
28
|
|
|
30
29
|
class Config:
|
|
31
|
-
"""Configuration for this pydantic object."""
|
|
32
|
-
|
|
33
30
|
arbitrary_types_allowed = True
|
|
34
31
|
|
|
35
32
|
def get_tools(self) -> List[BaseTool]:
|
|
@@ -71,8 +68,6 @@ class VectorStoreRouterToolkit(BaseToolkit):
|
|
|
71
68
|
llm: BaseLanguageModel
|
|
72
69
|
|
|
73
70
|
class Config:
|
|
74
|
-
"""Configuration for this pydantic object."""
|
|
75
|
-
|
|
76
71
|
arbitrary_types_allowed = True
|
|
77
72
|
|
|
78
73
|
def get_tools(self) -> List[BaseTool]:
|
langchain/agents/agent_types.py
CHANGED
|
@@ -11,7 +11,7 @@ from langchain_core._api import deprecated
|
|
|
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="
|
|
14
|
+
removal="1.0",
|
|
15
15
|
)
|
|
16
16
|
class AgentType(str, Enum):
|
|
17
17
|
"""An enum for agent types.
|
langchain/agents/chat/base.py
CHANGED
|
@@ -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="
|
|
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="
|
|
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="
|
|
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
|
|
langchain/agents/initialize.py
CHANGED
|
@@ -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="
|
|
21
|
+
removal="1.0",
|
|
22
22
|
)
|
|
23
23
|
def initialize_agent(
|
|
24
24
|
tools: Sequence[BaseTool],
|
|
@@ -45,7 +45,7 @@ def initialize_agent(
|
|
|
45
45
|
agent_kwargs: Additional keyword arguments to pass to the underlying agent.
|
|
46
46
|
Defaults to None.
|
|
47
47
|
tags: Tags to apply to the traced runs. Defaults to None.
|
|
48
|
-
|
|
48
|
+
kwargs: Additional keyword arguments passed to the agent executor.
|
|
49
49
|
|
|
50
50
|
Returns:
|
|
51
51
|
An agent executor.
|
|
@@ -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(
|
langchain/agents/loading.py
CHANGED
|
@@ -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="
|
|
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,
|
|
@@ -44,7 +44,7 @@ def load_agent_from_config(
|
|
|
44
44
|
config: Config dict to load agent from.
|
|
45
45
|
llm: Language model to use as the agent.
|
|
46
46
|
tools: List of tools this agent has access to.
|
|
47
|
-
|
|
47
|
+
kwargs: Additional keyword arguments passed to the agent executor.
|
|
48
48
|
|
|
49
49
|
Returns:
|
|
50
50
|
An agent executor.
|
|
@@ -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="
|
|
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]:
|
|
@@ -98,7 +98,7 @@ def load_agent(
|
|
|
98
98
|
|
|
99
99
|
Args:
|
|
100
100
|
path: Path to the agent file.
|
|
101
|
-
|
|
101
|
+
kwargs: Additional keyword arguments passed to the agent executor.
|
|
102
102
|
|
|
103
103
|
Returns:
|
|
104
104
|
An agent executor.
|
langchain/agents/mrkl/base.py
CHANGED
|
@@ -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="
|
|
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
|
|
|
@@ -128,7 +128,7 @@ class ZeroShotAgent(Agent):
|
|
|
128
128
|
format_instructions: The format instructions to use.
|
|
129
129
|
Defaults to FORMAT_INSTRUCTIONS.
|
|
130
130
|
input_variables: The input variables to use. Defaults to None.
|
|
131
|
-
|
|
131
|
+
kwargs: Additional parameters to pass to the agent.
|
|
132
132
|
"""
|
|
133
133
|
cls._validate_tools(tools)
|
|
134
134
|
prompt = cls.create_prompt(
|
|
@@ -168,7 +168,7 @@ class ZeroShotAgent(Agent):
|
|
|
168
168
|
super()._validate_tools(tools)
|
|
169
169
|
|
|
170
170
|
|
|
171
|
-
@deprecated("0.1.0", removal="
|
|
171
|
+
@deprecated("0.1.0", removal="1.0")
|
|
172
172
|
class MRKLChain(AgentExecutor):
|
|
173
173
|
"""Chain that implements the MRKL system."""
|
|
174
174
|
|
|
@@ -261,7 +261,7 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
|
|
|
261
261
|
model: Assistant model to use.
|
|
262
262
|
client: OpenAI or AzureOpenAI client.
|
|
263
263
|
Will create a default OpenAI client if not specified.
|
|
264
|
-
|
|
264
|
+
kwargs: Additional arguments.
|
|
265
265
|
|
|
266
266
|
Returns:
|
|
267
267
|
OpenAIAssistantRunnable configured to run using the created assistant.
|
|
@@ -418,7 +418,7 @@ class OpenAIAssistantRunnable(RunnableSerializable[Dict, OutputType]):
|
|
|
418
418
|
tools: Override Assistant tools for this run.
|
|
419
419
|
run_metadata: Metadata to associate with new run.
|
|
420
420
|
config: Runnable config. Defaults to None.
|
|
421
|
-
|
|
421
|
+
kwargs: Additional arguments.
|
|
422
422
|
|
|
423
423
|
Return:
|
|
424
424
|
If self.as_agent, will return
|
|
@@ -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="
|
|
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
|
|
|
@@ -262,7 +262,7 @@ class OpenAIFunctionsAgent(BaseSingleActionAgent):
|
|
|
262
262
|
extra_prompt_messages: Extra prompt messages to use. Defaults to None.
|
|
263
263
|
system_message: The system message to use.
|
|
264
264
|
Defaults to a default system message.
|
|
265
|
-
|
|
265
|
+
kwargs: Additional parameters to pass to the agent.
|
|
266
266
|
"""
|
|
267
267
|
prompt = cls.create_prompt(
|
|
268
268
|
extra_prompt_messages=extra_prompt_messages,
|
|
@@ -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="
|
|
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
|
|
|
@@ -307,7 +307,7 @@ class OpenAIMultiFunctionsAgent(BaseMultiActionAgent):
|
|
|
307
307
|
extra_prompt_messages: Extra prompt messages to use. Default is None.
|
|
308
308
|
system_message: The system message to use.
|
|
309
309
|
Default is a default system message.
|
|
310
|
-
|
|
310
|
+
kwargs: Additional arguments.
|
|
311
311
|
"""
|
|
312
312
|
prompt = cls.create_prompt(
|
|
313
313
|
extra_prompt_messages=extra_prompt_messages,
|
langchain/agents/react/agent.py
CHANGED
|
@@ -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(
|
langchain/agents/react/base.py
CHANGED
|
@@ -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="
|
|
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="
|
|
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="
|
|
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="
|
|
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="
|
|
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="
|
|
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
|
|
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="
|
|
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
|
|
langchain/agents/tools.py
CHANGED
|
@@ -6,7 +6,7 @@ from langchain_core.callbacks import (
|
|
|
6
6
|
AsyncCallbackManagerForToolRun,
|
|
7
7
|
CallbackManagerForToolRun,
|
|
8
8
|
)
|
|
9
|
-
from langchain_core.tools import BaseTool,
|
|
9
|
+
from langchain_core.tools import BaseTool, tool
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class InvalidTool(BaseTool):
|
|
@@ -44,4 +44,4 @@ class InvalidTool(BaseTool):
|
|
|
44
44
|
)
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
__all__ = ["InvalidTool", "
|
|
47
|
+
__all__ = ["InvalidTool", "tool"]
|