@@ -24,7 +24,7 @@ import {
24
24
IUsedTool ,
25
25
IVisionChatModal
26
26
} from '../../../src/Interface'
27
- import { ConsoleCallbackHandler , CustomChainHandler , additionalCallbacks } from '../../../src/handler'
27
+ import { ConsoleCallbackHandler , CustomChainHandler , CustomStreamingHandler , additionalCallbacks } from '../../../src/handler'
28
28
import { AgentExecutor , ToolCallingAgentOutputParser } from '../../../src/agents'
29
29
import { Moderation , checkInputs , streamResponse } from '../../moderation/Moderation'
30
30
import { formatResponse } from '../../outputparsers/OutputParserHelpers'
@@ -101,6 +101,15 @@ class ToolAgent_Agents implements INode {
101
101
type : 'number' ,
102
102
optional : true ,
103
103
additionalParams : true
104
+ } ,
105
+ {
106
+ label : 'Enable Detailed Streaming' ,
107
+ name : 'enableDetailedStreaming' ,
108
+ type : 'boolean' ,
109
+ default : false ,
110
+ description : 'Stream detailed intermediate steps during agent execution' ,
111
+ optional : true ,
112
+ additionalParams : true
104
113
}
105
114
]
106
115
this . sessionId = fields ?. sessionId
@@ -113,6 +122,7 @@ class ToolAgent_Agents implements INode {
113
122
async run ( nodeData : INodeData , input : string , options : ICommonObject ) : Promise < string | ICommonObject > {
114
123
const memory = nodeData . inputs ?. memory as FlowiseMemory
115
124
const moderations = nodeData . inputs ?. inputModeration as Moderation [ ]
125
+ const enableDetailedStreaming = nodeData . inputs ?. enableDetailedStreaming as boolean
116
126
117
127
const shouldStreamResponse = options . shouldStreamResponse
118
128
const sseStreamer : IServerSideEventStreamer = options . sseStreamer as IServerSideEventStreamer
@@ -136,14 +146,28 @@ class ToolAgent_Agents implements INode {
136
146
const loggerHandler = new ConsoleCallbackHandler ( options . logger )
137
147
const callbacks = await additionalCallbacks ( nodeData , options )
138
148
149
+ // Add custom streaming handler if detailed streaming is enabled
150
+ let customStreamingHandler = null
151
+
152
+ if ( enableDetailedStreaming && shouldStreamResponse ) {
153
+ customStreamingHandler = new CustomStreamingHandler ( sseStreamer , chatId )
154
+ }
155
+
139
156
let res : ChainValues = { }
140
157
let sourceDocuments : ICommonObject [ ] = [ ]
141
158
let usedTools : IUsedTool [ ] = [ ]
142
159
let artifacts = [ ]
143
160
144
161
if ( shouldStreamResponse ) {
145
162
const handler = new CustomChainHandler ( sseStreamer , chatId )
146
- res = await executor . invoke ( { input } , { callbacks : [ loggerHandler , handler , ...callbacks ] } )
163
+ const allCallbacks = [ loggerHandler , handler , ...callbacks ]
164
+
165
+ // Add detailed streaming handler if enabled
166
+ if ( enableDetailedStreaming && customStreamingHandler ) {
167
+ allCallbacks . push ( customStreamingHandler )
168
+ }
169
+
170
+ res = await executor . invoke ( { input } , { callbacks : allCallbacks } )
147
171
if ( res . sourceDocuments ) {
148
172
if ( sseStreamer ) {
149
173
sseStreamer . streamSourceDocumentsEvent ( chatId , flatten ( res . sourceDocuments ) )
@@ -174,7 +198,14 @@ class ToolAgent_Agents implements INode {
174
198
}
175
199
}
176
200
} else {
177
- res = await executor . invoke ( { input } , { callbacks : [ loggerHandler , ...callbacks ] } )
201
+ const allCallbacks = [ loggerHandler , ...callbacks ]
202
+
203
+ // Add detailed streaming handler if enabled
204
+ if ( enableDetailedStreaming && customStreamingHandler ) {
205
+ allCallbacks . push ( customStreamingHandler )
206
+ }
207
+
208
+ res = await executor . invoke ( { input } , { callbacks : allCallbacks } )
178
209
if ( res . sourceDocuments ) {
179
210
sourceDocuments = res . sourceDocuments
180
211
}
0 commit comments