js-agent-core
v1.0.33
Published
A powerful, isomorphic JS Agent core library for building AI agents with TypeScript (WIP: Early development stage)
Downloads
106
Readme
JS Agent Core
⚠️ 注意 (Warning): 该项目目前正处于活跃开发阶段,功能尚不完善且 API 可能发生破坏性变更。目前不建议在生产环境中使用。
This project is currently under active development. Features are incomplete and APIs may undergo breaking changes. Not recommended for production use.
A powerful, isomorphic, and extensible AI Agent framework built with TypeScript. Run your agents anywhere — from Node.js servers to browsers and edge environments.
🚀 Key Features
- 🌐 Isomorphic: Seamlessly runs in Node.js, Browsers, and Edge (Vercel/Cloudflare).
- 🧠 Dynamic Skill Routing: Scale your agent with hundreds of skills without blowing up context tokens. Only relevant tools are activated on-demand.
- 🏗️ Structured Planning: Uses a goal-oriented planning system that can break down complex requests into manageable tasks.
- 💾 Hybrid Memory: Combines short-term conversational history with long-term vector-based retrieval (RAG).
- 🛠️ Self-Evolution: Enable your agents to create, persist, and reuse their own skills in real-time.
- 📊 Observability: Built-in event system for tracing, logging, and real-time progress monitoring.
📦 Installation
npm install js-agent-core🚦 Quick Start
Basic Usage
import { BaseAgent, LLMProvider, NodeFsLogger } from 'js-agent-core';
const agent = new BaseAgent({
provider: new LLMProvider({ apiKey: 'your-key' }),
model: 'gpt-4o',
logger: new NodeFsLogger()
});
const response = await agent.run('Explain quantum entanglement like I am five.');
console.log(response);Using Skills & Tools
import { BaseAgent, LLMProvider } from 'js-agent-core';
import { z } from 'zod';
const agent = new BaseAgent({
provider: new LLMProvider({ apiKey: '...' }),
model: 'gpt-4o'
});
// Register a simple tool
agent.registerTool({
name: 'get_weather',
description: 'Get weather for a city',
parameters: z.object({ city: z.string() }),
execute: async ({ city }) => ({ success: true, data: `Sunny in ${city}` })
});
await agent.run('What is the weather in Tokyo?');🧩 Advanced Features
Dynamic Skill Routing
Avoid context explosion by enabling enableDynamicSkills. The agent will use a "Router" to select only necessary skills from its library before execution.
const agent = new BaseAgent({
// ...
enableDynamicSkills: true,
routerModel: 'gpt-4o-mini' // Use a cheaper model for routing
});
agent.registerSkill(massiveMathSkillLibrary);
agent.registerSkill(massiveDevOpsSkillLibrary);
// Agent will only activate math tools for math questions
await agent.run('What is the derivative of x^2?');Node.js Runtime (Auto-loaded)
When running in Node.js, js-agent-core automatically provides powerful system capabilities:
- File System: Read, write, list, and search files.
- Terminal: Execute shell commands.
- Self-Evolution: Agents can define new skills and save them for future use.
📖 API Reference
See the full API Reference for detailed documentation.
📄 License
ISC
