From AI Chat to AI Agent: 1360 Lines of Java Code in 300+ Days
The article details how the Feat team transformed a simple AI chat interface into a full‑featured AI agent using only 1,360 lines of Java code written over more than 300 days, emphasizing a lightweight, Java‑8‑compatible solution that rivals Spring AI in simplicity while delivering SSE‑based streaming responses.
Near the Chinese New Year, the Feat team announced a major breakthrough in AI Agent development. After typing smart-mqtt的技术栈是什么 into the front‑end, the back‑end automatically entered full‑automatic mode and produced the expected answer.
This behavior is common in modern AI products, but for Feat it marks a milestone because the team aims to provide a more suitable AI solution for Java developers—lighter, simpler, and fully compatible with the Java 8 ecosystem.
Development of the Feat AI module started during the 2025 Spring Festival and was completed just before the 2026 Spring Festival, achieving the evolution from AI Chat to AI Agent with only 1,360 lines of code .
To lower the barrier for building agents, the team put considerable thought into the API design, keeping the back‑end implementation minimal. The core controller handling chat completions is shown below:
@RequestMapping(value = OpenApi.BASE_API + "/chat/completions")
public void chat(HttpRequest request, @Param("messages") List<Message> messages) throws IOException {
PluginConfig.OpenAI openAI = pluginConfig.getOpenai();
StringBuilder sb = new StringBuilder();
for (Message message : messages) {
sb.append(message.getRole()).append(": ").append(message.getContent()).append("
");
}
FeatAgent agent = FeatAI.agent(agentOptions -> agentOptions
.addTool(new SearchTool())
.addTool(new WebPageReaderTool())
.chatOptions()
.system("你需要为用户提供关于 smart-mqtt 相关的专业性答疑服务,如果用户提问内容与本产品或者MQTT、物联网等无关,要给出提醒。
"
+ "- [产品官网](https://smartboot.tech/smart-mqtt/)获取相关内容。
"
+ "- [Gitee仓库](https://gitee.com/smartboot/smart-mqtt/)
"
+ "- [Github仓库](https://github.com/smartboot/smart-mqtt/)
")
.model(new ChatModelVendor(openAI.getUrl(), openAI.getModel()))
.apiKey(openAI.getApiKey()));
// SSE push data to front‑end page
request.upgrade(new SSEUpgrade() {
@Override
public void onOpen(SseEmitter sseEmitter) {
agent.options().hook(new Hook() {
// omitted push logic
});
CompletableFuture<String> future = agent.execute(sb.toString());
future.thenAccept(result -> {
try {
sseEmitter.sendAsJson(AiChunkTO.ofResult(result));
} finally {
sseEmitter.complete();
}
}).exceptionally(throwable -> {
try {
sseEmitter.sendAsJson(AiChunkTO.ofResult(throwable.getMessage()));
} finally {
sseEmitter.complete();
}
return null;
});
}
@Override
public void destroy() {
agent.cancel();
}
});
}An additional demo illustrates the agent in action:
public class ReActAgentTest {
public static void main(String[] args) throws ExecutionException, InterruptedException {
FeatAgent agent = FeatAI.agent(agentOptions -> agentOptions
.addTool(new SearchTool())
.addTool(new WebPageReaderTool())
.chatOptions()
.system("你需要为用户提供关于 smart-mqtt 相关的专业性答疑服务,如果用户提问内容与本产品或者MQTT、物联网等无关,要给出提醒。
"
+ "- [产品官网](https://smartboot.tech/smart-mqtt/)获取相关内容。
"
+ "- [Gitee仓库](https://gitee.com/smartboot/smart-mqtt/)
"
+ "- [Github仓库](https://github.com/smartboot/smart-mqtt/)
")
.model(ChatModelVendor.GiteeAI.Kimi_K25_Instruct));
// Execute test
String result = agent.execute("smart-mqtt的技术栈是什么").get();
System.out.println("
最终结果:
" + result);
System.out.println("
Agent最终状态: " + agent.getState());
}
}With this implementation, Feat moves closer to its goal of delivering a modern Java web‑service framework that outperforms Vert.x in runtime performance, offers a SpringBoot‑like development experience, and is driven by both AI‑native and cloud‑native engines.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Three Knives
Every line of code you contribute to open source could help make the future better.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
