UNPKG

@agentica/rpc

Version:

Agentic AI Library specialized in LLM Function Calling

79 lines (78 loc) 2.35 kB
import type { Agentica, IAgenticaController } from "@agentica/core"; import type { IAgenticaRpcListener } from "./IAgenticaRpcListener"; import type { IAgenticaRpcService } from "./IAgenticaRpcService"; /** * RPC service for the {@link Agentica}. * * `AgenticaRpcService` is class defining an AI agent service * provided from the server to clients through the RPC (Remote Procedure Call) * paradigm in the websocket protocol. * * Client connecting to the `AgenticaRpcService` providing websocket server * will call the {@link conversate} function remotely through its basic * interface type {@link IAgenticaRpcService} with the RPC paradigm. * * Also, the client provides the {@link IAgenticaRpcListener} type to the * server, so that `AgenticaRpcService` will remotely call the * {@link IAgenticaRpcListener listener}'s functions internally. * * You can open the WebSocket server of the AI agent like below: * * ```typescript * import { * IAgenticaRpcListener, * IAgenticaRpcService, * Agentica, * AgenticaRpcService, * } from "@agentica/core"; * import { WebSocketServer } from "tgrid"; * * const server: WebSocketServer< * null, * IAgenticaRpcService, * IAgenticaRpcListener * > = new WebSocketServer(); * await server.open(3001, async (acceptor) => { * await acceptor.accept( * new AgenticaRpcService({ * agent: new Agentica({ ... }), * listener: acceptor.getDriver(), * }), * ); * }); * ``` * * @author Samchon */ export declare class AgenticaRpcService implements IAgenticaRpcService { private readonly props; /** * Initializer Constructor. * * @param props Properties to construct the RPC service */ constructor(props: AgenticaRpcService.IProps); /** * @inheritDoc */ conversate(content: string | Parameters<typeof Agentica.prototype.conversate>[0]): Promise<void>; /** * @inheritDoc */ getControllers(): Promise<IAgenticaController[]>; } export declare namespace AgenticaRpcService { /** * Properties of the {@link AgenticaRpcService}. */ interface IProps { /** * Target agent to provide as RPC service. */ agent: Agentica; /** * Listener to be binded on the agent. */ listener: IAgenticaRpcListener; } }