taskforce-aiagent
Version:
TaskForce is a modular, open-source, production-ready TypeScript agent framework for orchestrating AI agents, LLM-powered autonomous agents, task pipelines, dynamic toolchains, RAG workflows and memory/retrieval systems.
55 lines (54 loc) • 1.82 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkDelegationValidity = checkDelegationValidity;
exports.updateDelegationChain = updateDelegationChain;
exports.checkDelegationScore = checkDelegationScore;
const MAX_DELEGATION_HOPS = 5;
function checkDelegationValidity(agent, task) {
const chain = task.executionContext?.delegationChain || [];
if (chain.includes(agent.name)) {
return {
canDelegate: false,
reason: `cycle_detected: ${agent.name} already in delegationChain`,
};
}
if (chain.length >= MAX_DELEGATION_HOPS) {
return {
canDelegate: false,
reason: `max_delegation_hops_exceeded (${MAX_DELEGATION_HOPS})`,
};
}
return { canDelegate: true };
}
function updateDelegationChain(task, agent) {
if (!task.executionContext)
task.executionContext = {};
if (!Array.isArray(task.executionContext.delegationChain)) {
task.executionContext.delegationChain = [];
}
task.executionContext.delegationChain.push(agent.name);
}
function checkDelegationScore(output) {
const cleaned = output.trim().toLowerCase();
let score = 10;
if (cleaned.startsWith("delegate(") && cleaned.length < 100) {
score = 3;
return {
isWeak: true,
reason: "Output contains only delegation without elaboration.",
score,
};
}
if (cleaned.includes("delegate(") &&
!cleaned.includes("because") &&
!cleaned.includes("therefore") &&
cleaned.length < 150) {
score = 5;
return {
isWeak: true,
reason: "Delegation present but lacks reasoning or explanation.",
score,
};
}
return { isWeak: false, score };
}