跳到正文
Skillpedia
API 与服务器(后端)6.2k · #14380

agentscope-java

它能做什么

这项技能是使用 AgentScope 框架构建智能体的 Java 指南。适合构建 LLM 智能体、工具调用和多智能体系统的 Java 开发者。

适用场景

  • ✓当你想用 AgentScope 框架编写 Java 智能体时。
  • ✓当你需要把语言模型或工具连接到 AgentScope 智能体时。
  • ✓当你想用响应式 Java 代码构建多智能体系统的时候。

技能链接

https://github.com/agentscope-ai/agentscope-java/blob/main/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/agentscope-ai/agentscope-java/blob/main/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“请编写一个使用天气工具和 DashScope 模型的 Java AgentScope ReAct 智能体,并包含错误处理。”

每周 5 个新技能,1 分钟读完。

工作原理

这项技能为智能体提供 AgentScope 的规则和正确的 API 用法,例如使用响应式类型,并从环境变量中读取密钥。然后智能体会按照这些用法编写 Java 代码。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

When the user asks you to write AgentScope Java code, follow these instructions carefully.

CRITICAL RULES - NEVER VIOLATE THESE

🚫 ABSOLUTELY FORBIDDEN:

  1. NEVER use .block() in example code - This is the #1 mistake. Only use .block() in main() methods or test code when explicitly creating a runnable example.
  2. NEVER use Thread.sleep() - Use Mono.delay() instead.
  3. NEVER use ThreadLocal - Use Reactor Context with Mono.deferContextual().
  4. NEVER hardcode API keys - Always use System.getenv().
  5. NEVER ignore errors silently - Always log errors and provide fallback values.
  6. NEVER use wrong import paths - Shared model interfaces are in io.agentscope.core.model.*; provider models are in io.agentscope.extensions.model.<provider>.*.

✅ ALWAYS DO:

  1. Use Mono and Flux for all asynchronous operations.
  2. Chain operations with .map(), .flatMap(), .then().
  3. Use Builder pattern for creating agents, models, and messages.
  4. Include error handling with .onErrorResume() or .onErrorReturn().
  5. Add logging with SLF4J for important operations.
  6. Use correct imports: import io.agentscope.extensions.model.dashscope.DashScopeChatModel;
  7. Use correct APIs (many methods don't exist or have changed):
    • toolkit.registerTool() NOT registerObject()
    • toolkit.getToolNames() NOT getTools()
    • event.getToolUse().getName() NOT getToolName()
    • result.getOutput() NOT getContent() (ToolResultBlock)
    • event.getToolResult() NOT getResult() (PostActingEvent)
    • toolUse.getInput() NOT getArguments() (ToolUseBlock)
    • Model builder: NO temperature() method, use defaultOptions(GenerateOptions.builder()...)
    • Hook events: NO getMessages(), getResponse(), getIterationCount(), getThinkingBlock() methods
    • ToolResultBlock: NO getToolUseName() method, use event.getToolUse().getName() instead
    • ToolResultBlock.getOutput() returns List<ContentBlock> NOT String, need to convert
    • @ToolParam format: MUST use @ToolParam(name = "x", description = "y") NOT @ToolParam(name="x")

WHEN GENERATING CODE

FIRST: Identify the context

  • Is this a main() method or test code? → .block() is allowed (but add a warning comment)
  • Is this agent logic, service method, or library code? → .block() is FORBIDDEN

For every code example you provide:

  1. Check: Does it use .block()? → If yes in non-main/non-test code, REWRITE IT.
  2. Check: Are all operations non-blocking? → If no, FIX IT.
  3. Check: Does it have error handling? → If no, ADD IT.
  4. Check: Are API keys from environment? → If no, CHANGE IT.
  5. Check: Are imports correct? → If using provider models from io.agentscope.core.model.*, FIX TO io.agentscope.extensions.model.<provider>.*.

Default code structure for agent logic:

// ✅ CORRECT - Non-blocking, reactive (use this pattern by default)
return model.generate(messages, null, null)
    .map(response -> processResponse(response))
    .onErrorResume(e -> {
        log.error("Operation failed", e);
        return Mono.just(fallbackValue);
    });

// ❌ WRONG - Never generate this in agent logic
String result = model.generate(messages, null, null).block(); // DON'T DO THIS

Only for main() methods (add warning comment):

public static void main(String[] args) {
    // ⚠️ .block() is ONLY allowed here because this is a main() method
    Msg response = agent.call(userMsg).block();
    System.out.println(response.getTextContent());
}

PROJECT SETUP

When creating a new AgentScope project, use the correct Maven dependencies:

Maven Configuration (pom.xml)

For production use (recommended):

<properties>
    <java.version>17</java.version>
</properties>

<dependencies>
    <!-- Use the latest stable release from Maven Central -->
    <dependency>
        <groupId>io.agentscope</groupId>
        <artifactId>agentscope</artifactId>
        <version>1.0.12</version>
    </dependency>
</dependencies>

For local development (if working with source code):

<properties>
    <agentscope.version>1.0.12</agentscope.version>
    <java.version>17</java.version>
</properties>

<dependencies>
    <dependency>
        <groupId>io.agentscope</groupId>
        <artifactId>agentscope-core</artifactId>
        <version>${agentscope.version}</version>
    </dependency>
    <dependency>
        <
常见问题

什么是 AgentScope?

AgentScope 是一个基于 Project Reactor、用于 Java 多智能体系统的框架。

API 密钥应该放在哪里?

技能规定应从环境变量中读取密钥,绝不把密钥写进代码。

它涵盖工具和钩子吗?

涵盖。描述中提到工具集成和钩子。

详情

作者的原始描述

Expert Java developer skill for AgentScope Java framework - a reactive, message-driven multi-agent system built on Project Reactor. Use when working with reactive programming, LLM integration, agent orchestration, multi-agent systems, or when the user mentions AgentScope, ReActAgent, Mono/Flux, Project Reactor, or Java agent development. Specializes in non-blocking code, tool integration, hooks, pipelines, and production-ready agent applications.

repo: agentscope-ai/agentscope-java

热度

GitHub 星标
6.2k
排名
#14380
许可证
Apache-2.0
更新时间
2026/11/2

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能