Skip to content

Commit

Permalink
fix(langchain): Prevent exception when using plan & execute agent wit…
Browse files Browse the repository at this point in the history
…h no tools (#6744)

Co-authored-by: Brace Sproul <[email protected]>
  • Loading branch information
OlegIvaniv and bracesproul authored Sep 12, 2024
1 parent d5ba68d commit 1a7e93f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,19 @@ 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: [],
});

await executor.call({
input: `Who is the current president of the United States? What is their current age raised to the second power?`,
});
});

0 comments on commit 1a7e93f

Please sign in to comment.