mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
@@ -167,6 +167,7 @@ export interface IUsedTool {
|
||||
toolInput: object
|
||||
toolOutput: string | object
|
||||
sourceDocuments?: ICommonObject[]
|
||||
error?: string
|
||||
}
|
||||
|
||||
export interface IMultiAgentNode {
|
||||
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
} from 'langchain/agents'
|
||||
import { formatLogToString } from 'langchain/agents/format_scratchpad/log'
|
||||
import { IUsedTool } from './Interface'
|
||||
import { getErrorMessage } from './error'
|
||||
|
||||
export const SOURCE_DOCUMENTS_PREFIX = '\n\n----FLOWISE_SOURCE_DOCUMENTS----\n\n'
|
||||
export const ARTIFACTS_PREFIX = '\n\n----FLOWISE_ARTIFACTS----\n\n'
|
||||
@@ -463,7 +464,21 @@ export class AgentExecutor extends BaseChain<ChainValues, AgentExecutorOutput> {
|
||||
throw e
|
||||
}
|
||||
observation = await new ExceptionTool().call(observation, runManager?.getChild())
|
||||
usedTools.push({
|
||||
tool: tool.name,
|
||||
toolInput: action.toolInput as any,
|
||||
toolOutput: '',
|
||||
error: getErrorMessage(e)
|
||||
})
|
||||
return { action, observation: observation ?? '' }
|
||||
} else {
|
||||
usedTools.push({
|
||||
tool: tool.name,
|
||||
toolInput: action.toolInput as any,
|
||||
toolOutput: '',
|
||||
error: getErrorMessage(e)
|
||||
})
|
||||
return { action, observation: getErrorMessage(e) }
|
||||
}
|
||||
}
|
||||
if (typeof observation === 'string' && observation.includes(SOURCE_DOCUMENTS_PREFIX)) {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
type ErrorWithMessage = {
|
||||
message: string
|
||||
}
|
||||
|
||||
const isErrorWithMessage = (error: unknown): error is ErrorWithMessage => {
|
||||
return (
|
||||
typeof error === 'object' && error !== null && 'message' in error && typeof (error as Record<string, unknown>).message === 'string'
|
||||
)
|
||||
}
|
||||
|
||||
const toErrorWithMessage = (maybeError: unknown): ErrorWithMessage => {
|
||||
if (isErrorWithMessage(maybeError)) return maybeError
|
||||
|
||||
try {
|
||||
return new Error(JSON.stringify(maybeError))
|
||||
} catch {
|
||||
// fallback in case there's an error stringifying the maybeError
|
||||
// like with circular references for example.
|
||||
return new Error(String(maybeError))
|
||||
}
|
||||
}
|
||||
|
||||
export const getErrorMessage = (error: unknown) => {
|
||||
return toErrorWithMessage(error).message
|
||||
}
|
||||
Reference in New Issue
Block a user