mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-29 05:01:10 +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 }
|
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 {
|
try {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
let toolOutput = await selectedTool.call(toolCall.args, { signal: abortController?.signal }, undefined, flowConfig)
|
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
|
// Extract source documents if present
|
||||||
if (typeof toolOutput === 'string' && toolOutput.includes(SOURCE_DOCUMENTS_PREFIX)) {
|
if (typeof toolOutput === 'string' && toolOutput.includes(SOURCE_DOCUMENTS_PREFIX)) {
|
||||||
const [output, docs] = toolOutput.split(SOURCE_DOCUMENTS_PREFIX)
|
const [output, docs] = toolOutput.split(SOURCE_DOCUMENTS_PREFIX)
|
||||||
@@ -1459,6 +1468,10 @@ class Agent_Agentflow implements INode {
|
|||||||
toolOutput
|
toolOutput
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (options.analyticHandlers && toolIds) {
|
||||||
|
await options.analyticHandlers.onToolEnd(toolIds, e)
|
||||||
|
}
|
||||||
|
|
||||||
console.error('Error invoking tool:', e)
|
console.error('Error invoking tool:', e)
|
||||||
usedTools.push({
|
usedTools.push({
|
||||||
tool: selectedTool.name,
|
tool: selectedTool.name,
|
||||||
@@ -1650,10 +1663,19 @@ class Agent_Agentflow implements INode {
|
|||||||
toolsInstance = toolsInstance.filter((tool) => tool.name !== toolCall.name)
|
toolsInstance = toolsInstance.filter((tool) => tool.name !== toolCall.name)
|
||||||
}
|
}
|
||||||
if (humanInput.type === 'proceed') {
|
if (humanInput.type === 'proceed') {
|
||||||
|
let toolIds: ICommonObject | undefined
|
||||||
|
if (options.analyticHandlers) {
|
||||||
|
toolIds = await options.analyticHandlers.onToolStart(toolCall.name, toolCall.args, options.parentTraceIds)
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
let toolOutput = await selectedTool.call(toolCall.args, { signal: abortController?.signal }, undefined, flowConfig)
|
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
|
// Extract source documents if present
|
||||||
if (typeof toolOutput === 'string' && toolOutput.includes(SOURCE_DOCUMENTS_PREFIX)) {
|
if (typeof toolOutput === 'string' && toolOutput.includes(SOURCE_DOCUMENTS_PREFIX)) {
|
||||||
const [output, docs] = toolOutput.split(SOURCE_DOCUMENTS_PREFIX)
|
const [output, docs] = toolOutput.split(SOURCE_DOCUMENTS_PREFIX)
|
||||||
@@ -1708,6 +1730,10 @@ class Agent_Agentflow implements INode {
|
|||||||
toolOutput
|
toolOutput
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
if (options.analyticHandlers && toolIds) {
|
||||||
|
await options.analyticHandlers.onToolEnd(toolIds, e)
|
||||||
|
}
|
||||||
|
|
||||||
console.error('Error invoking tool:', e)
|
console.error('Error invoking tool:', e)
|
||||||
usedTools.push({
|
usedTools.push({
|
||||||
tool: selectedTool.name,
|
tool: selectedTool.name,
|
||||||
|
|||||||
@@ -1503,7 +1503,14 @@ export const executeAgentFlow = async ({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (chatflow.analytic) {
|
if (chatflow.analytic) {
|
||||||
analyticHandlers = AnalyticHandler.getInstance({ inputs: {} } as any, {
|
// Override config analytics
|
||||||
|
let analyticInputs: ICommonObject = {}
|
||||||
|
if (overrideConfig?.analytics && Object.keys(overrideConfig.analytics).length > 0) {
|
||||||
|
analyticInputs = {
|
||||||
|
...overrideConfig.analytics
|
||||||
|
}
|
||||||
|
}
|
||||||
|
analyticHandlers = AnalyticHandler.getInstance({ inputs: { analytics: analyticInputs } } as any, {
|
||||||
orgId,
|
orgId,
|
||||||
workspaceId,
|
workspaceId,
|
||||||
appDataSource,
|
appDataSource,
|
||||||
|
|||||||
Reference in New Issue
Block a user