Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,33 @@ class ConditionAgent_Agentflow implements INode {
}
}

// Find the first exact match
const matchedScenarioIndex = _conditionAgentScenarios.findIndex(
// try exact match first
let matchedScenarioIndex = _conditionAgentScenarios.findIndex(
(scenario) => calledOutputName.toLowerCase() === scenario.scenario.toLowerCase()
)

// fallback: check if LLM returned a partial/abbreviated scenario name
if (matchedScenarioIndex === -1) {
matchedScenarioIndex = _conditionAgentScenarios.findIndex(
(scenario) => scenario.scenario.toLowerCase().startsWith(calledOutputName.toLowerCase().trim())
)
}

// further fallback: substring match in either direction
if (matchedScenarioIndex === -1) {
matchedScenarioIndex = _conditionAgentScenarios.findIndex(
(scenario) =>
scenario.scenario.toLowerCase().includes(calledOutputName.toLowerCase().trim()) ||
calledOutputName.toLowerCase().trim().includes(scenario.scenario.toLowerCase())
)
}
Comment thread
HenryHengZJ marked this conversation as resolved.
Outdated

// last resort: if still no match, use the last scenario as an "else" branch
// this prevents the flow from silently dying with no response
if (matchedScenarioIndex === -1) {
matchedScenarioIndex = _conditionAgentScenarios.length - 1
}

const conditions = _conditionAgentScenarios.map((scenario, index) => {
return {
output: scenario.scenario,
Expand Down
8 changes: 8 additions & 0 deletions packages/server/src/utils/buildAgentflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,14 @@ async function determineNodesToIgnore(
if (isDecisionNode && result.output?.conditions) {
const outputConditions: ICondition[] = result.output.conditions

// safety net: if no conditions were fulfilled, don't ignore ALL children
// treat the last condition as an else/default fallback
const anyFulfilled = outputConditions.some((c: any) => c.isFulfilled === true)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The type of c can be inferred from outputConditions which is ICondition[]. Explicitly typing it as any is unnecessary and reduces type-safety.

        const anyFulfilled = outputConditions.some((c) => c.isFulfilled === true)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah removed those, inference handles it fine since outputConditions is already typed as ICondition[]

if (!anyFulfilled && outputConditions.length > 0) {
// mark the last condition as fulfilled so at least one branch executes
outputConditions[outputConditions.length - 1].isFulfilled = true
}

// Find indexes of unfulfilled conditions
const unfulfilledIndexes = outputConditions
.map((condition: any, index: number) =>
Expand Down