Skip to content

Commit a5d003f

Browse files
authored
update notebook and make backwards compatible (#772)
1 parent 924b7ec commit a5d003f

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

docs/modules/agents/examples/custom_agent.ipynb

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
},
5454
{
5555
"cell_type": "code",
56-
"execution_count": 5,
56+
"execution_count": 2,
5757
"id": "becda2a1",
5858
"metadata": {},
5959
"outputs": [],
@@ -70,7 +70,7 @@
7070
},
7171
{
7272
"cell_type": "code",
73-
"execution_count": 6,
73+
"execution_count": 3,
7474
"id": "339b1bb8",
7575
"metadata": {},
7676
"outputs": [],
@@ -99,7 +99,7 @@
9999
},
100100
{
101101
"cell_type": "code",
102-
"execution_count": 7,
102+
"execution_count": 4,
103103
"id": "e21d2098",
104104
"metadata": {},
105105
"outputs": [
@@ -134,7 +134,6 @@
134134
]
135135
},
136136
{
137-
"attachments": {},
138137
"cell_type": "markdown",
139138
"id": "5e028e6d",
140139
"metadata": {},
@@ -146,7 +145,7 @@
146145
},
147146
{
148147
"cell_type": "code",
149-
"execution_count": 16,
148+
"execution_count": 5,
150149
"id": "9b1cc2a2",
151150
"metadata": {},
152151
"outputs": [],
@@ -156,17 +155,18 @@
156155
},
157156
{
158157
"cell_type": "code",
159-
"execution_count": 17,
158+
"execution_count": 7,
160159
"id": "e4f5092f",
161160
"metadata": {},
162161
"outputs": [],
163162
"source": [
164-
"agent = ZeroShotAgent(llm_chain=llm_chain, tools=tools)"
163+
"tool_names = [tool.name for tool in tools]\n",
164+
"agent = ZeroShotAgent(llm_chain=llm_chain, allowed_tools=tool_names)"
165165
]
166166
},
167167
{
168168
"cell_type": "code",
169-
"execution_count": 18,
169+
"execution_count": 8,
170170
"id": "490604e9",
171171
"metadata": {},
172172
"outputs": [],
@@ -176,7 +176,7 @@
176176
},
177177
{
178178
"cell_type": "code",
179-
"execution_count": 19,
179+
"execution_count": 9,
180180
"id": "653b1617",
181181
"metadata": {},
182182
"outputs": [
@@ -191,22 +191,23 @@
191191
"Action: Search\n",
192192
"Action Input: Population of Canada\u001b[0m\n",
193193
"Observation: \u001b[36;1m\u001b[1;3mCanada is a country in North America. Its ten provinces and three territories extend from the Atlantic Ocean to the Pacific Ocean and northward into the Arctic Ocean, covering over 9.98 million square kilometres, making it the world's second-largest country by total area.\u001b[0m\n",
194-
"Thought:\u001b[32;1m\u001b[1;3m I need to find out the exact population of Canada\n",
194+
"Thought:\u001b[32;1m\u001b[1;3m I need to find out the population of Canada\n",
195195
"Action: Search\n",
196-
"Action Input: Population of Canada 2020\u001b[0m\n",
196+
"Action Input: Population of Canada\u001b[0m\n",
197197
"Observation: \u001b[36;1m\u001b[1;3mCanada is a country in North America. Its ten provinces and three territories extend from the Atlantic Ocean to the Pacific Ocean and northward into the Arctic Ocean, covering over 9.98 million square kilometres, making it the world's second-largest country by total area.\u001b[0m\n",
198198
"Thought:\u001b[32;1m\u001b[1;3m I now know the population of Canada\n",
199-
"Final Answer: Arrr, Canada be home to 37.59 million people!\u001b[0m\n",
200-
"\u001b[1m> Finished AgentExecutor chain.\u001b[0m\n"
199+
"Final Answer: Arrr, Canada be home to over 37 million people!\u001b[0m\n",
200+
"\n",
201+
"\u001b[1m> Finished chain.\u001b[0m\n"
201202
]
202203
},
203204
{
204205
"data": {
205206
"text/plain": [
206-
"'Arrr, Canada be home to 37.59 million people!'"
207+
"'Arrr, Canada be home to over 37 million people!'"
207208
]
208209
},
209-
"execution_count": 19,
210+
"execution_count": 9,
210211
"metadata": {},
211212
"output_type": "execute_result"
212213
}
@@ -361,7 +362,7 @@
361362
],
362363
"metadata": {
363364
"kernelspec": {
364-
"display_name": "Python 3",
365+
"display_name": "Python 3 (ipykernel)",
365366
"language": "python",
366367
"name": "python3"
367368
},
@@ -375,7 +376,7 @@
375376
"name": "python",
376377
"nbconvert_exporter": "python",
377378
"pygments_lexer": "ipython3",
378-
"version": "3.8.12 (default, Feb 15 2022, 17:41:09) \n[Clang 12.0.5 (clang-1205.0.22.11)]"
379+
"version": "3.10.9"
379380
},
380381
"vscode": {
381382
"interpreter": {

langchain/agents/agent.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Agent(BaseModel):
3333
"""
3434

3535
llm_chain: LLMChain
36-
allowed_tools: List[str]
36+
allowed_tools: Optional[List[str]] = None
3737
return_values: List[str] = ["output"]
3838

3939
@abstractmethod
@@ -269,11 +269,12 @@ def validate_tools(cls, values: Dict) -> Dict:
269269
"""Validate that tools are compatible with agent."""
270270
agent = values["agent"]
271271
tools = values["tools"]
272-
if set(agent.allowed_tools) != set([tool.name for tool in tools]):
273-
raise ValueError(
274-
f"Allowed tools ({agent.allowed_tools}) different than "
275-
f"provided tools ({[tool.name for tool in tools]})"
276-
)
272+
if agent.allowed_tools is not None:
273+
if set(agent.allowed_tools) != set([tool.name for tool in tools]):
274+
raise ValueError(
275+
f"Allowed tools ({agent.allowed_tools}) different than "
276+
f"provided tools ({[tool.name for tool in tools]})"
277+
)
277278
return values
278279

279280
def save(self, file_path: Union[Path, str]) -> None:

0 commit comments

Comments
 (0)