[Agentica] 每个 TypeScript 开发人员都是 AI 开发人员

2025-06-07

[Agentica] 每个 TypeScript 开发人员都是 AI 开发人员

1. 前言

创建 TypeScript 类,并将其转换为 AI 聊天机器人。

从现在开始,每个 TypeScript 开发人员都可以成为 AI 开发人员。

TypeScript 开发者,让我们一起成为 AI 开发者@agentica

阿特尼卡

import { Agentica } from "@agentica/core";
import OpenAI from "openai";
import typia from "typia";

const agent = new Agentica({
  vendor: {
    model: "gpt-4o-mini",
    api: new OpenAI({ apiKey: "********" }),
  },
  controllers: [
    {
      protocol: "class",
      application: typia.llm.application<BbsArticleService, "chatgpt">(),
      execute: new BbsArticleService(),
    },
  ],
});
await agent.conversate("I want to write an article.");
Enter fullscreen mode Exit fullscreen mode

2. Agentica框架

@agentica是一个专门用于LLM函数调用的框架。

您可以通过 TypeScript 类类型提供函数。如果您创建FileSystem下面的类并将其与 集成@agentica,它将成为一个文件系统聊天机器人。您可以通过聊天机器人中的对话文本来管理您的文件系统。

如果您同时提供多个 TypeScript 类(例如GoogleScholarServiceNaverNewsServiceNotionService),您的 AI 代理就可以通过分析学术论文和新闻文章来编写 Notion 文档。当您要求代理分析韩国近期经济趋势、对其进行评论、整理相关论文并将其写入 Notion 时,AI 代理将执行这些任务。

只需定义您的 TypeScript 类,您就可以创建任何您想要的 AI 代理。

import fs from "fs";

export class FileSystem {
  public __dirname(): string {
    return __dirname;
  }

  public readdir(input: {
    path: string;
    options?:
      | {
          encoding: "utf-8";
          withFileTypes?: false | undefined;
          recursive?: boolean | undefined;
        }
      | "utf-8"
      | null;
  }): Promise<string[]> {
    return fs.promises.readdir(input.path, input.options);
  }

  public readFile(input: { path: string }): Promise<string> {
    return fs.promises.readFile(input.path, "utf8");
  }

  public writeFileSync(input: { 
    file: string; 
    data: string;
  }): Promise<void> {
    return fs.promises.writeFile(input.file, input.data);
  }
}
Enter fullscreen mode Exit fullscreen mode

3.企业示范

BbsArticleService有人可能会问:或类的功能不是FileSystem很少吗?这难道只是一个在有限场景下运作良好的玩具项目吗?能用 创建一个企业级聊天机器人吗@agentica

答案是肯定的,确实可以创建企业级聊天机器人。

这是一个企业级的购物中心聊天机器人,包含 289 个 API 函数。它支持标准电商平台的大多数功能,并且正如演示所示,运行起来没有任何问题。

作为参考,@agentica也可以从 Swagger/OpenAPI 文档中获取函数。下面的演示源自@samchon/shopping-backend

import { Agentica } from "@agentica/core";
import { HttpLlm, OpenApi } from "@samchon/openapi";
import typia from "typia";

const agent = new Agentica({
  model: "chatgpt",
  vendor: {
    api: new OpenAI({ apiKey: "*****" }),
    model: "gpt-4o-mini",
  },
  controllers: [
    {
      protocol: "http",
      name: "shopping",
      application: HttpLlm.application({
        model: "chatgpt",
        document: await fetch(
          "https://shopping-be.wrtn.ai/editor/swagger.json",
        ).then((r) => r.json()),
      }),
      connection: {
        host: "https://shopping-be.wrtn.ai",
        headers: {
          Authorization: "Bearer *****",
        },
      },
    },
    {
      protocol: "class",
      name: "counselor",
      application: typia.llm.application<ShoppingCounselor, "chatgpt">(),
      execute: new ShoppingCounselor(),
    },
    {
      protocol: "class",
      name: "policy",
      application: typia.llm.application<ShoppingPolicy, "chatgpt">(),
      execute: new ShoppingPolicy(),
    },
    {
      protocol: "class",
      name: "rag",
      application: typia.llm.application<ShoppingSearchRag, "chatgpt">(),
      execute: new ShoppingSearchRag(),
    },
  ],
});
await agent.conversate("I want to buy a MacBook Pro");
Enter fullscreen mode Exit fullscreen mode

4. 原则

如果你不熟悉AI,你可能会想知道如何@agentica通过函数来​​完成所有事情。

或者,如果您是 AI 代理开发专家,您可能会有不同的疑问。传统的代理开发以代理工作流图为中心,那么如何@agentica利用 LLM 函数调用来实现类似的功能呢?

访问我们的框架主页或阅读我之前的文章,了解 的关键原则@agentica。在这些资源中,你将了解新的 AI 开发范式:“编译器驱动开发”和“文档驱动开发”。

5. 下一篇文章

https://dev.to/samchon/every-backend-developer-is-a-great-ai-developer-338m

每个后端开发人员也是 AI 开发人员。

考虑到后端开发人员的工作性质,他们实际上比传统的 AI/ML 工程师更适合 AI 代理开发。

我们将swagger.json文件带到@agentica,以便让 AI 聊天机器人在对话期间执行 API 函数。

文章来源:https://dev.to/samchon/every-typescript-developer-is-an-ai-developer-2kan
PREV
[Nestia] 使用 fastify 使 NestJS 速度提高 30 倍
NEXT
JavaScript 中的 String startsWith() 方法