package com.xly.config; import dev.langchain4j.model.ollama.OllamaStreamingChatModel; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import java.time.Duration; import java.util.List; /** * agent 用的流式模型 Bean。 * *
单一 ReAct agent 的**组装**已移到 {@link AgentFactory}(按每次请求的身份新建携带 token/权限的工具实例, * 见 §5/§7 per-call context)。本类只保留全局复用的流式模型。 */ @Configuration public class AgentConfig { @Value("${langchain4j.ollama.base-url}") private String ollamaUrl; @Value("${langchain4j.ollama.chat-model-name}") private String chatModelName; @Autowired private TracingChatModelListener tracingListener; /** 专供 agent 的流式模型:低温度利于稳定的工具调用,较大 numPredict 避免答复被截断。 */ @Bean("agentStreamingModel") public OllamaStreamingChatModel agentStreamingModel() { return OllamaStreamingChatModel.builder() .baseUrl(ollamaUrl) .modelName(chatModelName) .temperature(0.1) .topP(0.9) .numPredict(2048) // qwen3 支持「思考」模式,但会显著拖慢交互;关闭它 -> 快,且思考不会混进回答 .think(false) .returnThinking(false) .listeners(List.of(tracingListener)) .timeout(Duration.ofSeconds(180)) .build(); } }