AI Agent智能体开发
🚀 一、AI Agent(智能体)开发需要掌握的技术栈(完整清单)
🚀 一、AI Agent(智能体)开发需要掌握的技术栈(完整清单)
✅ 1. 基础语言 & 运行环境
智能体主流语言:
-
Node.js(JS/TS)
-
Python
-
(你之前问过 Node + Nest.js,我重点围绕这两个说)
如果使用 Nest.js 开发智能体 API 层:
必须会:
-
Node.js 18+
-
TypeScript
-
Nest.js(模块、Controller、Service、Provider、Middleware)
-
Axios / Fetch(调用 OpenAI、DeepSeek API)
-
Webhook / SSE(智能体实时响应)
✅ 2. 大模型相关
必须会:
⭐ 大模型 API 使用
-
OpenAI API(GPT-4.1 / GPT-o1 / Assistant API)
-
DeepSeek API
-
阿里 Qwen
-
Moonshot Kimi
-
讯飞星火 / 百度文心等
⭐ Prompt Engineering(提示词工程)
-
角色设定
-
多轮记忆
-
工具调用(Function Call)
-
Agent 思维链(Chain-of-Thought)
✅ 3. Agent “工具调用”技术(核心)
智能体必须具备:
| 工具类型 | 技术说明 |
|---|---|
| 网络请求 | 调用 API、爬虫、搜索 |
| Python 代码执行 | 调用 Python 环境执行脚本 |
| 数据库操作 | MySQL/MongoDB/Redis |
| 文档处理 | PDF, Excel, Word |
| 计划分解 | Task decomposition |
| 浏览器控制 | Playwright / Puppeteer |
Node.js 常用:
-
LangChain JS
-
LobeHub
-
OpenAI Assistants API
-
Vercel AI SDK
✅ 4. RAG(检索增强)技术
AI Agent 必备能力之一。
必须掌握:
-
文档切分(如 RecursiveCharacterTextSplitter)
-
向量 Embedding(OpenAI / BGE / jina)
-
向量数据库(Milvus / pgvector / Pinecone)
-
RAG pipeline(检索→重排→总结)
✅ 5. 插件 / Agent 扩展开发
包括:
✔ OpenAI GPTs 插件(Action)
-
OpenAPI 规范
-
HTTPS 服务器
-
OAuth 验证
-
JSON Schema
✔ 智能体插件(Tools)
如:
-
天气查询
-
股票行情
-
网页爬取
-
自动写报告
-
自动跑脚本
✅ 6. 智能体系统架构
一个稳健的 AI Agent 系统包含:
[前端] → [Agent 服务层] → [工具层] → [大模型] → [向量库] → [计划执行器]
🧭 二、学习路线图(最快路径)
第 1 阶段:AI 基础
✔ Prompt
✔ 大模型 API
✔ JSON schema
✔ Function Call
第 2 阶段:Node.js / Nest.js + AI 接口
✔ Nest.js Controller
✔ OpenAI SDK
✔ Tool Calling
✔ SSE 流式输出
第 3 阶段:Agent 核心能力
✔ 多步推理
✔ 任务拆解
✔ 工具自动规划
✔ 多工具编排
第 4 阶段:RAG 能力
✔ 上下文检索
✔ 段落匹配
✔ 向量数据库
第 5 阶段:插件开发
✔ OpenAPI + Action
✔ 智能体自定义工具
第 6 阶段:构建完整 AI Agent
✔ 自主规划
✔ 自主行动
✔ 工具调度
✔ 日志和监控
🟦 三、Nest.js + OpenAI 实现一个最小智能体 Demo(可直接运行)
文件:src/agent/agent.service.ts
import { Injectable } from '@nestjs/common';
import OpenAI from 'openai';
@Injectable()
export class AgentService {
private openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
// 智能体主函数
async runAgent(userInput: string) {
const response = await this.openai.chat.completions.create({
model: "gpt-4.1",
messages: [
{ role: "system", content: "你是一个智能体,可以调用工具执行任务。" },
{ role: "user", content: userInput },
],
tools: [
{
type: "function",
function: {
name: "searchWeather",
description: "查询城市天气",
parameters: {
type: "object",
properties: {
city: { type: "string" },
},
required: ["city"],
},
},
}
]
});
const msg = response.choices[0].message;
// 如果模型要求调用工具
if (msg.tool_calls) {
const tool = msg.tool_calls[0];
if (tool.function.name === "searchWeather") {
const { city } = JSON.parse(tool.function.arguments);
const toolResult = await this.fakeWeather(city);
// 再把结果发给大模型
const final = await this.openai.chat.completions.create({
model: "gpt-4.1",
messages: [
...response.messages,
{ role: "tool", tool_call_id: tool.id, content: JSON.stringify(toolResult) }
]
});
return final.choices[0].message.content;
}
}
return msg.content;
}
// Tool 示例:查天气
private async fakeWeather(city: string) {
return {
city,
temp: "26°C",
condition: "晴"
};
}
}
🟣 四、AI 插件模板(OpenAI Actions)
这是 GPTs 可直接对接的 JSON Schema:
openapi: 3.1.0
info:
title: Demo Plugin
version: 1.0.0
paths:
/weather:
get:
summary: 查询天气
parameters:
- in: query
name: city
schema:
type: string
responses:
"200":
description: OK
Nest.js weather.controller.ts:
@Get('weather')
getWeather(@Query('city') city: string) {
return { city, temp: '28°C', condition: 'Sunny' };
}
🟢 五、RAG 示例项目(Node.js)
最小 RAG pipeline:
import { OpenAI } from "openai";
import { readFileSync } from "fs";
const client = new OpenAI();
async function ragQuery(question) {
// 1. 分割文档
const text = readFileSync("./docs/law.txt", "utf8");
const chunks = text.match(/.{1,300}/g);
// 2. Embedding
const embeddings = await Promise.all(
chunks.map(c => client.embeddings.create({
model: "text-embedding-3-large",
input: c
}))
);
// 3. 找最相近的片段
// (简单实现,可用向量数据库)
const userEmbedding = await client.embeddings.create({
model: "text-embedding-3-large",
input: question
});
// 4. RAG 构造提示词
const ctx = chunks[0]; // 简化:取第一个
const answer = await client.chat.completions.create({
model: "gpt-4.1",
messages: [
{ role: "system", content: `参考内容: ${ctx}` },
{ role: "user", content: question }
]
});
return answer.choices[0].message.content;
}
更多推荐


所有评论(0)