UNPKG

adk-typescript

Version:

TypeScript port of Google's Agent Development Kit (ADK)

74 lines (73 loc) 2.27 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.RemoteAgent = void 0; const axios_1 = __importDefault(require("axios")); const Event_1 = require("../events/Event"); const BaseAgent_1 = require("./BaseAgent"); /** * Remote agent that delegates processing to an external service. * Experimental, do not use. */ class RemoteAgent extends BaseAgent_1.BaseAgent { /** * Creates a new RemoteAgent. * * @param name The name of the agent * @param options Options for the agent */ constructor(name, options) { super(name, options); this.url = options.url; } /** * @inheritdoc */ async *runAsyncImpl(ctx) { const data = { invocation_id: ctx.invocationId, session: ctx.session, }; const response = await axios_1.default.post(this.url, JSON.stringify(data), { headers: { 'Content-Type': 'application/json', }, timeout: 120000, // 120 seconds (same as Python's 120 timeout) }); if (response.status !== 200) { throw new Error(`Remote agent request failed with status: ${response.status}`); } for (const eventData of response.data) { const event = new Event_1.Event({ ...eventData, author: this.name, }); yield event; } } /** * @inheritdoc */ async *runLiveImpl(ctx) { // For live implementation, we simply delegate to the async implementation yield* this.runAsyncImpl(ctx); } /** * @inheritdoc */ setUserContent(content, invocationContext) { // Remote agent doesn't need to store user content locally // It will be sent as part of the session data } /** * Override the addSubAgent method to prevent adding sub-agents. * Sub-agents are disabled in RemoteAgent. */ addSubAgent(agent) { console.warn('Sub-agents are disabled in RemoteAgent'); return this; } } exports.RemoteAgent = RemoteAgent;