Skip to Content
📖 Guide Documents📡 WebSocket ProtocolRemote Procedure Call

@agentica/rpc

RPC module of Agentica for WebSocket Communication.

@agentica/core is the simplest Agentic AI library specialized in LLM Function Calling, and @agentica/rpc is an RPC (Remote Procedure Call) wrapper module of it. If you combine the RPC wrapper module with TGrid, you can develop the WebSocket AI Chatbot.

And if you are considering to develop AI chatbot application development, WebSocket protocol is essentially required. Chatting application is basically a two-way communication. AI chatbot is also a two-way chat between an user and an assistant, based on events. Therefore, it cannot be a one-way communication HTTP Restful API, and a two-way protocol such as WebSocket is required.

However, don’t be afraid of WebSocket application development. Below is the example codes of WebSocket application development utilizing @agentica/rpc in both client and server side. Look at the example codes, and feel how easy and type-safe it is.

client/src/main.ts
import { IAgenticaRpcListener, IAgenticaRpcService } from "@agentica/rpc"; import { Driver, WebSocketConnector } from "tgrid"; const connector: WebSocketConnector< null, IAgenticaRpcListener<"chatgpt">, IAgenticaRpcService<"chatgpt"> > = new WebSocketConnector(null, { text: async (evt) => { console.log(evt.role, evt.text); }, describe: async (evt) => { console.log("describer", evt.text); }, }); await connector.connect("ws://localhost:3001"); const driver: Driver<IAgenticaRpcService<"chatgpt">> = connector.getDriver(); await driver.conversate("Hello, what you can do?");

Setup

NestJS Server

Terminal
npm install @agentica/core @samchon/openapi npm install @nestjs/common @nestjs/core @nestjs/platform-express npm install @agentica/rpc tgrid npm install -D nestia npx nestia setup

NodeJS Server

Terminal
npm install @agentica/core @samchon/openapi typia npm install @agentica/rpc tgrid npx typia setup

Client Application

Terminal
npm install @agentica/rpc tgrid

Remote Procedure Call

WebSocket protocol with RPC paradigm for AI chatbot.

@agentica/rpc supports WebSocket protocol that is utilizing TGrid and its RPC (Remote Procedure Call) paradigm for easy and type safe development. In the RPC paradigm, client application can call a function of IAgenticaRpcService remotely as if it were its own object.

Internally, the RPC has composed with three elements; Communicator, Provider and Driver. The first Communicator takes a responsibility of (WebSocket) network communication. The next Provider means an object providing to the remote system for RPC, and Driver is a proxy instance realizing the RPC to the remote provided Provider instance.

For example, below client application code is calling IAgenticaRpcService.conversate() function remotely through the Driver<IAgenticaRpcService> typed instance. In that case, IAgenticaRpcService is the Provider instance from server to client. And WebSocketConnector is the communicator taking responsibility of WebSocket communication.

client/src/main.ts
import { IAgenticaRpcListener, IAgenticaRpcService } from "@agentica/rpc"; import { Driver, WebSocketConnector } from "tgrid"; const connector: WebSocketConnector< null, IAgenticaRpcListener<"chatgpt">, IAgenticaRpcService<"chatgpt"> > = new WebSocketConnector(null, { text: async (evt) => { console.log(evt.role, evt.text); }, describe: async (evt) => { console.log("describer", evt.text); }, }); await connector.connect("ws://localhost:3001"); const driver: Driver<IAgenticaRpcService<"chatgpt">> = connector.getDriver(); await driver.conversate("Hello, what you can do?");
Last updated on