🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis
Socket
Book a DemoInstallSign in
Socket

@agentica/rpc

Package Overview
Dependencies
Maintainers
1
Versions
120
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@agentica/rpc

Agentic AI Library specialized in LLM Function Calling

Source
npmnpm
Version
0.7.0
Version published
Weekly downloads
82
-81.45%
Maintainers
1
Weekly downloads
 
Created
Source

@agentica/rpc

agentica-conceptual-diagram

GitHub license npm version Downloads Build Status

RPC module of Agentica for WebSocket Communication

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

import { IAgenticaRpcListener, IAgenticaRpcService } from "@agentica/rpc";
import { Driver, WebSocketConnector } from "tgrid";

const connector: WebSocketConnector<
  null,
  IAgenticaRpcListener,
  IAgenticaRpcService
> = 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> = connector.getDriver();
await driver.conversate("Hello, what you can do?");

How to use

Setup

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

Install @agentica/rpc with its dependent libraries.

Note that, you have to install not only @agentica/core and @agentica/rpc, but also @samchon/openapi, typia and tgrid too.

@samchon/openapi is an OpenAPI specification library which can convert Swagger/OpenAPI document to LLM function calling schema. And typia is a transformer (compiler) library which can compose LLM function calling schema from a TypeScript class type. And then tgrid is an RPC (REmote Procedure Call) framework supporting the websocket protocol.

By the way, as typia is a transformer library analyzing TypeScript source code in the compilation level, it needs additional setup command npx typia setup. Also, if your client (frontend) application is not using the standard TypeScript compiler (not tsc), you have to setup @ryoppippi/unplugin-typia too.

Server Application

import { Agentica } from "@agentica/core";
import {
  AgenticaRpcService,
  IAgenticaRpcListener,
  IAgenticaRpcService,
} from "@agentica/rpc";
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(),
    }),
  );
});

When developing backend server, wrap Agentica to AgenticaRpcService.

If you're developing WebSocket protocol backend server, create a new Agentica instance, and wrap it to the AgenticaRpcService class. And then open the websocket server like above code. The WebSocket server will call the client functions of the IAgenticaRpcListener remotely.

Client Application

import { IAgenticaRpcListener, IAgenticaRpcService } from "@agentica/rpc";
import { Driver, WebSocketConnector } from "tgrid";

const connector: WebSocketConnector<
  null,
  IAgenticaRpcListener,
  IAgenticaRpcService
> = 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> = connector.getDriver();
await driver.conversate("Hello, what you can do?");

When developing frontend application, define IAgenticaRpcListener instance.

Otherwise you're developing WebSocket protocol client application, connect to the websocket backend server with its URL address, and provide IAgenticaRpcListener instance for event listening.

And then call the backend server's function IAgenticaRpcService.conversate() remotely through the Driver<IAgenticaRpcService> wrapping. The backend server will call your IAgenticaRpcListener functions remotely through the RPC paradigm.

Keywords

openai

FAQs

Package last updated on 24 Feb 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts