Skip to content

Commit 5fdc1b5

Browse files
committed
deploy: 094c9ae
1 parent 0aee561 commit 5fdc1b5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+3986
-43
lines changed

_sources/en/intro.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,16 @@ Once you're familiar with the basics, explore these features:
111111

112112
## AI-Powered Development
113113

114-
AgentScope provides an LLM-friendly guide for AI code assistants like Cursor, Windsurf, and GitHub Copilot. This guide helps AI assistants understand AgentScope Java's APIs, patterns, and best practices to generate accurate code.
114+
AgentScope documentation supports the [`llms.txt` standard](https://llmstxt.org/), enabling AI coding assistants like Claude Code, Cursor, and Windsurf to understand AgentScope APIs and generate accurate code.
115115

116116
**Quick Setup for Cursor:**
117117

118118
1. Open Cursor Settings -> Features -> Docs
119119
2. Click "+ Add new Doc"
120120
3. Add URL: `https://java.agentscope.io/llms-full.txt`
121121

122+
For other tools and detailed configuration, see **[Coding with AI](task/ai-coding.md)**.
123+
122124
## Community
123125

124126
- **GitHub**: [agentscope-ai/agentscope-java](https://github.com/agentscope-ai/agentscope-java)

_sources/en/quickstart/key-concepts.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ Message is the most fundamental data structure in AgentScope, used for:
8585
- `ToolUseBlock` - Tool invocation initiated by LLM
8686
- `ToolResultBlock` - Tool execution result
8787

88+
**Response Metadata**:
89+
90+
Messages returned by Agent contain additional metadata to help understand execution state:
91+
92+
| Method | Description |
93+
|--------|-------------|
94+
| `getGenerateReason()` | Reason for message generation, used to determine next actions |
95+
| `getChatUsage()` | Token usage statistics (input/output tokens, time) |
96+
97+
**GenerateReason Values**:
98+
99+
| Value | Description |
100+
|-------|-------------|
101+
| `MODEL_STOP` | Task completed normally |
102+
| `TOOL_SUSPENDED` | Tool needs external execution, waiting for result |
103+
| `REASONING_STOP_REQUESTED` | Paused by Hook during Reasoning phase (HITL) |
104+
| `ACTING_STOP_REQUESTED` | Paused by Hook during Acting phase (HITL) |
105+
| `INTERRUPTED` | Agent was interrupted |
106+
| `MAX_ITERATIONS` | Maximum iterations reached |
107+
88108
**Example**:
89109

90110
```java

_sources/en/task/ai-coding.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Coding with AI
2+
3+
AgentScope Java documentation supports the [`llms.txt` standard](https://llmstxt.org/), providing a machine-readable index optimized for Large Language Models. This allows you to use the documentation as context in your AI-powered development environment.
4+
5+
## What is llms.txt?
6+
7+
`llms.txt` is a standardized text file that acts as a map for LLMs, listing the most important documentation pages and their descriptions. This helps AI tools understand the structure of the documentation and retrieve relevant information.
8+
9+
AgentScope provides the following files:
10+
11+
| File | Best For | URL |
12+
|------|----------|-----|
13+
| `llms.txt` | Tools that can fetch links dynamically | `https://java.agentscope.io/llms.txt` |
14+
| `llms-full.txt` | Tools that need a single, static text dump | `https://java.agentscope.io/llms-full.txt` |
15+
16+
## Development Tools
17+
18+
### Claude Code
19+
20+
[Claude Code](https://docs.anthropic.com/en/docs/claude-code) can be configured to query the AgentScope documentation by adding an MCP server.
21+
22+
**Installation:**
23+
24+
```bash
25+
claude mcp add agentscope-docs -- uvx --from mcpdoc mcpdoc --urls AgentScopeJava:https://java.agentscope.io/llms.txt
26+
```
27+
28+
**Usage:**
29+
30+
Once installed, you can ask questions about AgentScope directly in Claude Code:
31+
32+
> How do I create a tool with AgentScope Java?
33+
34+
### Cursor
35+
36+
[Cursor](https://cursor.com/) IDE can be configured to access the AgentScope documentation in two ways.
37+
38+
**Method 1: Docs Feature (Recommended)**
39+
40+
1. Open **Cursor Settings** -> **Features** -> **Docs**
41+
2. Click **+ Add new Doc**
42+
3. Add URL: `https://java.agentscope.io/llms-full.txt`
43+
44+
**Method 2: MCP Server**
45+
46+
1. Open **Cursor Settings** -> **Tools & MCP**
47+
2. Click **New MCP Server** to edit `mcp.json`
48+
3. Add the following configuration:
49+
50+
```json
51+
{
52+
"mcpServers": {
53+
"agentscope-docs": {
54+
"command": "uvx",
55+
"args": [
56+
"--from", "mcpdoc", "mcpdoc",
57+
"--urls", "AgentScopeJava:https://java.agentscope.io/llms.txt"
58+
]
59+
}
60+
}
61+
}
62+
```
63+
64+
**Usage:**
65+
66+
Once configured, you can prompt the coding agent:
67+
68+
> Use the AgentScope docs to build a ReActAgent with a weather tool.
69+
70+
### Windsurf
71+
72+
[Windsurf](https://codeium.com/windsurf) supports MCP servers for documentation access.
73+
74+
**Configuration:**
75+
76+
1. Open Windsurf Settings
77+
2. Navigate to MCP configuration
78+
3. Add the following server:
79+
80+
```json
81+
{
82+
"mcpServers": {
83+
"agentscope-docs": {
84+
"command": "uvx",
85+
"args": [
86+
"--from", "mcpdoc", "mcpdoc",
87+
"--urls", "AgentScopeJava:https://java.agentscope.io/llms.txt"
88+
]
89+
}
90+
}
91+
}
92+
```
93+
94+
### Other Tools
95+
96+
Any tool that supports the `llms.txt` standard or can ingest documentation from a URL can benefit from these files.
97+
98+
**For tools with Docs/Knowledge Base feature:**
99+
- Add URL: `https://java.agentscope.io/llms-full.txt`
100+
101+
**For tools with MCP support:**
102+
- Use the MCP configuration template above with `mcpdoc`
103+
104+
**Prerequisites:**
105+
106+
MCP configurations require [`uv`](https://docs.astral.sh/uv/) to be installed, as they use `uvx` to run the documentation server.

_sources/en/task/hitl.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Human-in-the-Loop
2+
3+
Human-in-the-Loop lets you insert human review checkpoints during agent execution. When the agent is about to call tools, you can pause for user confirmation before proceeding.
4+
5+
## Two Pause Points
6+
7+
Agent execution has two phases: "reasoning" and "acting". You can pause at either point:
8+
9+
**Pause after reasoning**: After the model decides which tools to call, but before execution. You can see the tool names and parameters, letting users decide whether to allow execution.
10+
11+
**Pause after acting**: After tool execution completes, but before the next reasoning iteration. You can see the results, letting users decide whether to continue.
12+
13+
## Example: Confirming Sensitive Operations
14+
15+
This example shows how to require user confirmation before executing sensitive operations like deleting files or sending emails:
16+
17+
```java
18+
// 1. Create confirmation hook
19+
Hook confirmationHook = new Hook() {
20+
private static final List<String> SENSITIVE_TOOLS = List.of("delete_file", "send_email");
21+
22+
@Override
23+
public <T extends HookEvent> Mono<T> onEvent(T event) {
24+
if (event instanceof PostReasoningEvent e) {
25+
Msg reasoningMsg = e.getReasoningMessage();
26+
List<ToolUseBlock> toolCalls = reasoningMsg.getContentBlocks(ToolUseBlock.class);
27+
28+
// Pause if sensitive tools are involved
29+
boolean hasSensitive = toolCalls.stream()
30+
.anyMatch(t -> SENSITIVE_TOOLS.contains(t.getName()));
31+
32+
if (hasSensitive) {
33+
e.stopAgent();
34+
}
35+
}
36+
return Mono.just(event);
37+
}
38+
};
39+
40+
// 2. Create agent
41+
ReActAgent agent = ReActAgent.builder()
42+
.name("Assistant")
43+
.model(model)
44+
.toolkit(toolkit)
45+
.hook(confirmationHook)
46+
.build();
47+
```
48+
49+
## Handling Pause and Resume
50+
51+
When the agent pauses, the returned message contains the pending tool information. Display it to the user and decide next steps based on their choice:
52+
53+
```java
54+
Msg response = agent.call(userMsg).block();
55+
56+
// Check for pending tool calls
57+
while (response.hasContentBlocks(ToolUseBlock.class)) {
58+
// Display pending tools
59+
List<ToolUseBlock> pending = response.getContentBlocks(ToolUseBlock.class);
60+
for (ToolUseBlock tool : pending) {
61+
System.out.println("Tool: " + tool.getName());
62+
System.out.println("Input: " + tool.getInput());
63+
}
64+
65+
if (userConfirms()) {
66+
// User confirmed, continue execution
67+
response = agent.call().block();
68+
} else {
69+
// User declined, return cancellation
70+
Msg cancelResult = Msg.builder()
71+
.role(MsgRole.TOOL)
72+
.content(pending.stream()
73+
.map(t -> ToolResultBlock.of(t.getId(), t.getName(),
74+
TextBlock.builder().text("Operation cancelled").build()))
75+
.toArray(ToolResultBlock[]::new))
76+
.build();
77+
response = agent.call(cancelResult).block();
78+
}
79+
}
80+
81+
// Final response
82+
System.out.println(response.getTextContent());
83+
```
84+
85+
## Quick Reference
86+
87+
**Pause methods**:
88+
- `PostReasoningEvent.stopAgent()` — Pause after reasoning
89+
- `PostActingEvent.stopAgent()` — Pause after acting
90+
91+
**Resume methods**:
92+
- `agent.call()` — Continue executing pending tools
93+
- `agent.call(toolResultMsg)` — Provide custom tool result and continue
94+
95+
**Check pause reason**:
96+
- `response.getGenerateReason()` returns `REASONING_STOP_REQUESTED` or `ACTING_STOP_REQUESTED`

_sources/en/task/tool.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,77 @@ toolkit.registerMetaTool();
296296
```
297297

298298
When there are many tool groups, agents can autonomously choose which groups to activate based on task requirements.
299+
300+
## Tool Suspend
301+
302+
When a tool throws `ToolSuspendException`, the Agent execution pauses and returns to the caller, allowing external systems to perform the actual execution before resuming.
303+
304+
**Use Cases**:
305+
- Tool requires external system execution (e.g., remote API, user manual operation)
306+
- Need to asynchronously wait for external results
307+
308+
**Usage**:
309+
310+
```java
311+
@Tool(name = "external_api", description = "Call external API")
312+
public ToolResultBlock callExternalApi(
313+
@ToolParam(name = "url") String url) {
314+
// Throw exception to suspend execution
315+
throw new ToolSuspendException("Awaiting external API response: " + url);
316+
}
317+
```
318+
319+
**Resume Execution**:
320+
321+
```java
322+
Msg response = agent.call(userMsg).block();
323+
324+
// Check if suspended
325+
if (response.getGenerateReason() == GenerateReason.TOOL_SUSPENDED) {
326+
// Get pending tool calls
327+
List<ToolUseBlock> pendingTools = response.getContentBlocks(ToolUseBlock.class);
328+
329+
// After external execution, provide result
330+
Msg toolResult = Msg.builder()
331+
.role(MsgRole.TOOL)
332+
.content(ToolResultBlock.of(toolUse.getId(), toolUse.getName(),
333+
TextBlock.builder().text("External execution result").build()))
334+
.build();
335+
336+
// Resume execution
337+
response = agent.call(toolResult).block();
338+
}
339+
```
340+
341+
## Schema Only Tool
342+
343+
Register only the tool's schema (name, description, parameters) without execution logic. When LLM calls this tool, the framework automatically triggers suspension and returns to the caller for execution.
344+
345+
**Use Cases**:
346+
- Tool implemented by external systems (e.g., frontend, other services)
347+
- Dynamically register third-party tools
348+
349+
**Usage**:
350+
351+
```java
352+
// Method 1: Using ToolSchema
353+
ToolSchema schema = ToolSchema.builder()
354+
.name("query_database")
355+
.description("Query external database")
356+
.parameters(Map.of(
357+
"type", "object",
358+
"properties", Map.of("sql", Map.of("type", "string")),
359+
"required", List.of("sql")
360+
))
361+
.build();
362+
363+
toolkit.registerSchema(schema);
364+
365+
// Method 2: Batch registration
366+
toolkit.registerSchemas(List.of(schema1, schema2));
367+
368+
// Check if it's an external tool
369+
boolean isExternal = toolkit.isExternalTool("query_database"); // true
370+
```
371+
372+
The call flow is the same as Tool Suspend: LLM calls → returns `TOOL_SUSPENDED` → external execution → provide result to resume.

_sources/zh/intro.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,16 @@ System.out.println(response.getTextContent());
111111

112112
## AI 辅助开发
113113

114-
AgentScope Cursor、Windsurf 和 GitHub Copilot 等 AI 代码助手提供了 LLM 友好的指南。该指南帮助 AI 助手理解 AgentScope Java 的 API、模式和最佳实践,以生成准确的代码
114+
AgentScope 文档支持 [`llms.txt` 标准](https://llmstxt.org/),使 Claude Code、Cursor、Windsurf 等 AI 编程助手能够理解 AgentScope API 并生成准确的代码
115115

116116
**Cursor 快速设置:**
117117

118118
1. 打开 Cursor 设置 -> Features -> Docs
119119
2. 点击 "+ Add new Doc"
120120
3. 添加 URL:`https://java.agentscope.io/llms-full.txt`
121121

122+
更多工具和详细配置,请参阅 **[使用 AI 编程](task/ai-coding.md)**
123+
122124
## 社区
123125

124126
- **GitHub**: [agentscope-ai/agentscope-java](https://github.com/agentscope-ai/agentscope-java)

_sources/zh/quickstart/key-concepts.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ Message 是 AgentScope 最核心的数据结构,用于:
8888
- `ToolUseBlock` - LLM 发起的工具调用
8989
- `ToolResultBlock` - 工具执行结果
9090

91+
**响应元信息**
92+
93+
Agent 返回的消息包含额外的元信息,帮助理解执行状态:
94+
95+
| 方法 | 说明 |
96+
|-----|------|
97+
| `getGenerateReason()` | 消息生成原因,用于判断后续操作 |
98+
| `getChatUsage()` | Token 用量统计(输入/输出 Token 数、耗时) |
99+
100+
**GenerateReason 枚举值**
101+
102+
|| 说明 |
103+
|----|------|
104+
| `MODEL_STOP` | 任务正常完成 |
105+
| `TOOL_SUSPENDED` | 工具需要外部执行,等待提供结果 |
106+
| `REASONING_STOP_REQUESTED` | Reasoning 阶段被 Hook 暂停(HITL) |
107+
| `ACTING_STOP_REQUESTED` | Acting 阶段被 Hook 暂停(HITL) |
108+
| `INTERRUPTED` | Agent 被中断 |
109+
| `MAX_ITERATIONS` | 达到最大迭代次数 |
110+
91111
**示例**
92112

93113
```java

0 commit comments

Comments
 (0)