adk-typescript
Version:
TypeScript port of Google's Agent Development Kit (ADK)
84 lines (83 loc) • 3.46 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.AutoFlow = void 0;
/**
* Implementation of AutoFlow.
*/
const agentTransfer = __importStar(require("./agentTransfer"));
const SingleFlow_1 = require("./SingleFlow");
/**
* AutoFlow is SingleFlow with agent transfer capability.
*
* Agent transfer is allowed in the following directions:
*
* 1. from parent to sub-agent;
* 2. from sub-agent to parent;
* 3. from sub-agent to its peer agents;
*
* For peer-agent transfers, it's only enabled when all below conditions are met:
*
* - The parent agent is also of AutoFlow;
* - `allowTransferToPeer` option of this agent is not set to false (default is true).
*
* Depending on the target agent flow type, the transfer may be automatically
* reversed. The condition is as below:
*
* - If the flow type of the transferee agent is also auto, transferee agent will
* remain as the active agent. The transferee agent will respond to the user's
* next message directly.
* - If the flow type of the transferee agent is not auto, the active agent will
* be reversed back to previous agent.
*
* Note: AutoFlow inherits _runOneStepAsync from BaseLlmFlow via SingleFlow, which
* properly handles function calls including transfer_to_agent. This matches the
* Python implementation where both classes inherit this method from BaseLlmFlow.
*/
class AutoFlow extends SingleFlow_1.SingleFlow {
/**
* Creates a new AutoFlow instance with agent transfer capability.
*
* @param additionalRequestProcessors Additional request processors to use
* @param additionalResponseProcessors Additional response processors to use
*/
constructor(additionalRequestProcessors = [], additionalResponseProcessors = []) {
// Pass the additional processors to the parent constructor
super(additionalRequestProcessors, additionalResponseProcessors);
// Add the agent transfer processor to enable transfer capabilities
this.requestProcessors.push(agentTransfer.requestProcessor);
}
}
exports.AutoFlow = AutoFlow;