Skip to content

Commit 76ba977

Browse files
committed
add callbacks to agents
1 parent e9ed663 commit 76ba977

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

packages/components/nodes/agents/MRKLAgentChat/MRKLAgentChat.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { INode, INodeData, INodeParams } from '../../../src/Interface'
1+
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
22
import { initializeAgentExecutorWithOptions, AgentExecutor } from 'langchain/agents'
33
import { getBaseClasses } from '../../../src/utils'
44
import { Tool } from 'langchain/tools'
55
import { BaseLanguageModel } from 'langchain/base_language'
66
import { flatten } from 'lodash'
7+
import { additionalCallbacks } from '../../../src/handler'
78

89
class MRKLAgentChat_Agents implements INode {
910
label: string
@@ -51,9 +52,12 @@ class MRKLAgentChat_Agents implements INode {
5152
return executor
5253
}
5354

54-
async run(nodeData: INodeData, input: string): Promise<string> {
55+
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
5556
const executor = nodeData.instance as AgentExecutor
56-
const result = await executor.call({ input })
57+
58+
const callbacks = await additionalCallbacks(nodeData, options)
59+
60+
const result = await executor.call({ input }, [...callbacks])
5761

5862
return result?.output
5963
}

packages/components/nodes/agents/MRKLAgentLLM/MRKLAgentLLM.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { INode, INodeData, INodeParams } from '../../../src/Interface'
1+
import { ICommonObject, INode, INodeData, INodeParams } from '../../../src/Interface'
22
import { initializeAgentExecutorWithOptions, AgentExecutor } from 'langchain/agents'
33
import { Tool } from 'langchain/tools'
44
import { getBaseClasses } from '../../../src/utils'
55
import { BaseLanguageModel } from 'langchain/base_language'
66
import { flatten } from 'lodash'
7+
import { additionalCallbacks } from '../../../src/handler'
78

89
class MRKLAgentLLM_Agents implements INode {
910
label: string
@@ -52,9 +53,12 @@ class MRKLAgentLLM_Agents implements INode {
5253
return executor
5354
}
5455

55-
async run(nodeData: INodeData, input: string): Promise<string> {
56+
async run(nodeData: INodeData, input: string, options: ICommonObject): Promise<string> {
5657
const executor = nodeData.instance as AgentExecutor
57-
const result = await executor.call({ input })
58+
59+
const callbacks = await additionalCallbacks(nodeData, options)
60+
61+
const result = await executor.call({ input }, [...callbacks])
5862

5963
return result?.output
6064
}

0 commit comments

Comments
 (0)