Bugfix/Avoid passing runnable assign when worker agent has no input variables (#2550)
avoid passing runnable assign when worker agent has no input variables
This commit is contained in:
parent
e15e6fafdc
commit
8c66d2c735
|
|
@ -199,19 +199,33 @@ async function createAgent(
|
||||||
}
|
}
|
||||||
const modelWithTools = llm.bindTools(tools)
|
const modelWithTools = llm.bindTools(tools)
|
||||||
|
|
||||||
const agent = RunnableSequence.from([
|
let agent
|
||||||
RunnablePassthrough.assign({
|
|
||||||
//@ts-ignore
|
if (!workerInputVariablesValues || !Object.keys(workerInputVariablesValues).length) {
|
||||||
agent_scratchpad: (input: { steps: ToolsAgentStep[] }) => formatToOpenAIToolMessages(input.steps)
|
agent = RunnableSequence.from([
|
||||||
}),
|
RunnablePassthrough.assign({
|
||||||
RunnablePassthrough.assign(transformObjectPropertyToFunction(workerInputVariablesValues)),
|
//@ts-ignore
|
||||||
prompt,
|
agent_scratchpad: (input: { steps: ToolsAgentStep[] }) => formatToOpenAIToolMessages(input.steps)
|
||||||
modelWithTools,
|
}),
|
||||||
new ToolCallingAgentOutputParser()
|
prompt,
|
||||||
])
|
modelWithTools,
|
||||||
|
new ToolCallingAgentOutputParser()
|
||||||
|
])
|
||||||
|
} else {
|
||||||
|
agent = RunnableSequence.from([
|
||||||
|
RunnablePassthrough.assign({
|
||||||
|
//@ts-ignore
|
||||||
|
agent_scratchpad: (input: { steps: ToolsAgentStep[] }) => formatToOpenAIToolMessages(input.steps)
|
||||||
|
}),
|
||||||
|
RunnablePassthrough.assign(transformObjectPropertyToFunction(workerInputVariablesValues)),
|
||||||
|
prompt,
|
||||||
|
modelWithTools,
|
||||||
|
new ToolCallingAgentOutputParser()
|
||||||
|
])
|
||||||
|
}
|
||||||
|
|
||||||
const executor = AgentExecutor.fromAgentAndTools({
|
const executor = AgentExecutor.fromAgentAndTools({
|
||||||
agent: agent,
|
agent,
|
||||||
tools,
|
tools,
|
||||||
sessionId: flowObj?.sessionId,
|
sessionId: flowObj?.sessionId,
|
||||||
chatId: flowObj?.chatId,
|
chatId: flowObj?.chatId,
|
||||||
|
|
@ -233,12 +247,19 @@ async function createAgent(
|
||||||
const msg = HumanMessagePromptTemplate.fromTemplate([...multiModalMessageContent])
|
const msg = HumanMessagePromptTemplate.fromTemplate([...multiModalMessageContent])
|
||||||
prompt.promptMessages.splice(1, 0, msg)
|
prompt.promptMessages.splice(1, 0, msg)
|
||||||
}
|
}
|
||||||
const conversationChain = RunnableSequence.from([
|
|
||||||
RunnablePassthrough.assign(transformObjectPropertyToFunction(workerInputVariablesValues)),
|
let conversationChain
|
||||||
prompt,
|
|
||||||
llm,
|
if (!workerInputVariablesValues || !Object.keys(workerInputVariablesValues).length) {
|
||||||
new StringOutputParser()
|
conversationChain = RunnableSequence.from([prompt, llm, new StringOutputParser()])
|
||||||
])
|
} else {
|
||||||
|
conversationChain = RunnableSequence.from([
|
||||||
|
RunnablePassthrough.assign(transformObjectPropertyToFunction(workerInputVariablesValues)),
|
||||||
|
prompt,
|
||||||
|
llm,
|
||||||
|
new StringOutputParser()
|
||||||
|
])
|
||||||
|
}
|
||||||
return conversationChain
|
return conversationChain
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -256,6 +277,7 @@ async function agentNode(
|
||||||
if (abortControllerSignal.signal.aborted) {
|
if (abortControllerSignal.signal.aborted) {
|
||||||
throw new Error('Aborted!')
|
throw new Error('Aborted!')
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await agent.invoke({ ...state, signal: abortControllerSignal.signal }, config)
|
const result = await agent.invoke({ ...state, signal: abortControllerSignal.signal }, config)
|
||||||
const additional_kwargs: ICommonObject = {}
|
const additional_kwargs: ICommonObject = {}
|
||||||
if (result.usedTools) {
|
if (result.usedTools) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue