
Agent开发环境搭建完全指南
文章目录
- Agent开发环境搭建完全指南
-
- 摘要
- 一、开发工具选择
-
- [1.1 编程语言选择](#1.1 编程语言选择)
- [1.2 开发环境推荐](#1.2 开发环境推荐)
- [1.3 容器化工具](#1.3 容器化工具)
- 二、Python环境配置
-
- [2.1 Python安装](#2.1 Python安装)
- [2.2 虚拟环境配置](#2.2 虚拟环境配置)
- [2.3 关键依赖库](#2.3 关键依赖库)
- 三、TypeScript环境配置
-
- [3.1 Node.js安装](#3.1 Node.js安装)
- [3.2 项目初始化](#3.2 项目初始化)
- [3.3 TypeScript配置](#3.3 TypeScript配置)
- 四、项目结构设计
-
- [4.1 典型项目结构](#4.1 典型项目结构)
- [4.2 文件职责划分](#4.2 文件职责划分)
- 五、配置管理
-
- [5.1 环境变量管理](#5.1 环境变量管理)
- [5.2 配置加载代码](#5.2 配置加载代码)
- 六、依赖注入与模块化
-
- [6.1 依赖注入模式](#6.1 依赖注入模式)
- [6.2 模块化设计原则](#6.2 模块化设计原则)
- 七、测试环境配置
-
- [7.1 测试框架选择](#7.1 测试框架选择)
- [7.2 测试配置](#7.2 测试配置)
- 八、开发环境验证
-
- [8.1 验证步骤](#8.1 验证步骤)
- [8.2 验证脚本](#8.2 验证脚本)
- 九、Docker容器化配置
-
- [9.1 Dockerfile示例](#9.1 Dockerfile示例)
- [9.2 docker-compose.yml示例](#9.2 docker-compose.yml示例)
- 十、总结与下一步
-
- [10.1 本文总结](#10.1 本文总结)
- [10.2 下一步](#10.2 下一步)
摘要
本文详细介绍Agent开发环境的搭建过程,包括开发工具选择、环境配置步骤和项目初始化。通过本文的指导,读者将能够从零开始搭建一个完整的Agent开发环境,并创建第一个简单的Agent项目。
一、开发工具选择
1.1 编程语言选择
选择合适的编程语言是Agent开发的第一步:
#mermaid-svg-a9jsmES6cpmdSqVV{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-a9jsmES6cpmdSqVV .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-a9jsmES6cpmdSqVV .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-a9jsmES6cpmdSqVV .error-icon{fill:#552222;}#mermaid-svg-a9jsmES6cpmdSqVV .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-a9jsmES6cpmdSqVV .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-a9jsmES6cpmdSqVV .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-a9jsmES6cpmdSqVV .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-a9jsmES6cpmdSqVV .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-a9jsmES6cpmdSqVV .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-a9jsmES6cpmdSqVV .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-a9jsmES6cpmdSqVV .marker{fill:#333333;stroke:#333333;}#mermaid-svg-a9jsmES6cpmdSqVV .marker.cross{stroke:#333333;}#mermaid-svg-a9jsmES6cpmdSqVV svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-a9jsmES6cpmdSqVV p{margin:0;}#mermaid-svg-a9jsmES6cpmdSqVV .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-a9jsmES6cpmdSqVV .cluster-label text{fill:#333;}#mermaid-svg-a9jsmES6cpmdSqVV .cluster-label span{color:#333;}#mermaid-svg-a9jsmES6cpmdSqVV .cluster-label span p{background-color:transparent;}#mermaid-svg-a9jsmES6cpmdSqVV .label text,#mermaid-svg-a9jsmES6cpmdSqVV span{fill:#333;color:#333;}#mermaid-svg-a9jsmES6cpmdSqVV .node rect,#mermaid-svg-a9jsmES6cpmdSqVV .node circle,#mermaid-svg-a9jsmES6cpmdSqVV .node ellipse,#mermaid-svg-a9jsmES6cpmdSqVV .node polygon,#mermaid-svg-a9jsmES6cpmdSqVV .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-a9jsmES6cpmdSqVV .rough-node .label text,#mermaid-svg-a9jsmES6cpmdSqVV .node .label text,#mermaid-svg-a9jsmES6cpmdSqVV .image-shape .label,#mermaid-svg-a9jsmES6cpmdSqVV .icon-shape .label{text-anchor:middle;}#mermaid-svg-a9jsmES6cpmdSqVV .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-a9jsmES6cpmdSqVV .rough-node .label,#mermaid-svg-a9jsmES6cpmdSqVV .node .label,#mermaid-svg-a9jsmES6cpmdSqVV .image-shape .label,#mermaid-svg-a9jsmES6cpmdSqVV .icon-shape .label{text-align:center;}#mermaid-svg-a9jsmES6cpmdSqVV .node.clickable{cursor:pointer;}#mermaid-svg-a9jsmES6cpmdSqVV .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-a9jsmES6cpmdSqVV .arrowheadPath{fill:#333333;}#mermaid-svg-a9jsmES6cpmdSqVV .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-a9jsmES6cpmdSqVV .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-a9jsmES6cpmdSqVV .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-a9jsmES6cpmdSqVV .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-a9jsmES6cpmdSqVV .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-a9jsmES6cpmdSqVV .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-a9jsmES6cpmdSqVV .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-a9jsmES6cpmdSqVV .cluster text{fill:#333;}#mermaid-svg-a9jsmES6cpmdSqVV .cluster span{color:#333;}#mermaid-svg-a9jsmES6cpmdSqVV div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-a9jsmES6cpmdSqVV .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-a9jsmES6cpmdSqVV rect.text{fill:none;stroke-width:0;}#mermaid-svg-a9jsmES6cpmdSqVV .icon-shape,#mermaid-svg-a9jsmES6cpmdSqVV .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-a9jsmES6cpmdSqVV .icon-shape p,#mermaid-svg-a9jsmES6cpmdSqVV .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-a9jsmES6cpmdSqVV .icon-shape .label rect,#mermaid-svg-a9jsmES6cpmdSqVV .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-a9jsmES6cpmdSqVV .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-a9jsmES6cpmdSqVV .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-a9jsmES6cpmdSqVV :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 编程语言选择
Python
JavaScript/TypeScript
Go
Java
丰富的AI库
快速原型开发
Web开发优势
Node.js生态
高性能
并发支持
企业级应用
成熟生态
| 语言 | 优势 | 适用场景 |
|---|---|---|
| Python | AI库丰富、开发效率高 | 原型开发、研究 |
| TypeScript | 类型安全、生态成熟 | Web Agent、企业应用 |
| Go | 高性能、并发好 | 分布式系统 |
| Java | 稳定、成熟 | 大型企业系统 |
1.2 开发环境推荐
代码编辑器
| 工具 | 特点 | 推荐插件 |
|---|---|---|
| VS Code | 轻量、插件丰富 | Python、TypeScript、GitLens |
| PyCharm | Python专业支持 | AI Assistant、Docker |
| WebStorm | Web开发专业 | Node.js、React |
版本控制
#mermaid-svg-A9syiRxYxyfEN7eQ{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-A9syiRxYxyfEN7eQ .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-A9syiRxYxyfEN7eQ .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-A9syiRxYxyfEN7eQ .error-icon{fill:#552222;}#mermaid-svg-A9syiRxYxyfEN7eQ .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-A9syiRxYxyfEN7eQ .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-A9syiRxYxyfEN7eQ .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-A9syiRxYxyfEN7eQ .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-A9syiRxYxyfEN7eQ .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-A9syiRxYxyfEN7eQ .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-A9syiRxYxyfEN7eQ .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-A9syiRxYxyfEN7eQ .marker{fill:#333333;stroke:#333333;}#mermaid-svg-A9syiRxYxyfEN7eQ .marker.cross{stroke:#333333;}#mermaid-svg-A9syiRxYxyfEN7eQ svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-A9syiRxYxyfEN7eQ p{margin:0;}#mermaid-svg-A9syiRxYxyfEN7eQ .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-A9syiRxYxyfEN7eQ .cluster-label text{fill:#333;}#mermaid-svg-A9syiRxYxyfEN7eQ .cluster-label span{color:#333;}#mermaid-svg-A9syiRxYxyfEN7eQ .cluster-label span p{background-color:transparent;}#mermaid-svg-A9syiRxYxyfEN7eQ .label text,#mermaid-svg-A9syiRxYxyfEN7eQ span{fill:#333;color:#333;}#mermaid-svg-A9syiRxYxyfEN7eQ .node rect,#mermaid-svg-A9syiRxYxyfEN7eQ .node circle,#mermaid-svg-A9syiRxYxyfEN7eQ .node ellipse,#mermaid-svg-A9syiRxYxyfEN7eQ .node polygon,#mermaid-svg-A9syiRxYxyfEN7eQ .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-A9syiRxYxyfEN7eQ .rough-node .label text,#mermaid-svg-A9syiRxYxyfEN7eQ .node .label text,#mermaid-svg-A9syiRxYxyfEN7eQ .image-shape .label,#mermaid-svg-A9syiRxYxyfEN7eQ .icon-shape .label{text-anchor:middle;}#mermaid-svg-A9syiRxYxyfEN7eQ .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-A9syiRxYxyfEN7eQ .rough-node .label,#mermaid-svg-A9syiRxYxyfEN7eQ .node .label,#mermaid-svg-A9syiRxYxyfEN7eQ .image-shape .label,#mermaid-svg-A9syiRxYxyfEN7eQ .icon-shape .label{text-align:center;}#mermaid-svg-A9syiRxYxyfEN7eQ .node.clickable{cursor:pointer;}#mermaid-svg-A9syiRxYxyfEN7eQ .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-A9syiRxYxyfEN7eQ .arrowheadPath{fill:#333333;}#mermaid-svg-A9syiRxYxyfEN7eQ .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-A9syiRxYxyfEN7eQ .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-A9syiRxYxyfEN7eQ .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-A9syiRxYxyfEN7eQ .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-A9syiRxYxyfEN7eQ .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-A9syiRxYxyfEN7eQ .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-A9syiRxYxyfEN7eQ .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-A9syiRxYxyfEN7eQ .cluster text{fill:#333;}#mermaid-svg-A9syiRxYxyfEN7eQ .cluster span{color:#333;}#mermaid-svg-A9syiRxYxyfEN7eQ div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-A9syiRxYxyfEN7eQ .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-A9syiRxYxyfEN7eQ rect.text{fill:none;stroke-width:0;}#mermaid-svg-A9syiRxYxyfEN7eQ .icon-shape,#mermaid-svg-A9syiRxYxyfEN7eQ .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-A9syiRxYxyfEN7eQ .icon-shape p,#mermaid-svg-A9syiRxYxyfEN7eQ .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-A9syiRxYxyfEN7eQ .icon-shape .label rect,#mermaid-svg-A9syiRxYxyfEN7eQ .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-A9syiRxYxyfEN7eQ .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-A9syiRxYxyfEN7eQ .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-A9syiRxYxyfEN7eQ :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 版本控制
Git
代码托管
GitHub
GitLab
Gitee
1.3 容器化工具
#mermaid-svg-0uWLByysSZSFLNpv{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-0uWLByysSZSFLNpv .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-0uWLByysSZSFLNpv .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-0uWLByysSZSFLNpv .error-icon{fill:#552222;}#mermaid-svg-0uWLByysSZSFLNpv .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-0uWLByysSZSFLNpv .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-0uWLByysSZSFLNpv .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-0uWLByysSZSFLNpv .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-0uWLByysSZSFLNpv .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-0uWLByysSZSFLNpv .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-0uWLByysSZSFLNpv .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-0uWLByysSZSFLNpv .marker{fill:#333333;stroke:#333333;}#mermaid-svg-0uWLByysSZSFLNpv .marker.cross{stroke:#333333;}#mermaid-svg-0uWLByysSZSFLNpv svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-0uWLByysSZSFLNpv p{margin:0;}#mermaid-svg-0uWLByysSZSFLNpv .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-0uWLByysSZSFLNpv .cluster-label text{fill:#333;}#mermaid-svg-0uWLByysSZSFLNpv .cluster-label span{color:#333;}#mermaid-svg-0uWLByysSZSFLNpv .cluster-label span p{background-color:transparent;}#mermaid-svg-0uWLByysSZSFLNpv .label text,#mermaid-svg-0uWLByysSZSFLNpv span{fill:#333;color:#333;}#mermaid-svg-0uWLByysSZSFLNpv .node rect,#mermaid-svg-0uWLByysSZSFLNpv .node circle,#mermaid-svg-0uWLByysSZSFLNpv .node ellipse,#mermaid-svg-0uWLByysSZSFLNpv .node polygon,#mermaid-svg-0uWLByysSZSFLNpv .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-0uWLByysSZSFLNpv .rough-node .label text,#mermaid-svg-0uWLByysSZSFLNpv .node .label text,#mermaid-svg-0uWLByysSZSFLNpv .image-shape .label,#mermaid-svg-0uWLByysSZSFLNpv .icon-shape .label{text-anchor:middle;}#mermaid-svg-0uWLByysSZSFLNpv .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-0uWLByysSZSFLNpv .rough-node .label,#mermaid-svg-0uWLByysSZSFLNpv .node .label,#mermaid-svg-0uWLByysSZSFLNpv .image-shape .label,#mermaid-svg-0uWLByysSZSFLNpv .icon-shape .label{text-align:center;}#mermaid-svg-0uWLByysSZSFLNpv .node.clickable{cursor:pointer;}#mermaid-svg-0uWLByysSZSFLNpv .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-0uWLByysSZSFLNpv .arrowheadPath{fill:#333333;}#mermaid-svg-0uWLByysSZSFLNpv .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-0uWLByysSZSFLNpv .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-0uWLByysSZSFLNpv .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-0uWLByysSZSFLNpv .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-0uWLByysSZSFLNpv .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-0uWLByysSZSFLNpv .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-0uWLByysSZSFLNpv .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-0uWLByysSZSFLNpv .cluster text{fill:#333;}#mermaid-svg-0uWLByysSZSFLNpv .cluster span{color:#333;}#mermaid-svg-0uWLByysSZSFLNpv div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-0uWLByysSZSFLNpv .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-0uWLByysSZSFLNpv rect.text{fill:none;stroke-width:0;}#mermaid-svg-0uWLByysSZSFLNpv .icon-shape,#mermaid-svg-0uWLByysSZSFLNpv .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-0uWLByysSZSFLNpv .icon-shape p,#mermaid-svg-0uWLByysSZSFLNpv .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-0uWLByysSZSFLNpv .icon-shape .label rect,#mermaid-svg-0uWLByysSZSFLNpv .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-0uWLByysSZSFLNpv .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-0uWLByysSZSFLNpv .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-0uWLByysSZSFLNpv :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 容器化
Docker
Kubernetes
环境隔离
快速部署
编排管理
高可用
二、Python环境配置
2.1 Python安装
#mermaid-svg-GHcrelAq37ZL3kNu{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-GHcrelAq37ZL3kNu .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-GHcrelAq37ZL3kNu .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-GHcrelAq37ZL3kNu .error-icon{fill:#552222;}#mermaid-svg-GHcrelAq37ZL3kNu .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-GHcrelAq37ZL3kNu .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-GHcrelAq37ZL3kNu .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-GHcrelAq37ZL3kNu .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-GHcrelAq37ZL3kNu .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-GHcrelAq37ZL3kNu .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-GHcrelAq37ZL3kNu .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-GHcrelAq37ZL3kNu .marker{fill:#333333;stroke:#333333;}#mermaid-svg-GHcrelAq37ZL3kNu .marker.cross{stroke:#333333;}#mermaid-svg-GHcrelAq37ZL3kNu svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-GHcrelAq37ZL3kNu p{margin:0;}#mermaid-svg-GHcrelAq37ZL3kNu .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-GHcrelAq37ZL3kNu .cluster-label text{fill:#333;}#mermaid-svg-GHcrelAq37ZL3kNu .cluster-label span{color:#333;}#mermaid-svg-GHcrelAq37ZL3kNu .cluster-label span p{background-color:transparent;}#mermaid-svg-GHcrelAq37ZL3kNu .label text,#mermaid-svg-GHcrelAq37ZL3kNu span{fill:#333;color:#333;}#mermaid-svg-GHcrelAq37ZL3kNu .node rect,#mermaid-svg-GHcrelAq37ZL3kNu .node circle,#mermaid-svg-GHcrelAq37ZL3kNu .node ellipse,#mermaid-svg-GHcrelAq37ZL3kNu .node polygon,#mermaid-svg-GHcrelAq37ZL3kNu .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-GHcrelAq37ZL3kNu .rough-node .label text,#mermaid-svg-GHcrelAq37ZL3kNu .node .label text,#mermaid-svg-GHcrelAq37ZL3kNu .image-shape .label,#mermaid-svg-GHcrelAq37ZL3kNu .icon-shape .label{text-anchor:middle;}#mermaid-svg-GHcrelAq37ZL3kNu .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-GHcrelAq37ZL3kNu .rough-node .label,#mermaid-svg-GHcrelAq37ZL3kNu .node .label,#mermaid-svg-GHcrelAq37ZL3kNu .image-shape .label,#mermaid-svg-GHcrelAq37ZL3kNu .icon-shape .label{text-align:center;}#mermaid-svg-GHcrelAq37ZL3kNu .node.clickable{cursor:pointer;}#mermaid-svg-GHcrelAq37ZL3kNu .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-GHcrelAq37ZL3kNu .arrowheadPath{fill:#333333;}#mermaid-svg-GHcrelAq37ZL3kNu .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-GHcrelAq37ZL3kNu .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-GHcrelAq37ZL3kNu .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-GHcrelAq37ZL3kNu .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-GHcrelAq37ZL3kNu .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-GHcrelAq37ZL3kNu .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-GHcrelAq37ZL3kNu .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-GHcrelAq37ZL3kNu .cluster text{fill:#333;}#mermaid-svg-GHcrelAq37ZL3kNu .cluster span{color:#333;}#mermaid-svg-GHcrelAq37ZL3kNu div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-GHcrelAq37ZL3kNu .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-GHcrelAq37ZL3kNu rect.text{fill:none;stroke-width:0;}#mermaid-svg-GHcrelAq37ZL3kNu .icon-shape,#mermaid-svg-GHcrelAq37ZL3kNu .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-GHcrelAq37ZL3kNu .icon-shape p,#mermaid-svg-GHcrelAq37ZL3kNu .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-GHcrelAq37ZL3kNu .icon-shape .label rect,#mermaid-svg-GHcrelAq37ZL3kNu .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-GHcrelAq37ZL3kNu .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-GHcrelAq37ZL3kNu .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-GHcrelAq37ZL3kNu :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 安装Python
下载安装包
运行安装程序
配置环境变量
验证安装
python --version
pip --version
安装步骤:
-
访问 Python官网
-
下载对应版本(推荐3.10+)
-
运行安装程序,勾选"Add Python to PATH"
-
验证安装:
bashpython --version pip --version
2.2 虚拟环境配置
终端 用户 终端 用户 #mermaid-svg-UivSu6vAtyXf67YH{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-UivSu6vAtyXf67YH .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-UivSu6vAtyXf67YH .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-UivSu6vAtyXf67YH .error-icon{fill:#552222;}#mermaid-svg-UivSu6vAtyXf67YH .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-UivSu6vAtyXf67YH .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-UivSu6vAtyXf67YH .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-UivSu6vAtyXf67YH .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-UivSu6vAtyXf67YH .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-UivSu6vAtyXf67YH .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-UivSu6vAtyXf67YH .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-UivSu6vAtyXf67YH .marker{fill:#333333;stroke:#333333;}#mermaid-svg-UivSu6vAtyXf67YH .marker.cross{stroke:#333333;}#mermaid-svg-UivSu6vAtyXf67YH svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-UivSu6vAtyXf67YH p{margin:0;}#mermaid-svg-UivSu6vAtyXf67YH .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-UivSu6vAtyXf67YH text.actor>tspan{fill:black;stroke:none;}#mermaid-svg-UivSu6vAtyXf67YH .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-UivSu6vAtyXf67YH .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-UivSu6vAtyXf67YH .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-UivSu6vAtyXf67YH .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-UivSu6vAtyXf67YH #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-UivSu6vAtyXf67YH .sequenceNumber{fill:white;}#mermaid-svg-UivSu6vAtyXf67YH #sequencenumber{fill:#333;}#mermaid-svg-UivSu6vAtyXf67YH #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-UivSu6vAtyXf67YH .messageText{fill:#333;stroke:none;}#mermaid-svg-UivSu6vAtyXf67YH .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-UivSu6vAtyXf67YH .labelText,#mermaid-svg-UivSu6vAtyXf67YH .labelText>tspan{fill:black;stroke:none;}#mermaid-svg-UivSu6vAtyXf67YH .loopText,#mermaid-svg-UivSu6vAtyXf67YH .loopText>tspan{fill:black;stroke:none;}#mermaid-svg-UivSu6vAtyXf67YH .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-UivSu6vAtyXf67YH .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-UivSu6vAtyXf67YH .noteText,#mermaid-svg-UivSu6vAtyXf67YH .noteText>tspan{fill:black;stroke:none;}#mermaid-svg-UivSu6vAtyXf67YH .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-UivSu6vAtyXf67YH .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-UivSu6vAtyXf67YH .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-UivSu6vAtyXf67YH .actorPopupMenu{position:absolute;}#mermaid-svg-UivSu6vAtyXf67YH .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-UivSu6vAtyXf67YH .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-UivSu6vAtyXf67YH .actor-man circle,#mermaid-svg-UivSu6vAtyXf67YH line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-UivSu6vAtyXf67YH :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} Windows: agent-env\Scripts\activate Linux/Mac: source agent-env/bin/activate 创建虚拟环境 python -m venv agent-env 激活虚拟环境 安装依赖 pip install -r requirements.txt
常用命令:
| 操作 | 命令 |
|---|---|
| 创建虚拟环境 | python -m venv agent-env |
| 激活(Windows) | agent-env\Scripts\activate |
| 激活(Linux/Mac) | source agent-env/bin/activate |
| 安装依赖 | pip install package_name |
| 导出依赖 | pip freeze > requirements.txt |
2.3 关键依赖库
#mermaid-svg-fEurcJhnxH82tzz2{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-fEurcJhnxH82tzz2 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-fEurcJhnxH82tzz2 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-fEurcJhnxH82tzz2 .error-icon{fill:#552222;}#mermaid-svg-fEurcJhnxH82tzz2 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-fEurcJhnxH82tzz2 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-fEurcJhnxH82tzz2 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-fEurcJhnxH82tzz2 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-fEurcJhnxH82tzz2 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-fEurcJhnxH82tzz2 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-fEurcJhnxH82tzz2 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-fEurcJhnxH82tzz2 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-fEurcJhnxH82tzz2 .marker.cross{stroke:#333333;}#mermaid-svg-fEurcJhnxH82tzz2 svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-fEurcJhnxH82tzz2 p{margin:0;}#mermaid-svg-fEurcJhnxH82tzz2 .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-fEurcJhnxH82tzz2 .cluster-label text{fill:#333;}#mermaid-svg-fEurcJhnxH82tzz2 .cluster-label span{color:#333;}#mermaid-svg-fEurcJhnxH82tzz2 .cluster-label span p{background-color:transparent;}#mermaid-svg-fEurcJhnxH82tzz2 .label text,#mermaid-svg-fEurcJhnxH82tzz2 span{fill:#333;color:#333;}#mermaid-svg-fEurcJhnxH82tzz2 .node rect,#mermaid-svg-fEurcJhnxH82tzz2 .node circle,#mermaid-svg-fEurcJhnxH82tzz2 .node ellipse,#mermaid-svg-fEurcJhnxH82tzz2 .node polygon,#mermaid-svg-fEurcJhnxH82tzz2 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-fEurcJhnxH82tzz2 .rough-node .label text,#mermaid-svg-fEurcJhnxH82tzz2 .node .label text,#mermaid-svg-fEurcJhnxH82tzz2 .image-shape .label,#mermaid-svg-fEurcJhnxH82tzz2 .icon-shape .label{text-anchor:middle;}#mermaid-svg-fEurcJhnxH82tzz2 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-fEurcJhnxH82tzz2 .rough-node .label,#mermaid-svg-fEurcJhnxH82tzz2 .node .label,#mermaid-svg-fEurcJhnxH82tzz2 .image-shape .label,#mermaid-svg-fEurcJhnxH82tzz2 .icon-shape .label{text-align:center;}#mermaid-svg-fEurcJhnxH82tzz2 .node.clickable{cursor:pointer;}#mermaid-svg-fEurcJhnxH82tzz2 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-fEurcJhnxH82tzz2 .arrowheadPath{fill:#333333;}#mermaid-svg-fEurcJhnxH82tzz2 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-fEurcJhnxH82tzz2 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-fEurcJhnxH82tzz2 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-fEurcJhnxH82tzz2 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-fEurcJhnxH82tzz2 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-fEurcJhnxH82tzz2 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-fEurcJhnxH82tzz2 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-fEurcJhnxH82tzz2 .cluster text{fill:#333;}#mermaid-svg-fEurcJhnxH82tzz2 .cluster span{color:#333;}#mermaid-svg-fEurcJhnxH82tzz2 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-fEurcJhnxH82tzz2 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-fEurcJhnxH82tzz2 rect.text{fill:none;stroke-width:0;}#mermaid-svg-fEurcJhnxH82tzz2 .icon-shape,#mermaid-svg-fEurcJhnxH82tzz2 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-fEurcJhnxH82tzz2 .icon-shape p,#mermaid-svg-fEurcJhnxH82tzz2 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-fEurcJhnxH82tzz2 .icon-shape .label rect,#mermaid-svg-fEurcJhnxH82tzz2 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-fEurcJhnxH82tzz2 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-fEurcJhnxH82tzz2 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-fEurcJhnxH82tzz2 :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 核心依赖
AI框架
工具库
Web框架
LangChain
OpenAI
HuggingFace
requests
pydantic
asyncio
FastAPI
Flask
requirements.txt示例:
txt
# AI相关
langchain==0.1.10
openai==1.13.3
transformers==4.39.0
torch==2.2.0
# 工具库
requests==2.31.0
pydantic==2.6.1
python-dotenv==1.0.1
asyncio==3.4.3
# Web框架
fastapi==0.110.0
uvicorn==0.27.1
三、TypeScript环境配置
3.1 Node.js安装
#mermaid-svg-ECs28cJdPPo33UG8{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-ECs28cJdPPo33UG8 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-ECs28cJdPPo33UG8 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-ECs28cJdPPo33UG8 .error-icon{fill:#552222;}#mermaid-svg-ECs28cJdPPo33UG8 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-ECs28cJdPPo33UG8 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-ECs28cJdPPo33UG8 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-ECs28cJdPPo33UG8 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-ECs28cJdPPo33UG8 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-ECs28cJdPPo33UG8 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-ECs28cJdPPo33UG8 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-ECs28cJdPPo33UG8 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-ECs28cJdPPo33UG8 .marker.cross{stroke:#333333;}#mermaid-svg-ECs28cJdPPo33UG8 svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-ECs28cJdPPo33UG8 p{margin:0;}#mermaid-svg-ECs28cJdPPo33UG8 .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-ECs28cJdPPo33UG8 .cluster-label text{fill:#333;}#mermaid-svg-ECs28cJdPPo33UG8 .cluster-label span{color:#333;}#mermaid-svg-ECs28cJdPPo33UG8 .cluster-label span p{background-color:transparent;}#mermaid-svg-ECs28cJdPPo33UG8 .label text,#mermaid-svg-ECs28cJdPPo33UG8 span{fill:#333;color:#333;}#mermaid-svg-ECs28cJdPPo33UG8 .node rect,#mermaid-svg-ECs28cJdPPo33UG8 .node circle,#mermaid-svg-ECs28cJdPPo33UG8 .node ellipse,#mermaid-svg-ECs28cJdPPo33UG8 .node polygon,#mermaid-svg-ECs28cJdPPo33UG8 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-ECs28cJdPPo33UG8 .rough-node .label text,#mermaid-svg-ECs28cJdPPo33UG8 .node .label text,#mermaid-svg-ECs28cJdPPo33UG8 .image-shape .label,#mermaid-svg-ECs28cJdPPo33UG8 .icon-shape .label{text-anchor:middle;}#mermaid-svg-ECs28cJdPPo33UG8 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-ECs28cJdPPo33UG8 .rough-node .label,#mermaid-svg-ECs28cJdPPo33UG8 .node .label,#mermaid-svg-ECs28cJdPPo33UG8 .image-shape .label,#mermaid-svg-ECs28cJdPPo33UG8 .icon-shape .label{text-align:center;}#mermaid-svg-ECs28cJdPPo33UG8 .node.clickable{cursor:pointer;}#mermaid-svg-ECs28cJdPPo33UG8 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-ECs28cJdPPo33UG8 .arrowheadPath{fill:#333333;}#mermaid-svg-ECs28cJdPPo33UG8 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-ECs28cJdPPo33UG8 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-ECs28cJdPPo33UG8 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-ECs28cJdPPo33UG8 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-ECs28cJdPPo33UG8 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-ECs28cJdPPo33UG8 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-ECs28cJdPPo33UG8 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-ECs28cJdPPo33UG8 .cluster text{fill:#333;}#mermaid-svg-ECs28cJdPPo33UG8 .cluster span{color:#333;}#mermaid-svg-ECs28cJdPPo33UG8 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-ECs28cJdPPo33UG8 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-ECs28cJdPPo33UG8 rect.text{fill:none;stroke-width:0;}#mermaid-svg-ECs28cJdPPo33UG8 .icon-shape,#mermaid-svg-ECs28cJdPPo33UG8 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-ECs28cJdPPo33UG8 .icon-shape p,#mermaid-svg-ECs28cJdPPo33UG8 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-ECs28cJdPPo33UG8 .icon-shape .label rect,#mermaid-svg-ECs28cJdPPo33UG8 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-ECs28cJdPPo33UG8 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-ECs28cJdPPo33UG8 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-ECs28cJdPPo33UG8 :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 安装Node.js
下载安装包
运行安装程序
验证安装
node --version
npm --version
安装步骤:
-
访问 Node.js官网
-
下载LTS版本
-
运行安装程序
-
验证安装:
bashnode --version npm --version
3.2 项目初始化
终端 用户 终端 用户 #mermaid-svg-M0yvHSdd2pmFon8o{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-M0yvHSdd2pmFon8o .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-M0yvHSdd2pmFon8o .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-M0yvHSdd2pmFon8o .error-icon{fill:#552222;}#mermaid-svg-M0yvHSdd2pmFon8o .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-M0yvHSdd2pmFon8o .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-M0yvHSdd2pmFon8o .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-M0yvHSdd2pmFon8o .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-M0yvHSdd2pmFon8o .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-M0yvHSdd2pmFon8o .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-M0yvHSdd2pmFon8o .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-M0yvHSdd2pmFon8o .marker{fill:#333333;stroke:#333333;}#mermaid-svg-M0yvHSdd2pmFon8o .marker.cross{stroke:#333333;}#mermaid-svg-M0yvHSdd2pmFon8o svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-M0yvHSdd2pmFon8o p{margin:0;}#mermaid-svg-M0yvHSdd2pmFon8o .actor{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-M0yvHSdd2pmFon8o text.actor>tspan{fill:black;stroke:none;}#mermaid-svg-M0yvHSdd2pmFon8o .actor-line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-M0yvHSdd2pmFon8o .innerArc{stroke-width:1.5;stroke-dasharray:none;}#mermaid-svg-M0yvHSdd2pmFon8o .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333;}#mermaid-svg-M0yvHSdd2pmFon8o .messageLine1{stroke-width:1.5;stroke-dasharray:2,2;stroke:#333;}#mermaid-svg-M0yvHSdd2pmFon8o #arrowhead path{fill:#333;stroke:#333;}#mermaid-svg-M0yvHSdd2pmFon8o .sequenceNumber{fill:white;}#mermaid-svg-M0yvHSdd2pmFon8o #sequencenumber{fill:#333;}#mermaid-svg-M0yvHSdd2pmFon8o #crosshead path{fill:#333;stroke:#333;}#mermaid-svg-M0yvHSdd2pmFon8o .messageText{fill:#333;stroke:none;}#mermaid-svg-M0yvHSdd2pmFon8o .labelBox{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-M0yvHSdd2pmFon8o .labelText,#mermaid-svg-M0yvHSdd2pmFon8o .labelText>tspan{fill:black;stroke:none;}#mermaid-svg-M0yvHSdd2pmFon8o .loopText,#mermaid-svg-M0yvHSdd2pmFon8o .loopText>tspan{fill:black;stroke:none;}#mermaid-svg-M0yvHSdd2pmFon8o .loopLine{stroke-width:2px;stroke-dasharray:2,2;stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);}#mermaid-svg-M0yvHSdd2pmFon8o .note{stroke:#aaaa33;fill:#fff5ad;}#mermaid-svg-M0yvHSdd2pmFon8o .noteText,#mermaid-svg-M0yvHSdd2pmFon8o .noteText>tspan{fill:black;stroke:none;}#mermaid-svg-M0yvHSdd2pmFon8o .activation0{fill:#f4f4f4;stroke:#666;}#mermaid-svg-M0yvHSdd2pmFon8o .activation1{fill:#f4f4f4;stroke:#666;}#mermaid-svg-M0yvHSdd2pmFon8o .activation2{fill:#f4f4f4;stroke:#666;}#mermaid-svg-M0yvHSdd2pmFon8o .actorPopupMenu{position:absolute;}#mermaid-svg-M0yvHSdd2pmFon8o .actorPopupMenuPanel{position:absolute;fill:#ECECFF;box-shadow:0px 8px 16px 0px rgba(0,0,0,0.2);filter:drop-shadow(3px 5px 2px rgb(0 0 0 / 0.4));}#mermaid-svg-M0yvHSdd2pmFon8o .actor-man line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;}#mermaid-svg-M0yvHSdd2pmFon8o .actor-man circle,#mermaid-svg-M0yvHSdd2pmFon8o line{stroke:hsl(259.6261682243, 59.7765363128%, 87.9019607843%);fill:#ECECFF;stroke-width:2px;}#mermaid-svg-M0yvHSdd2pmFon8o :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 创建项目目录 mkdir agent-project && cd agent-project 初始化项目 npm init -y 安装TypeScript npm install typescript ts-node @types/node --save-dev
package.json示例:
json
{
"name": "agent-project",
"version": "1.0.0",
"main": "dist/index.js",
"scripts": {
"start": "node dist/index.js",
"build": "tsc",
"dev": "ts-node src/index.ts"
},
"dependencies": {
"openai": "^4.28.4",
"axios": "^1.6.7"
},
"devDependencies": {
"@types/node": "^20.11.0",
"typescript": "^5.3.3"
}
}
3.3 TypeScript配置
tsconfig.json示例:
json
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules"]
}
四、项目结构设计
4.1 典型项目结构
#mermaid-svg-MJLBXtu46iUPw2PN{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-MJLBXtu46iUPw2PN .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-MJLBXtu46iUPw2PN .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-MJLBXtu46iUPw2PN .error-icon{fill:#552222;}#mermaid-svg-MJLBXtu46iUPw2PN .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-MJLBXtu46iUPw2PN .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-MJLBXtu46iUPw2PN .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-MJLBXtu46iUPw2PN .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-MJLBXtu46iUPw2PN .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-MJLBXtu46iUPw2PN .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-MJLBXtu46iUPw2PN .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-MJLBXtu46iUPw2PN .marker{fill:#333333;stroke:#333333;}#mermaid-svg-MJLBXtu46iUPw2PN .marker.cross{stroke:#333333;}#mermaid-svg-MJLBXtu46iUPw2PN svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-MJLBXtu46iUPw2PN p{margin:0;}#mermaid-svg-MJLBXtu46iUPw2PN .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-MJLBXtu46iUPw2PN .cluster-label text{fill:#333;}#mermaid-svg-MJLBXtu46iUPw2PN .cluster-label span{color:#333;}#mermaid-svg-MJLBXtu46iUPw2PN .cluster-label span p{background-color:transparent;}#mermaid-svg-MJLBXtu46iUPw2PN .label text,#mermaid-svg-MJLBXtu46iUPw2PN span{fill:#333;color:#333;}#mermaid-svg-MJLBXtu46iUPw2PN .node rect,#mermaid-svg-MJLBXtu46iUPw2PN .node circle,#mermaid-svg-MJLBXtu46iUPw2PN .node ellipse,#mermaid-svg-MJLBXtu46iUPw2PN .node polygon,#mermaid-svg-MJLBXtu46iUPw2PN .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-MJLBXtu46iUPw2PN .rough-node .label text,#mermaid-svg-MJLBXtu46iUPw2PN .node .label text,#mermaid-svg-MJLBXtu46iUPw2PN .image-shape .label,#mermaid-svg-MJLBXtu46iUPw2PN .icon-shape .label{text-anchor:middle;}#mermaid-svg-MJLBXtu46iUPw2PN .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-MJLBXtu46iUPw2PN .rough-node .label,#mermaid-svg-MJLBXtu46iUPw2PN .node .label,#mermaid-svg-MJLBXtu46iUPw2PN .image-shape .label,#mermaid-svg-MJLBXtu46iUPw2PN .icon-shape .label{text-align:center;}#mermaid-svg-MJLBXtu46iUPw2PN .node.clickable{cursor:pointer;}#mermaid-svg-MJLBXtu46iUPw2PN .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-MJLBXtu46iUPw2PN .arrowheadPath{fill:#333333;}#mermaid-svg-MJLBXtu46iUPw2PN .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-MJLBXtu46iUPw2PN .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-MJLBXtu46iUPw2PN .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-MJLBXtu46iUPw2PN .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-MJLBXtu46iUPw2PN .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-MJLBXtu46iUPw2PN .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-MJLBXtu46iUPw2PN .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-MJLBXtu46iUPw2PN .cluster text{fill:#333;}#mermaid-svg-MJLBXtu46iUPw2PN .cluster span{color:#333;}#mermaid-svg-MJLBXtu46iUPw2PN div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-MJLBXtu46iUPw2PN .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-MJLBXtu46iUPw2PN rect.text{fill:none;stroke-width:0;}#mermaid-svg-MJLBXtu46iUPw2PN .icon-shape,#mermaid-svg-MJLBXtu46iUPw2PN .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-MJLBXtu46iUPw2PN .icon-shape p,#mermaid-svg-MJLBXtu46iUPw2PN .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-MJLBXtu46iUPw2PN .icon-shape .label rect,#mermaid-svg-MJLBXtu46iUPw2PN .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-MJLBXtu46iUPw2PN .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-MJLBXtu46iUPw2PN .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-MJLBXtu46iUPw2PN :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 项目根目录
src/
tests/
docs/
config/
scripts/
agent/
services/
utils/
types/
index.ts
core/
modules/
agents/
项目结构说明:
| 目录 | 用途 |
|---|---|
src/agent/ |
Agent核心代码 |
src/services/ |
外部服务调用 |
src/utils/ |
工具函数 |
src/types/ |
类型定义 |
tests/ |
测试代码 |
config/ |
配置文件 |
4.2 文件职责划分
#mermaid-svg-LMTukTA3zlqz2tJ5{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-LMTukTA3zlqz2tJ5 .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-LMTukTA3zlqz2tJ5 .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-LMTukTA3zlqz2tJ5 .error-icon{fill:#552222;}#mermaid-svg-LMTukTA3zlqz2tJ5 .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-LMTukTA3zlqz2tJ5 .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-LMTukTA3zlqz2tJ5 .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-LMTukTA3zlqz2tJ5 .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-LMTukTA3zlqz2tJ5 .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-LMTukTA3zlqz2tJ5 .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-LMTukTA3zlqz2tJ5 .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-LMTukTA3zlqz2tJ5 .marker{fill:#333333;stroke:#333333;}#mermaid-svg-LMTukTA3zlqz2tJ5 .marker.cross{stroke:#333333;}#mermaid-svg-LMTukTA3zlqz2tJ5 svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-LMTukTA3zlqz2tJ5 p{margin:0;}#mermaid-svg-LMTukTA3zlqz2tJ5 .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-LMTukTA3zlqz2tJ5 .cluster-label text{fill:#333;}#mermaid-svg-LMTukTA3zlqz2tJ5 .cluster-label span{color:#333;}#mermaid-svg-LMTukTA3zlqz2tJ5 .cluster-label span p{background-color:transparent;}#mermaid-svg-LMTukTA3zlqz2tJ5 .label text,#mermaid-svg-LMTukTA3zlqz2tJ5 span{fill:#333;color:#333;}#mermaid-svg-LMTukTA3zlqz2tJ5 .node rect,#mermaid-svg-LMTukTA3zlqz2tJ5 .node circle,#mermaid-svg-LMTukTA3zlqz2tJ5 .node ellipse,#mermaid-svg-LMTukTA3zlqz2tJ5 .node polygon,#mermaid-svg-LMTukTA3zlqz2tJ5 .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-LMTukTA3zlqz2tJ5 .rough-node .label text,#mermaid-svg-LMTukTA3zlqz2tJ5 .node .label text,#mermaid-svg-LMTukTA3zlqz2tJ5 .image-shape .label,#mermaid-svg-LMTukTA3zlqz2tJ5 .icon-shape .label{text-anchor:middle;}#mermaid-svg-LMTukTA3zlqz2tJ5 .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-LMTukTA3zlqz2tJ5 .rough-node .label,#mermaid-svg-LMTukTA3zlqz2tJ5 .node .label,#mermaid-svg-LMTukTA3zlqz2tJ5 .image-shape .label,#mermaid-svg-LMTukTA3zlqz2tJ5 .icon-shape .label{text-align:center;}#mermaid-svg-LMTukTA3zlqz2tJ5 .node.clickable{cursor:pointer;}#mermaid-svg-LMTukTA3zlqz2tJ5 .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-LMTukTA3zlqz2tJ5 .arrowheadPath{fill:#333333;}#mermaid-svg-LMTukTA3zlqz2tJ5 .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-LMTukTA3zlqz2tJ5 .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-LMTukTA3zlqz2tJ5 .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-LMTukTA3zlqz2tJ5 .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-LMTukTA3zlqz2tJ5 .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-LMTukTA3zlqz2tJ5 .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-LMTukTA3zlqz2tJ5 .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-LMTukTA3zlqz2tJ5 .cluster text{fill:#333;}#mermaid-svg-LMTukTA3zlqz2tJ5 .cluster span{color:#333;}#mermaid-svg-LMTukTA3zlqz2tJ5 div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-LMTukTA3zlqz2tJ5 .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-LMTukTA3zlqz2tJ5 rect.text{fill:none;stroke-width:0;}#mermaid-svg-LMTukTA3zlqz2tJ5 .icon-shape,#mermaid-svg-LMTukTA3zlqz2tJ5 .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-LMTukTA3zlqz2tJ5 .icon-shape p,#mermaid-svg-LMTukTA3zlqz2tJ5 .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-LMTukTA3zlqz2tJ5 .icon-shape .label rect,#mermaid-svg-LMTukTA3zlqz2tJ5 .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-LMTukTA3zlqz2tJ5 .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-LMTukTA3zlqz2tJ5 .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-LMTukTA3zlqz2tJ5 :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} Agent项目结构
agent/core/
agent/modules/
agent/agents/
Agent.ts
Memory.ts
Planning.ts
perception/
decision/
execution/
SimpleAgent.ts
ChatAgent.ts
ToolAgent.ts
五、配置管理
5.1 环境变量管理
#mermaid-svg-w1vSDDtD81Pnqb7n{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-w1vSDDtD81Pnqb7n .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-w1vSDDtD81Pnqb7n .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-w1vSDDtD81Pnqb7n .error-icon{fill:#552222;}#mermaid-svg-w1vSDDtD81Pnqb7n .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-w1vSDDtD81Pnqb7n .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-w1vSDDtD81Pnqb7n .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-w1vSDDtD81Pnqb7n .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-w1vSDDtD81Pnqb7n .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-w1vSDDtD81Pnqb7n .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-w1vSDDtD81Pnqb7n .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-w1vSDDtD81Pnqb7n .marker{fill:#333333;stroke:#333333;}#mermaid-svg-w1vSDDtD81Pnqb7n .marker.cross{stroke:#333333;}#mermaid-svg-w1vSDDtD81Pnqb7n svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-w1vSDDtD81Pnqb7n p{margin:0;}#mermaid-svg-w1vSDDtD81Pnqb7n .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-w1vSDDtD81Pnqb7n .cluster-label text{fill:#333;}#mermaid-svg-w1vSDDtD81Pnqb7n .cluster-label span{color:#333;}#mermaid-svg-w1vSDDtD81Pnqb7n .cluster-label span p{background-color:transparent;}#mermaid-svg-w1vSDDtD81Pnqb7n .label text,#mermaid-svg-w1vSDDtD81Pnqb7n span{fill:#333;color:#333;}#mermaid-svg-w1vSDDtD81Pnqb7n .node rect,#mermaid-svg-w1vSDDtD81Pnqb7n .node circle,#mermaid-svg-w1vSDDtD81Pnqb7n .node ellipse,#mermaid-svg-w1vSDDtD81Pnqb7n .node polygon,#mermaid-svg-w1vSDDtD81Pnqb7n .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-w1vSDDtD81Pnqb7n .rough-node .label text,#mermaid-svg-w1vSDDtD81Pnqb7n .node .label text,#mermaid-svg-w1vSDDtD81Pnqb7n .image-shape .label,#mermaid-svg-w1vSDDtD81Pnqb7n .icon-shape .label{text-anchor:middle;}#mermaid-svg-w1vSDDtD81Pnqb7n .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-w1vSDDtD81Pnqb7n .rough-node .label,#mermaid-svg-w1vSDDtD81Pnqb7n .node .label,#mermaid-svg-w1vSDDtD81Pnqb7n .image-shape .label,#mermaid-svg-w1vSDDtD81Pnqb7n .icon-shape .label{text-align:center;}#mermaid-svg-w1vSDDtD81Pnqb7n .node.clickable{cursor:pointer;}#mermaid-svg-w1vSDDtD81Pnqb7n .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-w1vSDDtD81Pnqb7n .arrowheadPath{fill:#333333;}#mermaid-svg-w1vSDDtD81Pnqb7n .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-w1vSDDtD81Pnqb7n .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-w1vSDDtD81Pnqb7n .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-w1vSDDtD81Pnqb7n .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-w1vSDDtD81Pnqb7n .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-w1vSDDtD81Pnqb7n .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-w1vSDDtD81Pnqb7n .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-w1vSDDtD81Pnqb7n .cluster text{fill:#333;}#mermaid-svg-w1vSDDtD81Pnqb7n .cluster span{color:#333;}#mermaid-svg-w1vSDDtD81Pnqb7n div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-w1vSDDtD81Pnqb7n .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-w1vSDDtD81Pnqb7n rect.text{fill:none;stroke-width:0;}#mermaid-svg-w1vSDDtD81Pnqb7n .icon-shape,#mermaid-svg-w1vSDDtD81Pnqb7n .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-w1vSDDtD81Pnqb7n .icon-shape p,#mermaid-svg-w1vSDDtD81Pnqb7n .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-w1vSDDtD81Pnqb7n .icon-shape .label rect,#mermaid-svg-w1vSDDtD81Pnqb7n .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-w1vSDDtD81Pnqb7n .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-w1vSDDtD81Pnqb7n .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-w1vSDDtD81Pnqb7n :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 配置管理
.env文件
配置类
配置验证
API密钥
数据库连接
服务地址
加载配置
类型安全
必填检查
格式验证
.env文件示例:
env
# OpenAI配置
OPENAI_API_KEY=your-api-key-here
OPENAI_MODEL=gpt-4-turbo
# 服务配置
PORT=3000
HOST=localhost
# 数据库配置
DB_HOST=localhost
DB_PORT=5432
DB_NAME=agent_db
5.2 配置加载代码
Python示例:
python
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
openai_api_key: str
openai_model: str = "gpt-4-turbo"
port: int = 3000
model_config = SettingsConfigDict(env_file=".env")
settings = Settings()
TypeScript示例:
typescript
import * as dotenv from 'dotenv';
import { z } from 'zod';
dotenv.config();
const envSchema = z.object({
OPENAI_API_KEY: z.string(),
OPENAI_MODEL: z.string().default('gpt-4-turbo'),
PORT: z.coerce.number().default(3000),
});
export const env = envSchema.parse(process.env);
六、依赖注入与模块化
6.1 依赖注入模式
#mermaid-svg-Uh5znU2R7u0cZiBI{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-Uh5znU2R7u0cZiBI .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-Uh5znU2R7u0cZiBI .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-Uh5znU2R7u0cZiBI .error-icon{fill:#552222;}#mermaid-svg-Uh5znU2R7u0cZiBI .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-Uh5znU2R7u0cZiBI .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-Uh5znU2R7u0cZiBI .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-Uh5znU2R7u0cZiBI .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-Uh5znU2R7u0cZiBI .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-Uh5znU2R7u0cZiBI .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-Uh5znU2R7u0cZiBI .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-Uh5znU2R7u0cZiBI .marker{fill:#333333;stroke:#333333;}#mermaid-svg-Uh5znU2R7u0cZiBI .marker.cross{stroke:#333333;}#mermaid-svg-Uh5znU2R7u0cZiBI svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-Uh5znU2R7u0cZiBI p{margin:0;}#mermaid-svg-Uh5znU2R7u0cZiBI .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-Uh5znU2R7u0cZiBI .cluster-label text{fill:#333;}#mermaid-svg-Uh5znU2R7u0cZiBI .cluster-label span{color:#333;}#mermaid-svg-Uh5znU2R7u0cZiBI .cluster-label span p{background-color:transparent;}#mermaid-svg-Uh5znU2R7u0cZiBI .label text,#mermaid-svg-Uh5znU2R7u0cZiBI span{fill:#333;color:#333;}#mermaid-svg-Uh5znU2R7u0cZiBI .node rect,#mermaid-svg-Uh5znU2R7u0cZiBI .node circle,#mermaid-svg-Uh5znU2R7u0cZiBI .node ellipse,#mermaid-svg-Uh5znU2R7u0cZiBI .node polygon,#mermaid-svg-Uh5znU2R7u0cZiBI .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-Uh5znU2R7u0cZiBI .rough-node .label text,#mermaid-svg-Uh5znU2R7u0cZiBI .node .label text,#mermaid-svg-Uh5znU2R7u0cZiBI .image-shape .label,#mermaid-svg-Uh5znU2R7u0cZiBI .icon-shape .label{text-anchor:middle;}#mermaid-svg-Uh5znU2R7u0cZiBI .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-Uh5znU2R7u0cZiBI .rough-node .label,#mermaid-svg-Uh5znU2R7u0cZiBI .node .label,#mermaid-svg-Uh5znU2R7u0cZiBI .image-shape .label,#mermaid-svg-Uh5znU2R7u0cZiBI .icon-shape .label{text-align:center;}#mermaid-svg-Uh5znU2R7u0cZiBI .node.clickable{cursor:pointer;}#mermaid-svg-Uh5znU2R7u0cZiBI .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-Uh5znU2R7u0cZiBI .arrowheadPath{fill:#333333;}#mermaid-svg-Uh5znU2R7u0cZiBI .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-Uh5znU2R7u0cZiBI .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-Uh5znU2R7u0cZiBI .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-Uh5znU2R7u0cZiBI .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-Uh5znU2R7u0cZiBI .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-Uh5znU2R7u0cZiBI .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-Uh5znU2R7u0cZiBI .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-Uh5znU2R7u0cZiBI .cluster text{fill:#333;}#mermaid-svg-Uh5znU2R7u0cZiBI .cluster span{color:#333;}#mermaid-svg-Uh5znU2R7u0cZiBI div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-Uh5znU2R7u0cZiBI .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-Uh5znU2R7u0cZiBI rect.text{fill:none;stroke-width:0;}#mermaid-svg-Uh5znU2R7u0cZiBI .icon-shape,#mermaid-svg-Uh5znU2R7u0cZiBI .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-Uh5znU2R7u0cZiBI .icon-shape p,#mermaid-svg-Uh5znU2R7u0cZiBI .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-Uh5znU2R7u0cZiBI .icon-shape .label rect,#mermaid-svg-Uh5znU2R7u0cZiBI .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-Uh5znU2R7u0cZiBI .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-Uh5znU2R7u0cZiBI .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-Uh5znU2R7u0cZiBI :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 依赖注入
容器
服务注册
服务获取
管理依赖
生命周期
单例注册
工厂注册
自动注入
按需获取
6.2 模块化设计原则
#mermaid-svg-tS6NxdsSqyaRuLbZ{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-tS6NxdsSqyaRuLbZ .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-tS6NxdsSqyaRuLbZ .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-tS6NxdsSqyaRuLbZ .error-icon{fill:#552222;}#mermaid-svg-tS6NxdsSqyaRuLbZ .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-tS6NxdsSqyaRuLbZ .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-tS6NxdsSqyaRuLbZ .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-tS6NxdsSqyaRuLbZ .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-tS6NxdsSqyaRuLbZ .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-tS6NxdsSqyaRuLbZ .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-tS6NxdsSqyaRuLbZ .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-tS6NxdsSqyaRuLbZ .marker{fill:#333333;stroke:#333333;}#mermaid-svg-tS6NxdsSqyaRuLbZ .marker.cross{stroke:#333333;}#mermaid-svg-tS6NxdsSqyaRuLbZ svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-tS6NxdsSqyaRuLbZ p{margin:0;}#mermaid-svg-tS6NxdsSqyaRuLbZ .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-tS6NxdsSqyaRuLbZ .cluster-label text{fill:#333;}#mermaid-svg-tS6NxdsSqyaRuLbZ .cluster-label span{color:#333;}#mermaid-svg-tS6NxdsSqyaRuLbZ .cluster-label span p{background-color:transparent;}#mermaid-svg-tS6NxdsSqyaRuLbZ .label text,#mermaid-svg-tS6NxdsSqyaRuLbZ span{fill:#333;color:#333;}#mermaid-svg-tS6NxdsSqyaRuLbZ .node rect,#mermaid-svg-tS6NxdsSqyaRuLbZ .node circle,#mermaid-svg-tS6NxdsSqyaRuLbZ .node ellipse,#mermaid-svg-tS6NxdsSqyaRuLbZ .node polygon,#mermaid-svg-tS6NxdsSqyaRuLbZ .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-tS6NxdsSqyaRuLbZ .rough-node .label text,#mermaid-svg-tS6NxdsSqyaRuLbZ .node .label text,#mermaid-svg-tS6NxdsSqyaRuLbZ .image-shape .label,#mermaid-svg-tS6NxdsSqyaRuLbZ .icon-shape .label{text-anchor:middle;}#mermaid-svg-tS6NxdsSqyaRuLbZ .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-tS6NxdsSqyaRuLbZ .rough-node .label,#mermaid-svg-tS6NxdsSqyaRuLbZ .node .label,#mermaid-svg-tS6NxdsSqyaRuLbZ .image-shape .label,#mermaid-svg-tS6NxdsSqyaRuLbZ .icon-shape .label{text-align:center;}#mermaid-svg-tS6NxdsSqyaRuLbZ .node.clickable{cursor:pointer;}#mermaid-svg-tS6NxdsSqyaRuLbZ .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-tS6NxdsSqyaRuLbZ .arrowheadPath{fill:#333333;}#mermaid-svg-tS6NxdsSqyaRuLbZ .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-tS6NxdsSqyaRuLbZ .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-tS6NxdsSqyaRuLbZ .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-tS6NxdsSqyaRuLbZ .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-tS6NxdsSqyaRuLbZ .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-tS6NxdsSqyaRuLbZ .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-tS6NxdsSqyaRuLbZ .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-tS6NxdsSqyaRuLbZ .cluster text{fill:#333;}#mermaid-svg-tS6NxdsSqyaRuLbZ .cluster span{color:#333;}#mermaid-svg-tS6NxdsSqyaRuLbZ div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-tS6NxdsSqyaRuLbZ .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-tS6NxdsSqyaRuLbZ rect.text{fill:none;stroke-width:0;}#mermaid-svg-tS6NxdsSqyaRuLbZ .icon-shape,#mermaid-svg-tS6NxdsSqyaRuLbZ .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-tS6NxdsSqyaRuLbZ .icon-shape p,#mermaid-svg-tS6NxdsSqyaRuLbZ .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-tS6NxdsSqyaRuLbZ .icon-shape .label rect,#mermaid-svg-tS6NxdsSqyaRuLbZ .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-tS6NxdsSqyaRuLbZ .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-tS6NxdsSqyaRuLbZ .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-tS6NxdsSqyaRuLbZ :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 模块化设计
高内聚低耦合
单一职责
接口抽象
功能独立
易于维护
一个类一个职责
清晰边界
依赖接口
便于测试
七、测试环境配置
7.1 测试框架选择
| 框架 | 语言 | 特点 |
|---|---|---|
| pytest | Python | 简洁、插件丰富 |
| Jest | TypeScript | 功能强大、速度快 |
| pytest-asyncio | Python | 异步测试支持 |
| Vitest | TypeScript | 快速、现代化 |
7.2 测试配置
pytest配置文件(pytest.ini):
ini
[pytest]
testpaths = ["tests"]
pythonpath = ["src"]
asyncio_mode = auto
测试目录结构:
tests/
├── unit/ # 单元测试
├── integration/ # 集成测试
└── e2e/ # 端到端测试
八、开发环境验证
8.1 验证步骤
#mermaid-svg-mJSOw3XUQSmjlMue{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}@keyframes edge-animation-frame{from{stroke-dashoffset:0;}}@keyframes dash{to{stroke-dashoffset:0;}}#mermaid-svg-mJSOw3XUQSmjlMue .edge-animation-slow{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 50s linear infinite;stroke-linecap:round;}#mermaid-svg-mJSOw3XUQSmjlMue .edge-animation-fast{stroke-dasharray:9,5!important;stroke-dashoffset:900;animation:dash 20s linear infinite;stroke-linecap:round;}#mermaid-svg-mJSOw3XUQSmjlMue .error-icon{fill:#552222;}#mermaid-svg-mJSOw3XUQSmjlMue .error-text{fill:#552222;stroke:#552222;}#mermaid-svg-mJSOw3XUQSmjlMue .edge-thickness-normal{stroke-width:1px;}#mermaid-svg-mJSOw3XUQSmjlMue .edge-thickness-thick{stroke-width:3.5px;}#mermaid-svg-mJSOw3XUQSmjlMue .edge-pattern-solid{stroke-dasharray:0;}#mermaid-svg-mJSOw3XUQSmjlMue .edge-thickness-invisible{stroke-width:0;fill:none;}#mermaid-svg-mJSOw3XUQSmjlMue .edge-pattern-dashed{stroke-dasharray:3;}#mermaid-svg-mJSOw3XUQSmjlMue .edge-pattern-dotted{stroke-dasharray:2;}#mermaid-svg-mJSOw3XUQSmjlMue .marker{fill:#333333;stroke:#333333;}#mermaid-svg-mJSOw3XUQSmjlMue .marker.cross{stroke:#333333;}#mermaid-svg-mJSOw3XUQSmjlMue svg{font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;}#mermaid-svg-mJSOw3XUQSmjlMue p{margin:0;}#mermaid-svg-mJSOw3XUQSmjlMue .label{font-family:"trebuchet ms",verdana,arial,sans-serif;color:#333;}#mermaid-svg-mJSOw3XUQSmjlMue .cluster-label text{fill:#333;}#mermaid-svg-mJSOw3XUQSmjlMue .cluster-label span{color:#333;}#mermaid-svg-mJSOw3XUQSmjlMue .cluster-label span p{background-color:transparent;}#mermaid-svg-mJSOw3XUQSmjlMue .label text,#mermaid-svg-mJSOw3XUQSmjlMue span{fill:#333;color:#333;}#mermaid-svg-mJSOw3XUQSmjlMue .node rect,#mermaid-svg-mJSOw3XUQSmjlMue .node circle,#mermaid-svg-mJSOw3XUQSmjlMue .node ellipse,#mermaid-svg-mJSOw3XUQSmjlMue .node polygon,#mermaid-svg-mJSOw3XUQSmjlMue .node path{fill:#ECECFF;stroke:#9370DB;stroke-width:1px;}#mermaid-svg-mJSOw3XUQSmjlMue .rough-node .label text,#mermaid-svg-mJSOw3XUQSmjlMue .node .label text,#mermaid-svg-mJSOw3XUQSmjlMue .image-shape .label,#mermaid-svg-mJSOw3XUQSmjlMue .icon-shape .label{text-anchor:middle;}#mermaid-svg-mJSOw3XUQSmjlMue .node .katex path{fill:#000;stroke:#000;stroke-width:1px;}#mermaid-svg-mJSOw3XUQSmjlMue .rough-node .label,#mermaid-svg-mJSOw3XUQSmjlMue .node .label,#mermaid-svg-mJSOw3XUQSmjlMue .image-shape .label,#mermaid-svg-mJSOw3XUQSmjlMue .icon-shape .label{text-align:center;}#mermaid-svg-mJSOw3XUQSmjlMue .node.clickable{cursor:pointer;}#mermaid-svg-mJSOw3XUQSmjlMue .root .anchor path{fill:#333333!important;stroke-width:0;stroke:#333333;}#mermaid-svg-mJSOw3XUQSmjlMue .arrowheadPath{fill:#333333;}#mermaid-svg-mJSOw3XUQSmjlMue .edgePath .path{stroke:#333333;stroke-width:2.0px;}#mermaid-svg-mJSOw3XUQSmjlMue .flowchart-link{stroke:#333333;fill:none;}#mermaid-svg-mJSOw3XUQSmjlMue .edgeLabel{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-mJSOw3XUQSmjlMue .edgeLabel p{background-color:rgba(232,232,232, 0.8);}#mermaid-svg-mJSOw3XUQSmjlMue .edgeLabel rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-mJSOw3XUQSmjlMue .labelBkg{background-color:rgba(232, 232, 232, 0.5);}#mermaid-svg-mJSOw3XUQSmjlMue .cluster rect{fill:#ffffde;stroke:#aaaa33;stroke-width:1px;}#mermaid-svg-mJSOw3XUQSmjlMue .cluster text{fill:#333;}#mermaid-svg-mJSOw3XUQSmjlMue .cluster span{color:#333;}#mermaid-svg-mJSOw3XUQSmjlMue div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:12px;background:hsl(80, 100%, 96.2745098039%);border:1px solid #aaaa33;border-radius:2px;pointer-events:none;z-index:100;}#mermaid-svg-mJSOw3XUQSmjlMue .flowchartTitleText{text-anchor:middle;font-size:18px;fill:#333;}#mermaid-svg-mJSOw3XUQSmjlMue rect.text{fill:none;stroke-width:0;}#mermaid-svg-mJSOw3XUQSmjlMue .icon-shape,#mermaid-svg-mJSOw3XUQSmjlMue .image-shape{background-color:rgba(232,232,232, 0.8);text-align:center;}#mermaid-svg-mJSOw3XUQSmjlMue .icon-shape p,#mermaid-svg-mJSOw3XUQSmjlMue .image-shape p{background-color:rgba(232,232,232, 0.8);padding:2px;}#mermaid-svg-mJSOw3XUQSmjlMue .icon-shape .label rect,#mermaid-svg-mJSOw3XUQSmjlMue .image-shape .label rect{opacity:0.5;background-color:rgba(232,232,232, 0.8);fill:rgba(232,232,232, 0.8);}#mermaid-svg-mJSOw3XUQSmjlMue .label-icon{display:inline-block;height:1em;overflow:visible;vertical-align:-0.125em;}#mermaid-svg-mJSOw3XUQSmjlMue .node .label-icon path{fill:currentColor;stroke:revert;stroke-width:revert;}#mermaid-svg-mJSOw3XUQSmjlMue :root{--mermaid-font-family:"trebuchet ms",verdana,arial,sans-serif;} 环境验证
依赖检查
代码检查
测试运行
服务启动
pip/npm install
lint检查
pytest/jest
启动服务
8.2 验证脚本
package.json脚本示例:
json
{
"scripts": {
"start": "node dist/index.js",
"build": "tsc",
"dev": "ts-node src/index.ts",
"test": "jest",
"lint": "eslint src/",
"format": "prettier --write src/"
}
}
九、Docker容器化配置
9.1 Dockerfile示例
dockerfile
FROM node:20-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY dist/ ./dist/
EXPOSE 3000
CMD ["node", "dist/index.js"]
9.2 docker-compose.yml示例
yaml
version: '3.8'
services:
agent:
build: .
ports:
- "3000:3000"
env_file:
- .env
restart: unless-stopped
十、总结与下一步
10.1 本文总结
本文介绍了Agent开发环境的搭建:
- 开发工具选择:编程语言、编辑器、容器化工具
- Python环境配置:安装、虚拟环境、依赖管理
- TypeScript环境配置:Node.js、TypeScript配置
- 项目结构设计:模块化架构
- 配置管理:环境变量、配置验证
- 测试环境:测试框架配置
- 容器化:Docker配置
10.2 下一步
下一篇文章将介绍如何实现第一个简单的Agent。
