mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
Bugfix/Overrideconfig Analytics in AgentflowV2 (#4599)
* fix(utils/buildAgentflow): enhance analytic handler configuration to support overrides * fix(agentflow): integrate analytic handlers for tool execution tracking
This commit is contained in:
@@ -1401,10 +1401,19 @@ class Agent_Agentflow implements INode {
|
||||
return { response, usedTools, sourceDocuments, artifacts, totalTokens, isWaitingForHumanInput: true }
|
||||
}
|
||||
|
||||
let toolIds: ICommonObject | undefined
|
||||
if (options.analyticHandlers) {
|
||||
toolIds = await options.analyticHandlers.onToolStart(toolCall.name, toolCall.args, options.parentTraceIds)
|
||||
}
|
||||
|
||||
try {
|
||||
//@ts-ignore
|
||||
let toolOutput = await selectedTool.call(toolCall.args, { signal: abortController?.signal }, undefined, flowConfig)
|
||||
|
||||
if (options.analyticHandlers && toolIds) {
|
||||
await options.analyticHandlers.onToolEnd(toolIds, toolOutput)
|
||||
}
|
||||
|
||||
// Extract source documents if present
|
||||
if (typeof toolOutput === 'string' && toolOutput.includes(SOURCE_DOCUMENTS_PREFIX)) {
|
||||
const [output, docs] = toolOutput.split(SOURCE_DOCUMENTS_PREFIX)
|
||||
@@ -1459,6 +1468,10 @@ class Agent_Agentflow implements INode {
|
||||
toolOutput
|
||||
})
|
||||
} catch (e) {
|
||||
if (options.analyticHandlers && toolIds) {
|
||||
await options.analyticHandlers.onToolEnd(toolIds, e)
|
||||
}
|
||||
|
||||
console.error('Error invoking tool:', e)
|
||||
usedTools.push({
|
||||
tool: selectedTool.name,
|
||||
@@ -1650,10 +1663,19 @@ class Agent_Agentflow implements INode {
|
||||
toolsInstance = toolsInstance.filter((tool) => tool.name !== toolCall.name)
|
||||
}
|
||||
if (humanInput.type === 'proceed') {
|
||||
let toolIds: ICommonObject | undefined
|
||||
if (options.analyticHandlers) {
|
||||
toolIds = await options.analyticHandlers.onToolStart(toolCall.name, toolCall.args, options.parentTraceIds)
|
||||
}
|
||||
|
||||
try {
|
||||
//@ts-ignore
|
||||
let toolOutput = await selectedTool.call(toolCall.args, { signal: abortController?.signal }, undefined, flowConfig)
|
||||
|
||||
if (options.analyticHandlers && toolIds) {
|
||||
await options.analyticHandlers.onToolEnd(toolIds, toolOutput)
|
||||
}
|
||||
|
||||
// Extract source documents if present
|
||||
if (typeof toolOutput === 'string' && toolOutput.includes(SOURCE_DOCUMENTS_PREFIX)) {
|
||||
const [output, docs] = toolOutput.split(SOURCE_DOCUMENTS_PREFIX)
|
||||
@@ -1708,6 +1730,10 @@ class Agent_Agentflow implements INode {
|
||||
toolOutput
|
||||
})
|
||||
} catch (e) {
|
||||
if (options.analyticHandlers && toolIds) {
|
||||
await options.analyticHandlers.onToolEnd(toolIds, e)
|
||||
}
|
||||
|
||||
console.error('Error invoking tool:', e)
|
||||
usedTools.push({
|
||||
tool: selectedTool.name,
|
||||
|
||||
Reference in New Issue
Block a user