simple - Hello world
2026年1月14日 下午2:36:04
在 solon 项目里添加依赖。也可嵌入到第三方框架生态。
<dependency>
<groupId>org.noear</groupId>
<artifactId>solon-ai-agent</artifactId>
</dependency>
1、Helloworld
借助 gitee ai 服务,使用 Qwen3-32B 模型服务。然后开始 SimpleAgent 编码:
import org.noear.solon.ai.agent.react.ReActAgent;
import org.noear.solon.ai.agent.simple.SimpleAgent;
import org.noear.solon.ai.annotation.ToolMapping;
import org.noear.solon.ai.chat.ChatModel;
import org.noear.solon.ai.chat.tool.MethodToolProvider;
import java.time.LocalDateTime;
public class DemoApp {
public static void main(String[] args) throws Throwable {
ChatModel chatModel = ChatModel.of("https://ai.gitee.com/v1/chat/completions")
.apiKey("***")
.model("Qwen3-32B")
.build();
SimpleAgent robot = SimpleAgent.of(chatModel)
.toolAdd(new MethodToolProvider(new TimeTool()))
.build();
String answer = robot.prompt( "现在几点了?")
.call()
.getContent();
System.out.println("Robot 答复: " + answer);
}
public static class TimeTool {
@ToolMapping(description = "获取当前系统时间")
public String getTime() {
return LocalDateTime.now().toString();
}
}
}