UNPKG

@mxlabs/okxnotify

Version:

OKX notification package with Feishu, Cloudflare Workers, and Gemini AI agent integration - Complete bundle

48 lines (47 loc) 1.74 kB
/** * 搭建基于EventEmmiter的 Agent 基类 , 通过事件驱动的方式,实现 Agent 的各个阶段的生命周期管理 */ import { ToolCall } from '@langchain/core/dist/messages/tool'; import { BaseLanguageModelInput } from '@langchain/core/language_models/base'; import { AIMessageChunk } from '@langchain/core/messages'; import { Runnable } from '@langchain/core/runnables'; import { DynamicStructuredTool } from '@langchain/core/tools'; import { ChatGoogleGenerativeAI, GoogleGenerativeAIChatCallOptions } from '@langchain/google-genai'; import { EventEmitter } from 'events'; export interface EventResponse { tool: string; args: { symbol: string; userId: string; } & Record<string, any>; } export default abstract class Agent extends EventEmitter { protected tools: DynamicStructuredTool[]; protected modelWithTools?: Runnable<BaseLanguageModelInput, AIMessageChunk, GoogleGenerativeAIChatCallOptions>; protected model?: ChatGoogleGenerativeAI; constructor(); /** * 抽象方法,用于处理用户输入 * @param userInput 用户输入的文本 * @returns Promise<ToolResponse> 处理结果 */ abstract invokeMessage(userInput: string): Promise<{ tool: string; result: string; }[]>; /** * 重写监听事件返回数据 * @param event 事件名称 * @param listener 事件监听器 * @returns this */ on(event: string, listener: (...args: EventResponse[]) => void): this; /** * 处理工具调用 * @param toolCalls 工具调用 */ processToolCall(toolCalls: ToolCall[], extraArgs?: Record<string, any>): Promise<{ tool: string; result: string; }[]>; }