|
1 | 1 | --- |
2 | | -title: Agent Framework 快速开始 |
3 | | -sidebar_label: 快速开始 |
4 | | -description: 使用 ARGI Agent Framework 创建一个基于 ReactAgent 的智能体。 |
| 2 | +title: Agent Framework quick start |
| 3 | +sidebar_label: Quick start |
| 4 | +description: Create a ReactAgent with the neutral ARGI ChatClient contract. |
5 | 5 | --- |
6 | 6 |
|
7 | | -# Agent Framework 快速开始 |
| 7 | +# Agent Framework quick start |
8 | 8 |
|
9 | | -Agent Framework 提供面向智能体应用的上层 API。当前核心入口是 `ReactAgent`:它接收 Spring AI 的 `ChatModel`,可以绑定工具,并在推理、工具调用和观察结果之间循环执行。 |
| 9 | +`ReactAgent` accepts an ARGI `ChatClient` and neutral `ToolRegistry`. |
| 10 | +Wrap a native provider client in an adapter before passing it to the runtime. |
| 11 | +See [versions](../../versions.md) for the exact RC2 source baseline. |
10 | 12 |
|
11 | | -## 添加依赖 |
| 13 | +## Add the runtime |
12 | 14 |
|
13 | | -使用 BOM 管理版本后,引入 Agent Framework: |
| 15 | +After importing `io.github.agentic-ai-java:argi-bom`, add: |
14 | 16 |
|
15 | 17 | ```xml |
16 | 18 | <dependency> |
17 | | - <groupId>io.github.agentic-ai</groupId> |
18 | | - <artifactId>argi-agent-framework</artifactId> |
| 19 | + <groupId>io.github.agentic-ai-java</groupId> |
| 20 | + <artifactId>argi-agent-framework</artifactId> |
19 | 21 | </dependency> |
20 | 22 | ``` |
21 | 23 |
|
22 | | -`argi-agent-framework` 依赖 `argi-graph-core`。如果应用只直接使用 `ReactAgent`,通常不需要再显式声明 Graph Core 依赖。 |
| 24 | +The agent framework brings Graph Core transitively. Choose one optional model |
| 25 | +adapter for your provider; credentials belong in environment configuration. |
23 | 26 |
|
24 | | -## 创建 ReactAgent |
25 | | - |
26 | | -`ReactAgent` 使用 Spring AI 的 `ChatModel`。模型实例由应用按所选模型提供方创建或注入。 |
| 27 | +## Create an agent |
27 | 28 |
|
28 | 29 | ```java |
| 30 | +import io.github.agentic.ai.api.chat.ChatClient; |
| 31 | +import io.github.agentic.ai.api.chat.ChatMessage; |
| 32 | +import io.github.agentic.ai.api.tool.ToolRegistry; |
29 | 33 | import io.github.agentic.ai.graph.agent.ReactAgent; |
30 | | -import org.springframework.ai.chat.messages.AssistantMessage; |
31 | | -import org.springframework.ai.chat.model.ChatModel; |
32 | | -import org.springframework.ai.tool.annotation.Tool; |
33 | 34 |
|
34 | | -import java.time.LocalDate; |
| 35 | +public final class AssistantService { |
| 36 | + private final ReactAgent agent; |
35 | 37 |
|
36 | | -class DateTools { |
| 38 | + public AssistantService(ChatClient client, ToolRegistry tools) { |
| 39 | + this.agent = ReactAgent.builder() |
| 40 | + .name("assistant") |
| 41 | + .chatClient(client) |
| 42 | + .toolRegistry(tools) |
| 43 | + .validateToolArguments(true) |
| 44 | + .build(); |
| 45 | + } |
37 | 46 |
|
38 | | - @Tool(description = "Get the current date.") |
39 | | - String currentDate() { |
40 | | - return LocalDate.now().toString(); |
| 47 | + public ChatMessage answer(String question) throws Exception { |
| 48 | + return agent.call(question); |
41 | 49 | } |
42 | 50 | } |
| 51 | +``` |
43 | 52 |
|
44 | | -ChatModel chatModel = obtainChatModel(); |
| 53 | +The application supplies a configured neutral client and registered tools. For Spring AI, |
| 54 | +wrap its native `ChatModel` or `ChatClient` in `SpringAiChatClientAdapter`; |
| 55 | +native callbacks require `SpringAiToolAdapter`. LangChain4j and Google ADK have |
| 56 | +separate adapters. Do not pass a native model to the removed `chatModel(...)` builder entry. |
45 | 57 |
|
46 | | -ReactAgent agent = ReactAgent.builder() |
47 | | - .name("assistant") |
48 | | - .model(chatModel) |
49 | | - .instruction("Answer concisely and call tools when external data is required.") |
50 | | - .methodTools(new DateTools()) |
51 | | - .build(); |
| 58 | +## Add execution policies |
52 | 59 |
|
53 | | -AssistantMessage response = agent.call("今天是几号?"); |
54 | | -System.out.println(response.getText()); |
55 | | -``` |
| 60 | +Argument validation is explicitly enabled above. Authorization, effect-aware retries, |
| 61 | +business-result mapping and tool-selection failure policies are separate opt-in |
| 62 | +features. Read [tool execution policies](./tool-execution-policies.md) before composing |
| 63 | +them. Tool selection does not confer execution permission. |
| 64 | + |
| 65 | +For checkpointed conversations, supply a stable `RunnableConfig.threadId(...)`. |
| 66 | +Attach authenticated identity through `trustedExecutionContext(...)`, rather than |
| 67 | +putting caller-controlled identity values into message history. |
| 68 | + |
| 69 | +## Run complete examples |
56 | 70 |
|
57 | | -## 常用构建选项 |
58 | | - |
59 | | -| 方法 | 用途 | |
60 | | -| --- | --- | |
61 | | -| `model(ChatModel)` | 设置底层模型。 | |
62 | | -| `tools(...)` | 传入 Spring AI `ToolCallback`。 | |
63 | | -| `methodTools(...)` | 将带有 `@Tool` 的对象方法转换为工具。 | |
64 | | -| `instruction(...)` | 设置 Agent 级任务指令。 | |
65 | | -| `systemPrompt(...)` | 设置模型调用使用的系统提示。 | |
66 | | -| `saver(...)` | 设置检查点存储,用于会话状态与恢复。 | |
67 | | -| `hooks(...)` | 注册 Agent 或 Model 执行阶段的 Hook。 | |
68 | | -| `interceptors(...)` | 注册模型或工具调用拦截器。 | |
69 | | -| `outputType(...)` / `outputSchema(...)` | 约束模型输出结构。 | |
70 | | -| `throwOnModelError(true)` | 模型同步调用失败时抛出原始异常,而不是转换为 `AssistantMessage`。 | |
71 | | - |
72 | | -## 接着阅读 |
73 | | - |
74 | | -- [Agents 介绍](./agents-intro.md) |
75 | | -- [ReAct Agent 理论基础](./react-agent-theory.md) |
76 | | -- [Tools 工具](./tools.md) |
77 | | -- [Hooks 与 Interceptors](./hooks-interceptors.md) |
| 71 | +[Current runtime contracts](./runtime-contracts.md) maps new capabilities to executable |
| 72 | +modules in `argi-example`. Local examples inspect policy decisions without a provider. |
| 73 | +The existing `react-tools` and adapter examples demonstrate real-model configuration |
| 74 | +and require their documented environment variables. |
0 commit comments