npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ai-agent-sdk/agent-core

v1.0.1

Published

## 📦 Cài đặt

Downloads

46

Readme

Agent Core SDK

📦 Cài đặt

Yêu cầu: Bun (hoặc Node.js >= 18)

# Cài đặt dependencies
bun install

Thiết lập file .env ở thư mục gốc:

OPENAI_API_KEY=your_openai_api_key_here
OPENAI_MODEL=gpt-4o-mini
OPENAI_BASE_URL=https://api.openai.com/v1

🚀 Hướng dẫn sử dụng cơ bản

1. Khởi tạo LLM Adapter và Agent

import { Agent, OpenAIAdapter } from "./src";

const model = new OpenAIAdapter({
  apiKey: process.env.OPENAI_API_KEY!,
  model: process.env.OPENAI_MODEL,
  baseURL: process.env.OPENAI_BASE_URL,
});

const agent = new Agent({
  model,
  instructions: "Bạn là trợ lý ảo hữu ích.",
  // Ép trả về JSON nếu cần (Tuỳ chọn)
  // responseFormat: 'json_object'
});

const result = await agent.run("Xin chào!");
console.log(result.content); // Output: Chào bạn! Mình có thể giúp gì cho bạn?
console.log(`Tokens dùng: ${result.usage.promptTokens}`);

2. Sử dụng Công cụ (Tools)

Tools giúp LLM thực hiện các tác vụ bên ngoài như lấy thời tiết, tính toán, gọi API.

import type { ITool } from "./src";

const getWeatherTool: ITool = {
  name: "getWeather",
  description: "Lấy thời tiết hiện tại.",
  schema: {
    type: "object",
    properties: { location: { type: "string" } },
    required: ["location"],
  },
  execute: async ({ location }) => {
    return `Thời tiết ở ${location} là 28°C.`;
  },
};

const agent = new Agent({
  model,
  instructions: "Sử dụng công cụ nếu người dùng hỏi thời tiết.",
  tools: [getWeatherTool],
});

3. Kỹ năng tải động (Lazy Skills)

Gom nhóm nhiều Tools lại thành 1 Skill. Agent sẽ chỉ nạp Tools này vào context khi nó cho rằng cần thiết, giúp giữ System Prompt luôn gọn nhẹ.

import type { ISkill } from "./src";

const mathSkill: ISkill = {
  name: "MathExpert",
  description: "Dùng khi cần tính toán số học phức tạp.",
  instructions: "Không tự tính nhẩm, hãy gọi tool calculate.",
  tools: [calculateTool],
};

const agent = new Agent({
  model,
  skills: [mathSkill],
});

4. Streaming và Memory (Chat CLI)

Tạo ứng dụng Chat có khả năng ghi nhớ và phản hồi từng chữ (Streaming).

import { LocalMemory } from "./your-memory-impl";

const agent = new Agent({
  model,
  memory: new LocalMemory(),
  maxHistoryMessages: 20, // Tự động xoá chat cũ nếu quá 20 tin nhắn
  callbacks: {
    onStream: (chunk) => process.stdout.write(chunk), // In ra từng chữ
    onToolStart: (name) => console.log(`[Đang chạy ${name}...]`),
  },
});

// sessionId giúp nhận diện người dùng / phiên chat
const result = await agent.run("Xin chào, tôi tên là Bacoor", {
  sessionId: "user_123",
});

(Tham khảo mã nguồn đầy đủ của ứng dụng chat tại examples/chat.ts)

🧱 Kiến trúc (Architecture)

Hệ thống được thiết kế hoàn toàn theo nguyên tắc SOLID, bao gồm các thành phần (Interfaces) có thể thay thế độc lập:

  • ILanguageModel: Chịu trách nhiệm giao tiếp với Provider (Ví dụ: OpenAIAdapter).
  • IMemoryProvider: Chịu trách nhiệm quản lý lịch sử (Có thể thay thế bằng RedisMemory, MongoDBMemory).
  • ITool / ISkill: Khả năng mở rộng vô hạn.
  • Middleware: Can thiệp và chỉnh sửa chuỗi xử lý (Ví dụ: nhúng hệ thống RAG/VectorDB).

Build & Dev

bun run build # Dịch ra thư mục ./dist