devto 2026-06-08 원문 보기 ↗
In 2026, building enterprise-grade Java agents means managing thousands of potential database, API, and legacy system tools. If you are still hardcoding all your @Tool definitions into your LLM context on every single turn, you are burning cash, spiking latency, and blowing past model context limits.
@Tool into the ChatClient configuration, expecting Claude 3.5 Sonnet or GPT-4o to magically sort through 500+ tool definitions without hallucinating.Treat your tool definitions as semantic documents: index their metadata in a vector database and query them dynamically at runtime based on the user's intent.
VectorStore during application bootstrap.ChatOptions of your ChatClient call for that specific turn.Heads up: if you want to see these patterns applied to real interview problems, javalld.com has full machine coding solutions with traces.
// Dynamic Tool Routing with Spring AI
public ChatResponse executeWithDynamicTools(String userPrompt) {
List<Document> relevantTools = vectorStore.similaritySearch(
SearchRequest.query(userPrompt).withTopK(3).withSimilarityThreshold(0.8)
);
String[] activeToolNames = relevantTools.stream()
.map(doc -> doc.getMetadata().get("tool_name").toString())
.toArray(String[]::new);
return chatClient.prompt(userPrompt)
.options(OpenAiChatOptions.builder()
.withFunctionCallbacks(toolRegistry.getCallbacks(activeToolNames))
.build())
.call()
.chatResponse();
}
VectorStore coupled with a custom FunctionCallback registry allows teams to scale tools independently without redeploying the core agent.