From 2ece692a4f1a10ee2ef4e117c1357bf132de0255 Mon Sep 17 00:00:00 2001 From: Oleg Ivaniv Date: Thu, 12 Sep 2024 14:47:19 +0200 Subject: [PATCH 1/2] fix: Prevent exception when using plan & execute agent with no tools --- .../plan_and_execute/agent_executor.ts | 2 +- .../tests/plan_and_execute.int.test.ts | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/langchain/src/experimental/plan_and_execute/agent_executor.ts b/langchain/src/experimental/plan_and_execute/agent_executor.ts index e0ca666ab024..0a744c8c1684 100644 --- a/langchain/src/experimental/plan_and_execute/agent_executor.ts +++ b/langchain/src/experimental/plan_and_execute/agent_executor.ts @@ -132,7 +132,7 @@ export class PlanAndExecuteAgentExecutor extends BaseChain { }) { let agent; - if (isDynamicStructuredTool(tools[0])) { + if (tools.length > 0 && isDynamicStructuredTool(tools[0])) { agent = StructuredChatAgent.fromLLMAndTools(llm, tools, { humanMessageTemplate, inputVariables: ["previous_steps", "current_step", "agent_scratchpad"], diff --git a/langchain/src/experimental/plan_and_execute/tests/plan_and_execute.int.test.ts b/langchain/src/experimental/plan_and_execute/tests/plan_and_execute.int.test.ts index 2b166db811e6..bc12d26c6979 100644 --- a/langchain/src/experimental/plan_and_execute/tests/plan_and_execute.int.test.ts +++ b/langchain/src/experimental/plan_and_execute/tests/plan_and_execute.int.test.ts @@ -67,3 +67,21 @@ test.skip("Run agent with a sequential math problem", async () => { // console.log(result); }); + +test.skip("Should run agent with no tools", async () => { + const model = new ChatOpenAI({ + temperature: 0, + modelName: "gpt-3.5-turbo", + verbose: true, + }); + const executor = await PlanAndExecuteAgentExecutor.fromLLMAndTools({ + llm: model, + tools: [], + }); + + // @eslint-disable-next-line/@typescript-eslint/ban-ts-comment + // @ts-expect-error unused var + const result = await executor.call({ + input: `Who is the current president of the United States? What is their current age raised to the second power?`, + }); +}); From 3181144326d070de0923d3556056eff746c702f4 Mon Sep 17 00:00:00 2001 From: Brace Sproul Date: Thu, 12 Sep 2024 09:28:01 -0700 Subject: [PATCH 2/2] Update langchain/src/experimental/plan_and_execute/tests/plan_and_execute.int.test.ts --- .../plan_and_execute/tests/plan_and_execute.int.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/langchain/src/experimental/plan_and_execute/tests/plan_and_execute.int.test.ts b/langchain/src/experimental/plan_and_execute/tests/plan_and_execute.int.test.ts index bc12d26c6979..70c70447b4f1 100644 --- a/langchain/src/experimental/plan_and_execute/tests/plan_and_execute.int.test.ts +++ b/langchain/src/experimental/plan_and_execute/tests/plan_and_execute.int.test.ts @@ -79,9 +79,7 @@ test.skip("Should run agent with no tools", async () => { tools: [], }); - // @eslint-disable-next-line/@typescript-eslint/ban-ts-comment - // @ts-expect-error unused var - const result = await executor.call({ + await executor.call({ input: `Who is the current president of the United States? What is their current age raised to the second power?`, }); });