Step 380: rejection rerouting feedback loop

This commit is contained in:
Bill
2026-02-16 12:36:36 -07:00
parent e2dd2b1d3a
commit b99957e2fc
7 changed files with 475 additions and 4 deletions

View File

@@ -182,6 +182,36 @@ public:
return decisions;
}
RoutingDecision routeWithHistory(const WorkItem& item, int rejectionCount) const {
RoutingDecision base = route(item);
if (rejectionCount <= 0) return base;
// Escalate one level per rejection attempt, based on the last rejected
// worker. This prevents skipping stages (e.g. slm -> human).
std::string priorWorker = base.workerType;
if (!item.rejectionHistory.empty() &&
!item.rejectionHistory.back().workerType.empty()) {
priorWorker = item.rejectionHistory.back().workerType;
}
if (priorWorker == "human") {
base.workerType = "human";
base.reviewRequired = true;
base.reasoning += " | remains human after rejection";
base.agentRole = agentRoleForWorker(base.workerType);
return base;
}
base.workerType = escalateWorker(priorWorker);
base.contextWidth = widenedContext(base.contextWidth, 1);
base.contextBudgetTokens = estimateContextBudget(base.contextWidth);
base.reviewRequired = true;
base.confidence = std::max(0.4f, base.confidence - 0.10f);
base.reasoning += " | escalated after rejection history";
base.agentRole = agentRoleForWorker(base.workerType);
return base;
}
// Route and apply: updates the WorkItem's workerType + reviewRequired
void routeAndApply(WorkItem& item) const {
auto decision = route(item);
@@ -189,4 +219,24 @@ public:
item.reviewRequired = decision.reviewRequired;
item.contextWidth = decision.contextWidth;
}
private:
static std::string escalateWorker(const std::string& workerType) {
if (workerType == "deterministic" || workerType == "template") return "slm";
if (workerType == "slm") return "llm";
return "human";
}
static std::string widenedContext(const std::string& ctx, int rejectionCount) {
std::vector<std::string> order = {"local", "file", "project", "cross-project"};
int idx = 0;
for (size_t i = 0; i < order.size(); ++i) {
if (order[i] == ctx) {
idx = static_cast<int>(i);
break;
}
}
idx = std::min(3, idx + rejectionCount);
return order[idx];
}
};