Why is returnDirect for Custom Tools of multi-action agents not supported? #4631
-
Checked other resources
Commit to Help
Example Codeimport { ChatPromptTemplate } from "@langchain/core/prompts";
import { DynamicTool } from "@langchain/core/tools";
import { ChatOpenAI } from "@langchain/openai";
import { AgentExecutor, createOpenAIFunctionsAgent } from "langchain/agents";
import { pull } from "langchain/hub";
import { customCallbackHandler } from "./callback-handler.js";
const questionOfLife = new DynamicTool({
name: "Question_of_Life",
description:
"Rufe dies auf, um zu erfahren wie die endgültige Frage nach dem Leben, dem Universum und dem ganzen Rest beantwortet wird.",
returnDirect: true,
func: async () => "42"
});
const tools = [questionOfLife];
// Get the prompt to use - you can modify this!
// If you want to see the prompt in full, you can at:
// https://smith.langchain.com/hub/hwchase17/openai-functions-agent
const agentPrompt = await pull<ChatPromptTemplate>("hwchase17/openai-functions-agent");
const agentModel = new ChatOpenAI({
modelName: "gpt-3.5-turbo-1106",
temperature: 0
});
const agent = await createOpenAIFunctionsAgent({
llm: agentModel,
tools,
prompt: agentPrompt
});
const agentExecutor = new AgentExecutor({
agent,
tools,
verbose: false
});
class AgentService {
async askLlm(msg: string) {
return agentExecutor.invoke(
{ input: msg },
{
callbacks: [customCallbackHandler]
}
);
}
}
export const agentService = new AgentService(); DescriptionI am trying to use OpenAI functions in combination with custom tools. For some use cases I want the output of a custom tool not to be parsed again by the LLM. I found the returnDirect option for custom tools in the documentation, but when I use the option, it returns the Error System Info[email protected] |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
Hey @niklas-lohmann, nice to see you back here! Hope you're doing well. The error you're encountering, "Tool with return direct ${tool.name} not supported for multi-action agent," is due to a specific check within the Here's the relevant code snippet from the if (this.agent._agentActionType() === "multi") {
for (const tool of this.tools) {
if (tool.returnDirect) {
throw new Error(
`Tool with return direct ${tool.name} not supported for multi-action agent.`
);
}
}
} This design decision is likely made to ensure that the tools used with multi-action agents adhere to certain expectations regarding their output handling, which might not be compatible with the direct return mechanism. The Unfortunately, this means that if you're using a multi-action agent, you won't be able to use the You can find more details about this in the langchain/src/agents/executor.ts and examples/src/chains/graph_db_return_direct.ts files in the LangChain repository. Sources
|
Beta Was this translation helpful? Give feedback.
-
This sounds like an oversight - could you open an issue or (if you're feeling brave!) take a stab at a PR? |
Beta Was this translation helpful? Give feedback.
-
Hi guys, sorry to reopening this discussion, but I'm still getting this error even after updating:
Am I doing something wrong? const agent = RunnablePassthrough.assign({
agent_scratchpad: x => generatedScratchpad((x.intermediateSteps ?? []) as AgentStep[]),
}).pipe(prompt).pipe(this.verboseRunnable).pipe(currentLLM).pipe(new ProceduresOutputParser())
const agentExecutor = AgentExecutor.fromAgentAndTools({
agent,
tools,
returnIntermediateSteps: true,
maxIterations: 5,
}) that throws the error: langchainjs/langchain/src/agents/executor.ts Line 433 in ed1f3fb |
Beta Was this translation helpful? Give feedback.
-
Still getting this error on langchain==0.2.5 |
Beta Was this translation helpful? Give feedback.
-
Did anyone find a solution? Since functions seem to be deprecated trying to switch to the new tools param. |
Beta Was this translation helpful? Give feedback.
-
Hi, I have a use case - I query for "add a Pizza to cart" the langchain understands the intent is "order" and adds the pizza to the cart! To add the pizza in "addToCart" tool, it queries mongoDb database and returns me list of Pizza to get specific pizza. Now the results from the DB have image, name, price which I want to send it to my bot for displaying in cards but I am just getting a agent response as output with no DB list of Objects which I am sending from Tool.
|
Beta Was this translation helpful? Give feedback.
This sounds like an oversight - could you open an issue or (if you're feeling brave!) take a stab at a PR?