安装¶
AgentScope Java 支持多种大模型供应商、RAG 后端和扩展功能,每种都需要不同的第三方 SDK。如果将所有依赖打包在一起,您的项目将被大量可能永远用不到的依赖拖累——增加 JAR 体积、拖慢构建速度,还可能引发版本冲突。
为了平衡易用性和依赖控制,我们提供两种方式:
All-in-one:单一依赖,内置合理的默认配置(DashScope SDK、MCP SDK)。适合快速上手,按需添加额外依赖即可。
Core + 扩展:从最小化的核心包开始,只添加实际使用的扩展模块。适合对依赖有严格要求的生产环境。
我们的建议: 快速开发时使用 all-in-one。当需要优化依赖体积或解决冲突时,再切换到 core + 扩展方式。
未来规划: 我们正在将模型供应商 SDK 替换为原生 HTTP 实现。这将大幅减少外部依赖,同时保持对所有已支持模型的完全兼容。
AgentScope Java 需要 JDK 17 或更高版本。
依赖选择¶
AgentScope Java 提供两种依赖方式:
方式 |
适用场景 |
特点 |
|---|---|---|
all-in-one |
快速开始、大多数用户 |
单一依赖,默认传递 DashScope SDK |
core + 扩展 |
需要精细控制依赖 |
按需引入,减少不必要的依赖 |
方式一:All-in-One(推荐)¶
Maven:
<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope</artifactId>
<version>1.0.1</version>
</dependency>
Gradle:
implementation 'io.agentscope:agentscope:1.0.1'
默认传递的依赖¶
All-in-one 包默认传递以下依赖,无需额外配置:
DashScope SDK(通义千问系列模型)
MCP SDK(模型上下文协议)
Reactor Core、Jackson、SLF4J(基础框架)
额外功能所需依赖¶
使用其他模型或扩展功能时,需要手动添加对应依赖:
功能 |
所需依赖 |
Maven 坐标 |
|---|---|---|
OpenAI 模型 |
|
|
Google Gemini 模型 |
|
|
Anthropic 模型 |
|
|
Mem0 长期记忆 |
|
|
百炼 RAG |
|
|
Qdrant RAG |
|
|
PDF 文档处理 |
|
|
Word 文档处理 |
|
示例:使用 OpenAI 模型¶
<!-- 在 agentscope 基础上添加 -->
<dependency>
<groupId>com.openai</groupId>
<artifactId>openai-java</artifactId>
</dependency>
示例:使用 Qdrant RAG + PDF 处理¶
<!-- 在 agentscope 基础上添加 -->
<dependency>
<groupId>io.qdrant</groupId>
<artifactId>client</artifactId>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
</dependency>
Studio 集成¶
集成 AgentScope Studio 实现可视化和调试,需要添加以下依赖:
所需依赖 |
Maven 坐标 |
|---|---|
|
|
|
|
|
|
|
|
|
完整配置:
<!-- 在 agentscope 基础上添加 -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>io.socket</groupId>
<artifactId>socket.io-client</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-reactor-3.1</artifactId>
</dependency>
方式二:Core + 扩展¶
如果您需要更精细地控制依赖,可以使用 agentscope-core 配合扩展模块:
Maven:
<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-core</artifactId>
<version>1.0.1</version>
</dependency>
Gradle:
implementation 'io.agentscope:agentscope-core:1.0.1'
扩展模块¶
模块 |
功能 |
Maven 坐标 |
|---|---|---|
Mem0 长期记忆 |
|
|
百炼知识库 RAG |
|
|
Qdrant 向量检索 RAG |
|
|
AgentScope Studio 集成 |
|
扩展模块会自动传递所需的第三方依赖,无需手动添加。
示例:Core + Mem0 扩展¶
<!-- 在 agentscope-core 基础上添加 -->
<dependency>
<groupId>io.agentscope</groupId>
<artifactId>agentscope-extensions-mem0</artifactId>
<version>1.0.1</version>
</dependency>