@@ -43,7 +43,6 @@ public static void main(String[] args) {
4343 Model model = DashScopeChatModel . builder()
4444 .apiKey(System . getenv(" DASHSCOPE_API_KEY" ))
4545 .modelName(" qwen-max" )
46- .baseUrl(" https://dashscope.aliyuncs.com/v1" )
4746 .build();
4847
4948 ReActAgent agent = ReActAgent . builder()
@@ -59,7 +58,7 @@ public static void main(String[] args) {
5958 .role(MsgRole . USER )
6059 .textContent(" Hello, please introduce yourself." )
6160 .build();
62- Msg response = agent. stream (userMessage). blockLast ();
61+ Msg response = agent. reply (userMessage). block ();
6362
6463 System . out. println(" Agent Response: " + response. getTextContent());
6564}
@@ -68,38 +67,31 @@ public static void main(String[] args) {
6867### Equip Agent with Tools
69681 . Define Tool
7069
71- Define a tool `TimeFunctionalTool` for obtaining time, with the input parameter being `String` and the output parameter being of type `ToolResponse`(required).
70+ Define a tool class with methods annotated with `@Tool`. Here's an example `SimpleTools` class with a time tool:
7271
7372 ```java
74- public class TimeFunctionTool implements Function<String, ToolResponse> {
75- @Override
76- public ToolResponse apply(String s) {
77- try {
78- // Get current time and format it as string
79- LocalDateTime now = LocalDateTime.now();
80- String currentTime = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
81-
82- TextBlock textBlock = TextBlock.builder().text(currentTime).build();
83- return new ToolResponse(List.of(textBlock));
84- } catch (Exception e) {
85- return ToolResponse.error("Tool execution failed: " + e.getMessage());
86- }
73+ public class SimpleTools {
74+ @Tool(name = "get_time", description = "Get current time string of a time zone")
75+ public String getTime(@ToolParam(description = "Time zone, e.g., Beijing") String zone) {
76+ LocalDateTime now = LocalDateTime.now();
77+ return now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
8778 }
8879 }
8980 ```
9081
91822 . Register Tool to ReActAgent
9283
93- Register the Tool through `Toolkit` and specify `toolName` and `description` (Another way of doing this is using annotations when declaring the Tool).
84+ Register the tool class through `Toolkit` using the `registerTool` method:
9485
9586 ```java
9687 public static void main(String[] args) {
88+ Model model = DashScopeChatModel.builder()
89+ .apiKey(System.getenv("DASHSCOPE_API_KEY"))
90+ .modelName("qwen-max")
91+ .build();
92+
9793 Toolkit toolkit = new Toolkit();
98- toolkit.registerTool(
99- "timeTool",
100- "Get the current time of a specific zone in format YYYY-MM-DD HH:MM:SS",
101- new TimeFunctionTool()
102- );
94+ toolkit.registerTool(new SimpleTools());
10395
10496 ReActAgent agent = ReActAgent.builder()
10597 .name("hello-world-agent")
@@ -112,16 +104,13 @@ public static void main(String[] args) {
112104
113105 Msg userMessage = Msg.builder()
114106 .role(MsgRole.USER)
115- .textContent("Please tell me the current time of Beijing and London .")
107+ .textContent("Please tell me the current time.")
116108 .build();
117109
118- agent.stream(userMessage).doOnNext(msg -> {;
119- System.out.println("Agent Response: " + msg.getTextContent());
120- }).blockLast();
110+ Msg response = agent.reply(userMessage).block();
111+ System.out.println("Agent Response: " + response.getTextContent());
121112 }
122113 ```
123-
124-
125114## <font style =" color :rgb (31 , 35 , 40 );" >📖</font ><font style =" color :rgb (31 , 35 , 40 );" > Documentation</font >
126115+ [ Create Message] ( ./docs/quickstart-message.md )
127116+ [ Create ReAct Agent] ( ./docs/quickstart-agent.md )
@@ -134,9 +123,6 @@ public static void main(String[] args) {
134123In the upcoming versions, AgentScope Java version will focus on improving the following features.
135124
136125+ Multi-modal
137- + Prompt Formatter
138- + State/Session Management
139- + Real-time Steering
140126+ Multi-Agent
141127+ Tracing
142128+ AgentScope Studio
0 commit comments