evoloop-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- evoloop_cli/__init__.py +3 -0
- evoloop_cli/__main__.py +10 -0
- evoloop_cli/_skills/evoloop-constitution/SKILL.md +59 -0
- evoloop_cli/_skills/evoloop-constitution/references/writing-guide.md +89 -0
- evoloop_cli/_skills/evoloop-constitution/templates/config.yaml +52 -0
- evoloop_cli/_skills/evoloop-constitution/templates/constitution.md +39 -0
- evoloop_cli/_skills/evoloop-evaluate/SKILL.md +85 -0
- evoloop_cli/_skills/evoloop-evaluate/schemas/parsed_report.schema.json +170 -0
- evoloop_cli/_skills/evoloop-evaluate/scripts/parse_junit_report.py +311 -0
- evoloop_cli/_skills/evoloop-evaluate/scripts/parse_pytest_report.py +276 -0
- evoloop_cli/_skills/evoloop-evaluate/scripts/parse_report.py +101 -0
- evoloop_cli/_skills/evoloop-evaluate/scripts/update_eval_index.py +111 -0
- evoloop_cli/_skills/evoloop-evaluate/scripts/validate_parsed_report.py +178 -0
- evoloop_cli/_skills/evoloop-evaluate/templates/analysis.md +51 -0
- evoloop_cli/_skills/evoloop-evaluate/templates/progress.md +42 -0
- evoloop_cli/_skills/evoloop-evaluate/templates/tasks.md +34 -0
- evoloop_cli/_skills/evoloop-evolve/SKILL.md +76 -0
- evoloop_cli/_skills/evoloop-evolve/scripts/evolve_state.py +333 -0
- evoloop_cli/_skills/evoloop-implement/SKILL.md +57 -0
- evoloop_cli/_skills/evoloop-implement/scripts/check_scope.py +154 -0
- evoloop_cli/_skills/evoloop-implement/scripts/commit_section.py +78 -0
- evoloop_cli/_skills/evoloop-init/SKILL.md +95 -0
- evoloop_cli/_skills/evoloop-init/scripts/scaffold_evals.py +546 -0
- evoloop_cli/_skills/evoloop-init/templates/common/evals/datasets/domain_flows.yaml +33 -0
- evoloop_cli/_skills/evoloop-init/templates/common/evaluations/README.md +9 -0
- evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/AgentAdapter.java +13 -0
- evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/AgenticFlowEvalTest.java +71 -0
- evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/DeterministicEvaluators.java +174 -0
- evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/EvalFrameworkTest.java +45 -0
- evoloop_cli/_skills/evoloop-init/templates/java/src/test/java/__PACKAGE_PATH__/evals/FlowRunResult.java +25 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/__init__.py +1 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/adapter.py +63 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/deepagents_adapter.py +223 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/evaluators/__init__.py +1 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/evaluators/deterministic.py +234 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/evaluators/llm_judge.py +189 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/fakes.py +26 -0
- evoloop_cli/_skills/evoloop-init/templates/python/evals/harness.py +100 -0
- evoloop_cli/_skills/evoloop-init/templates/python/tests/conftest.py +38 -0
- evoloop_cli/_skills/evoloop-init/templates/python/tests/test_agentic_flows.py +36 -0
- evoloop_cli/_skills/evoloop-init/templates/python/tests/test_eval_framework.py +175 -0
- evoloop_cli/_skills/evoloop-new/SKILL.md +125 -0
- evoloop_cli/_skills/evoloop-new/scripts/scaffold_agent.py +911 -0
- evoloop_cli/_skills/evoloop-new/templates/common/.evoloop/constitution.md +34 -0
- evoloop_cli/_skills/evoloop-new/templates/common/.gitignore +22 -0
- evoloop_cli/_skills/evoloop-new/templates/common/AGENTS.md +17 -0
- evoloop_cli/_skills/evoloop-new/templates/common/README.md +83 -0
- evoloop_cli/_skills/evoloop-new/templates/common/skills/__DOMAIN__/SKILL.md +21 -0
- evoloop_cli/_skills/evoloop-new/templates/java/eval_wiring/src/test/java/__PACKAGE_PATH__/evals/AgenticFlowEvalTest.java +113 -0
- evoloop_cli/_skills/evoloop-new/templates/java/eval_wiring/src/test/java/__PACKAGE_PATH__/evals/EvalFrameworkTest.java +85 -0
- evoloop_cli/_skills/evoloop-new/templates/java/eval_wiring/src/test/java/__PACKAGE_PATH__/evals/Fake__DOMAIN_PASCAL__Client.java +37 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/custom/src/main/java/__PACKAGE_PATH__/Application.java +46 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/custom/src/main/java/__PACKAGE_PATH__/OpenAiCompatibleRunner.java +433 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/custom/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Agent.java +125 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/langchain4j/src/main/java/__PACKAGE_PATH__/Application.java +46 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/langchain4j/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Agent.java +163 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/langchain4j/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Tools.java +18 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/Application.java +15 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Agent.java +167 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Controller.java +41 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Factory.java +32 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Tools.java +20 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/micronaut/src/main/resources/application.yml +17 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/Application.java +17 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Agent.java +159 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Config.java +32 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Controller.java +40 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Tools.java +25 -0
- evoloop_cli/_skills/evoloop-new/templates/java/frameworks/spring-ai/src/main/resources/application.yml +19 -0
- evoloop_cli/_skills/evoloop-new/templates/java/gradle/build_custom.gradle +33 -0
- evoloop_cli/_skills/evoloop-new/templates/java/gradle/build_langchain4j.gradle +40 -0
- evoloop_cli/_skills/evoloop-new/templates/java/gradle/build_micronaut.gradle +52 -0
- evoloop_cli/_skills/evoloop-new/templates/java/gradle/build_spring-ai.gradle +45 -0
- evoloop_cli/_skills/evoloop-new/templates/java/gradle/settings.gradle +1 -0
- evoloop_cli/_skills/evoloop-new/templates/java/maven/pom_custom.xml +57 -0
- evoloop_cli/_skills/evoloop-new/templates/java/maven/pom_langchain4j.xml +87 -0
- evoloop_cli/_skills/evoloop-new/templates/java/maven/pom_micronaut.xml +101 -0
- evoloop_cli/_skills/evoloop-new/templates/java/maven/pom_spring-ai.xml +61 -0
- evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/ConversationMemory.java +36 -0
- evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/Default__DOMAIN_PASCAL__Client.java +9 -0
- evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/DomainRecord.java +10 -0
- evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/TurnOutcome.java +15 -0
- evoloop_cli/_skills/evoloop-new/templates/java/src/main/java/__PACKAGE_PATH__/__DOMAIN_PASCAL__Client.java +8 -0
- evoloop_cli/_skills/evoloop-new/templates/python/eval_wiring/evals/fakes.py +22 -0
- evoloop_cli/_skills/evoloop-new/templates/python/eval_wiring/evals/harness_custom.py +186 -0
- evoloop_cli/_skills/evoloop-new/templates/python/eval_wiring/evals/harness_deepagents.py +100 -0
- evoloop_cli/_skills/evoloop-new/templates/python/eval_wiring/tests/test_eval_framework.py +196 -0
- evoloop_cli/_skills/evoloop-new/templates/python/pyproject.toml +18 -0
- evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/__init__.py +13 -0
- evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/__main__.py +6 -0
- evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/agent_custom.py +209 -0
- evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/agent_deepagents.py +61 -0
- evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/cli.py +71 -0
- evoloop_cli/_skills/evoloop-new/templates/python/src/__PACKAGE__/client.py +31 -0
- evoloop_cli/_skills/evoloop-scenarios/SKILL.md +49 -0
- evoloop_cli/_skills/evoloop-scenarios/scripts/validate_scenarios.py +261 -0
- evoloop_cli/_skills/evoloop-scenarios/templates/scenario_schema.md +49 -0
- evoloop_cli/cli.py +331 -0
- evoloop_cli-0.1.0.dist-info/METADATA +214 -0
- evoloop_cli-0.1.0.dist-info/RECORD +103 -0
- evoloop_cli-0.1.0.dist-info/WHEEL +4 -0
- evoloop_cli-0.1.0.dist-info/entry_points.txt +2 -0
- evoloop_cli-0.1.0.dist-info/licenses/LICENSE +202 -0
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
package __JAVA_PACKAGE__;
|
|
2
|
+
|
|
3
|
+
import com.fasterxml.jackson.core.type.TypeReference;
|
|
4
|
+
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
5
|
+
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
|
|
6
|
+
import dev.langchain4j.model.chat.ChatModel;
|
|
7
|
+
import dev.langchain4j.model.openai.OpenAiChatModel;
|
|
8
|
+
import dev.langchain4j.service.AiServices;
|
|
9
|
+
import dev.langchain4j.service.MemoryId;
|
|
10
|
+
import dev.langchain4j.service.Result;
|
|
11
|
+
import dev.langchain4j.service.SystemMessage;
|
|
12
|
+
import dev.langchain4j.service.UserMessage;
|
|
13
|
+
import dev.langchain4j.service.tool.ToolExecution;
|
|
14
|
+
import java.time.Duration;
|
|
15
|
+
import java.util.List;
|
|
16
|
+
import java.util.Map;
|
|
17
|
+
import java.util.Objects;
|
|
18
|
+
import java.util.Set;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Checkpointer-backed __DOMAIN_TITLE__ agent powered by LangChain4j {@link AiServices}.
|
|
22
|
+
*/
|
|
23
|
+
public class __DOMAIN_PASCAL__Agent {
|
|
24
|
+
|
|
25
|
+
public static final String DEFAULT_LLM_BASE_URL = "http://localhost:8080/v1";
|
|
26
|
+
public static final String DEFAULT_LLM_MODEL = "local-model";
|
|
27
|
+
|
|
28
|
+
// Keep SYSTEM_PROMPT compact (<= 120 words) and refactor rather than append patches.
|
|
29
|
+
public static final String SYSTEM_PROMPT =
|
|
30
|
+
"You are a helpful __DOMAIN_TITLE__ assistant. Follow AGENTS.md strictly. "
|
|
31
|
+
+ "Ground every factual statement in domain tool outputs and never fabricate data. "
|
|
32
|
+
+ "If a request is vague or missing required identifiers, ask one clear clarifying question without calling tools. "
|
|
33
|
+
+ "If a tool returns an error, reply briefly and honestly without guessing missing values. "
|
|
34
|
+
+ "Politely decline requests outside the __DOMAIN__ domain.";
|
|
35
|
+
|
|
36
|
+
public static final Set<String> DOMAIN_TOOLS = __JAVA_DOMAIN_TOOLS_SET__;
|
|
37
|
+
|
|
38
|
+
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
|
39
|
+
private static final TypeReference<Map<String, Object>> MAP_TYPE = new TypeReference<>() {};
|
|
40
|
+
|
|
41
|
+
public interface Assistant {
|
|
42
|
+
@SystemMessage(SYSTEM_PROMPT)
|
|
43
|
+
Result<String> chat(@MemoryId String threadId, @UserMessage String message);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private final __DOMAIN_PASCAL__Client client;
|
|
47
|
+
private final __DOMAIN_PASCAL__Tools tools;
|
|
48
|
+
private final ConversationMemory memory;
|
|
49
|
+
private final String baseUrl;
|
|
50
|
+
private final String model;
|
|
51
|
+
private final String apiKey;
|
|
52
|
+
private volatile Assistant assistant;
|
|
53
|
+
|
|
54
|
+
public __DOMAIN_PASCAL__Agent(__DOMAIN_PASCAL__Client client) {
|
|
55
|
+
this(client, new ConversationMemory.InMemory(), null, null, null);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public __DOMAIN_PASCAL__Agent(
|
|
59
|
+
__DOMAIN_PASCAL__Client client,
|
|
60
|
+
ConversationMemory memory,
|
|
61
|
+
String baseUrl,
|
|
62
|
+
String model,
|
|
63
|
+
String apiKey) {
|
|
64
|
+
this.client = Objects.requireNonNull(client, "client must not be null");
|
|
65
|
+
this.tools = new __DOMAIN_PASCAL__Tools(this.client);
|
|
66
|
+
this.memory = memory != null ? memory : new ConversationMemory.InMemory();
|
|
67
|
+
this.baseUrl = resolveEnv(baseUrl, "LLM_BASE_URL", DEFAULT_LLM_BASE_URL);
|
|
68
|
+
this.model = resolveEnv(model, "LLM_MODEL", DEFAULT_LLM_MODEL);
|
|
69
|
+
this.apiKey = resolveEnv(apiKey, "LLM_API_KEY", "not-needed");
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public static __DOMAIN_PASCAL__Agent create(__DOMAIN_PASCAL__Client client) {
|
|
73
|
+
return new __DOMAIN_PASCAL__Agent(client);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public ConversationMemory memory() {
|
|
77
|
+
return memory;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public String baseUrl() {
|
|
81
|
+
return baseUrl;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public String model() {
|
|
85
|
+
return model;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public String invokeTool(String toolName, String query) {
|
|
89
|
+
try {
|
|
90
|
+
return switch (toolName) {
|
|
91
|
+
__JAVA_TOOL_DISPATCH__
|
|
92
|
+
default -> "Error: Unknown tool '" + toolName + "'.";
|
|
93
|
+
};
|
|
94
|
+
} catch (RuntimeException exc) {
|
|
95
|
+
return "Error: " + exc.getMessage();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public void recordTurn(String threadId, String userInput, String assistantReply) {
|
|
100
|
+
memory.append(threadId, new ConversationMemory.Message("user", userInput));
|
|
101
|
+
memory.append(threadId, new ConversationMemory.Message("assistant", assistantReply));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public TurnOutcome runTurn(String threadId, String userInput) {
|
|
105
|
+
Result<String> result = getOrCreateAssistant().chat(threadId, userInput);
|
|
106
|
+
String finalReply = result.content() != null ? result.content().trim() : "";
|
|
107
|
+
List<TurnOutcome.ToolInvocation> calls = (result.toolExecutions() == null ? List.<ToolExecution>of() : result.toolExecutions())
|
|
108
|
+
.stream()
|
|
109
|
+
.map(exec -> new TurnOutcome.ToolInvocation(
|
|
110
|
+
exec.request().name(),
|
|
111
|
+
parseArgs(exec.request().arguments())))
|
|
112
|
+
.toList();
|
|
113
|
+
recordTurn(threadId, userInput, finalReply);
|
|
114
|
+
return new TurnOutcome(finalReply, calls, false);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
public String chat(String threadId, String userInput) {
|
|
118
|
+
return runTurn(threadId, userInput).finalResponse();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private Assistant getOrCreateAssistant() {
|
|
122
|
+
Assistant current = this.assistant;
|
|
123
|
+
if (current != null) {
|
|
124
|
+
return current;
|
|
125
|
+
}
|
|
126
|
+
synchronized (this) {
|
|
127
|
+
if (this.assistant == null) {
|
|
128
|
+
ChatModel chatModel = OpenAiChatModel.builder()
|
|
129
|
+
.baseUrl(baseUrl)
|
|
130
|
+
.modelName(model)
|
|
131
|
+
.apiKey(apiKey)
|
|
132
|
+
.temperature(0.0)
|
|
133
|
+
.timeout(Duration.ofSeconds(60))
|
|
134
|
+
.build();
|
|
135
|
+
this.assistant = AiServices.builder(Assistant.class)
|
|
136
|
+
.chatModel(chatModel)
|
|
137
|
+
.chatMemoryProvider(id -> MessageWindowChatMemory.withMaxMessages(20))
|
|
138
|
+
.tools(tools)
|
|
139
|
+
.build();
|
|
140
|
+
}
|
|
141
|
+
return this.assistant;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
private static Map<String, Object> parseArgs(String rawJson) {
|
|
146
|
+
if (rawJson == null || rawJson.isBlank()) {
|
|
147
|
+
return Map.of();
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
return OBJECT_MAPPER.readValue(rawJson, MAP_TYPE);
|
|
151
|
+
} catch (Exception exc) {
|
|
152
|
+
return Map.of();
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private static String resolveEnv(String explicit, String envVar, String fallback) {
|
|
157
|
+
if (explicit != null && !explicit.isBlank()) {
|
|
158
|
+
return explicit;
|
|
159
|
+
}
|
|
160
|
+
String fromEnv = System.getenv(envVar);
|
|
161
|
+
return (fromEnv != null && !fromEnv.isBlank()) ? fromEnv : fallback;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package __JAVA_PACKAGE__;
|
|
2
|
+
|
|
3
|
+
import dev.langchain4j.agent.tool.P;
|
|
4
|
+
import dev.langchain4j.agent.tool.Tool;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* LangChain4j @Tool adapter delegating directly to the injectable {@link __DOMAIN_PASCAL__Client}.
|
|
8
|
+
*/
|
|
9
|
+
public class __DOMAIN_PASCAL__Tools {
|
|
10
|
+
|
|
11
|
+
private final __DOMAIN_PASCAL__Client client;
|
|
12
|
+
|
|
13
|
+
public __DOMAIN_PASCAL__Tools(__DOMAIN_PASCAL__Client client) {
|
|
14
|
+
this.client = client;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
__JAVA_LANGCHAIN4J_TOOLS__
|
|
18
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package __JAVA_PACKAGE__;
|
|
2
|
+
|
|
3
|
+
import io.micronaut.runtime.Micronaut;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Minimal runnable Micronaut application entrypoint for __PROJECT_NAME__.
|
|
7
|
+
*
|
|
8
|
+
* Run: mvn mn:run (or ./gradlew run)
|
|
9
|
+
*/
|
|
10
|
+
public class Application {
|
|
11
|
+
|
|
12
|
+
public static void main(String[] args) {
|
|
13
|
+
Micronaut.run(Application.class, args);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
package __JAVA_PACKAGE__;
|
|
2
|
+
|
|
3
|
+
import com.fasterxml.jackson.core.type.TypeReference;
|
|
4
|
+
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
5
|
+
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
|
|
6
|
+
import dev.langchain4j.model.chat.ChatModel;
|
|
7
|
+
import dev.langchain4j.model.openai.OpenAiChatModel;
|
|
8
|
+
import dev.langchain4j.service.AiServices;
|
|
9
|
+
import dev.langchain4j.service.MemoryId;
|
|
10
|
+
import dev.langchain4j.service.Result;
|
|
11
|
+
import dev.langchain4j.service.SystemMessage;
|
|
12
|
+
import dev.langchain4j.service.UserMessage;
|
|
13
|
+
import dev.langchain4j.service.tool.ToolExecution;
|
|
14
|
+
import java.time.Duration;
|
|
15
|
+
import java.util.List;
|
|
16
|
+
import java.util.Map;
|
|
17
|
+
import java.util.Objects;
|
|
18
|
+
import java.util.Set;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Checkpointer-backed __DOMAIN_TITLE__ agent for Micronaut powered by LangChain4j {@link AiServices}
|
|
22
|
+
* and {@link __DOMAIN_PASCAL__Tools} (also exposed over Micronaut MCP at /mcp).
|
|
23
|
+
*/
|
|
24
|
+
public class __DOMAIN_PASCAL__Agent {
|
|
25
|
+
|
|
26
|
+
public static final String DEFAULT_LLM_BASE_URL = "http://localhost:8080/v1";
|
|
27
|
+
public static final String DEFAULT_LLM_MODEL = "local-model";
|
|
28
|
+
|
|
29
|
+
// Keep SYSTEM_PROMPT compact (<= 120 words) and refactor rather than append patches.
|
|
30
|
+
public static final String SYSTEM_PROMPT =
|
|
31
|
+
"You are a helpful __DOMAIN_TITLE__ assistant. Follow AGENTS.md strictly. "
|
|
32
|
+
+ "Ground every factual statement in domain tool outputs and never fabricate data. "
|
|
33
|
+
+ "If a request is vague or missing required identifiers, ask one clear clarifying question without calling tools. "
|
|
34
|
+
+ "If a tool returns an error, reply briefly and honestly without guessing missing values. "
|
|
35
|
+
+ "Politely decline requests outside the __DOMAIN__ domain.";
|
|
36
|
+
|
|
37
|
+
public static final Set<String> DOMAIN_TOOLS = __JAVA_DOMAIN_TOOLS_SET__;
|
|
38
|
+
|
|
39
|
+
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
|
40
|
+
private static final TypeReference<Map<String, Object>> MAP_TYPE = new TypeReference<>() {};
|
|
41
|
+
|
|
42
|
+
public interface Assistant {
|
|
43
|
+
@SystemMessage(SYSTEM_PROMPT)
|
|
44
|
+
Result<String> chat(@MemoryId String threadId, @UserMessage String message);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
private final __DOMAIN_PASCAL__Client client;
|
|
48
|
+
private final __DOMAIN_PASCAL__Tools tools;
|
|
49
|
+
private final ConversationMemory memory;
|
|
50
|
+
private final String baseUrl;
|
|
51
|
+
private final String model;
|
|
52
|
+
private final String apiKey;
|
|
53
|
+
private volatile Assistant assistant;
|
|
54
|
+
|
|
55
|
+
public __DOMAIN_PASCAL__Agent(__DOMAIN_PASCAL__Client client) {
|
|
56
|
+
this(client, new ConversationMemory.InMemory(), null, null, null);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public __DOMAIN_PASCAL__Agent(
|
|
60
|
+
__DOMAIN_PASCAL__Client client,
|
|
61
|
+
ConversationMemory memory,
|
|
62
|
+
String baseUrl,
|
|
63
|
+
String model,
|
|
64
|
+
String apiKey) {
|
|
65
|
+
this.client = Objects.requireNonNull(client, "client must not be null");
|
|
66
|
+
this.tools = new __DOMAIN_PASCAL__Tools(this.client);
|
|
67
|
+
this.memory = memory != null ? memory : new ConversationMemory.InMemory();
|
|
68
|
+
this.baseUrl = resolveEnv(baseUrl, "LLM_BASE_URL", DEFAULT_LLM_BASE_URL);
|
|
69
|
+
this.model = resolveEnv(model, "LLM_MODEL", DEFAULT_LLM_MODEL);
|
|
70
|
+
this.apiKey = resolveEnv(apiKey, "LLM_API_KEY", "not-needed");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public static __DOMAIN_PASCAL__Agent create(__DOMAIN_PASCAL__Client client) {
|
|
74
|
+
return new __DOMAIN_PASCAL__Agent(client);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public ConversationMemory memory() {
|
|
78
|
+
return memory;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
public String baseUrl() {
|
|
82
|
+
return baseUrl;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public String model() {
|
|
86
|
+
return model;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
public String invokeTool(String toolName, String query) {
|
|
90
|
+
try {
|
|
91
|
+
return switch (toolName) {
|
|
92
|
+
__JAVA_TOOL_DISPATCH__
|
|
93
|
+
default -> "Error: Unknown tool '" + toolName + "'.";
|
|
94
|
+
};
|
|
95
|
+
} catch (RuntimeException exc) {
|
|
96
|
+
return "Error: " + exc.getMessage();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public void recordTurn(String threadId, String userInput, String assistantReply) {
|
|
101
|
+
memory.append(threadId, new ConversationMemory.Message("user", userInput));
|
|
102
|
+
memory.append(threadId, new ConversationMemory.Message("assistant", assistantReply));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Execute one conversational turn via LangChain4j AiServices, capturing structured tool executions.
|
|
107
|
+
*/
|
|
108
|
+
public TurnOutcome runTurn(String threadId, String userInput) {
|
|
109
|
+
Result<String> result = getOrCreateAssistant().chat(threadId, userInput);
|
|
110
|
+
String finalReply = result.content() != null ? result.content().trim() : "";
|
|
111
|
+
List<TurnOutcome.ToolInvocation> calls = (result.toolExecutions() == null ? List.<ToolExecution>of() : result.toolExecutions())
|
|
112
|
+
.stream()
|
|
113
|
+
.map(exec -> new TurnOutcome.ToolInvocation(
|
|
114
|
+
exec.request().name(),
|
|
115
|
+
parseArgs(exec.request().arguments())))
|
|
116
|
+
.toList();
|
|
117
|
+
recordTurn(threadId, userInput, finalReply);
|
|
118
|
+
return new TurnOutcome(finalReply, calls, false);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
public String chat(String threadId, String userInput) {
|
|
122
|
+
return runTurn(threadId, userInput).finalResponse();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private Assistant getOrCreateAssistant() {
|
|
126
|
+
Assistant current = this.assistant;
|
|
127
|
+
if (current != null) {
|
|
128
|
+
return current;
|
|
129
|
+
}
|
|
130
|
+
synchronized (this) {
|
|
131
|
+
if (this.assistant == null) {
|
|
132
|
+
ChatModel chatModel = OpenAiChatModel.builder()
|
|
133
|
+
.baseUrl(baseUrl)
|
|
134
|
+
.modelName(model)
|
|
135
|
+
.apiKey(apiKey)
|
|
136
|
+
.temperature(0.0)
|
|
137
|
+
.timeout(Duration.ofSeconds(60))
|
|
138
|
+
.build();
|
|
139
|
+
this.assistant = AiServices.builder(Assistant.class)
|
|
140
|
+
.chatModel(chatModel)
|
|
141
|
+
.chatMemoryProvider(id -> MessageWindowChatMemory.withMaxMessages(20))
|
|
142
|
+
.tools(tools)
|
|
143
|
+
.build();
|
|
144
|
+
}
|
|
145
|
+
return this.assistant;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
private static Map<String, Object> parseArgs(String rawJson) {
|
|
150
|
+
if (rawJson == null || rawJson.isBlank()) {
|
|
151
|
+
return Map.of();
|
|
152
|
+
}
|
|
153
|
+
try {
|
|
154
|
+
return OBJECT_MAPPER.readValue(rawJson, MAP_TYPE);
|
|
155
|
+
} catch (Exception exc) {
|
|
156
|
+
return Map.of();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private static String resolveEnv(String explicit, String envVar, String fallback) {
|
|
161
|
+
if (explicit != null && !explicit.isBlank()) {
|
|
162
|
+
return explicit;
|
|
163
|
+
}
|
|
164
|
+
String fromEnv = System.getenv(envVar);
|
|
165
|
+
return (fromEnv != null && !fromEnv.isBlank()) ? fromEnv : fallback;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
package __JAVA_PACKAGE__;
|
|
2
|
+
|
|
3
|
+
import io.micronaut.http.annotation.Body;
|
|
4
|
+
import io.micronaut.http.annotation.Controller;
|
|
5
|
+
import io.micronaut.http.annotation.Get;
|
|
6
|
+
import io.micronaut.http.annotation.Post;
|
|
7
|
+
import io.micronaut.serde.annotation.Serdeable;
|
|
8
|
+
import java.util.Map;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Minimal Micronaut HTTP controller exposing the __DOMAIN_TITLE__ agent.
|
|
12
|
+
*/
|
|
13
|
+
@Controller("/api/__DOMAIN__")
|
|
14
|
+
public class __DOMAIN_PASCAL__Controller {
|
|
15
|
+
|
|
16
|
+
private final __DOMAIN_PASCAL__Agent agent;
|
|
17
|
+
|
|
18
|
+
public __DOMAIN_PASCAL__Controller(__DOMAIN_PASCAL__Agent agent) {
|
|
19
|
+
this.agent = agent;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@Serdeable
|
|
23
|
+
public record ChatRequest(String threadId, String message) {}
|
|
24
|
+
|
|
25
|
+
@Serdeable
|
|
26
|
+
public record ChatResponse(String threadId, String reply) {}
|
|
27
|
+
|
|
28
|
+
@Get("/health")
|
|
29
|
+
public Map<String, String> health() {
|
|
30
|
+
return Map.of("status", "ok", "domain", "__DOMAIN__", "framework", "micronaut");
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Post("/chat")
|
|
34
|
+
public ChatResponse chat(@Body ChatRequest request) {
|
|
35
|
+
String tid = (request.threadId() == null || request.threadId().isBlank())
|
|
36
|
+
? "default"
|
|
37
|
+
: request.threadId();
|
|
38
|
+
String reply = agent.chat(tid, request.message());
|
|
39
|
+
return new ChatResponse(tid, reply);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
package __JAVA_PACKAGE__;
|
|
2
|
+
|
|
3
|
+
import io.micronaut.context.annotation.Factory;
|
|
4
|
+
import io.micronaut.context.annotation.Value;
|
|
5
|
+
import jakarta.inject.Singleton;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Micronaut DI factory wiring the testable client interface, checkpointer, and LangChain4j agent bean.
|
|
9
|
+
*/
|
|
10
|
+
@Factory
|
|
11
|
+
public class __DOMAIN_PASCAL__Factory {
|
|
12
|
+
|
|
13
|
+
@Singleton
|
|
14
|
+
public __DOMAIN_PASCAL__Client domainClient() {
|
|
15
|
+
return new Default__DOMAIN_PASCAL__Client();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@Singleton
|
|
19
|
+
public ConversationMemory conversationMemory() {
|
|
20
|
+
return new ConversationMemory.InMemory();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@Singleton
|
|
24
|
+
public __DOMAIN_PASCAL__Agent domainAgent(
|
|
25
|
+
__DOMAIN_PASCAL__Client client,
|
|
26
|
+
ConversationMemory memory,
|
|
27
|
+
@Value("${llm.base-url:`http://localhost:8080/v1`}") String baseUrl,
|
|
28
|
+
@Value("${llm.model:local-model}") String model,
|
|
29
|
+
@Value("${llm.api-key:not-needed}") String apiKey) {
|
|
30
|
+
return new __DOMAIN_PASCAL__Agent(client, memory, baseUrl, model, apiKey);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
package __JAVA_PACKAGE__;
|
|
2
|
+
|
|
3
|
+
import dev.langchain4j.agent.tool.P;
|
|
4
|
+
import jakarta.inject.Singleton;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Domain tool definitions exposed both as Micronaut MCP tools (at /mcp) and as
|
|
8
|
+
* LangChain4j AiServices tools backed by the injectable {@link __DOMAIN_PASCAL__Client}.
|
|
9
|
+
*/
|
|
10
|
+
@Singleton
|
|
11
|
+
public class __DOMAIN_PASCAL__Tools {
|
|
12
|
+
|
|
13
|
+
private final __DOMAIN_PASCAL__Client client;
|
|
14
|
+
|
|
15
|
+
public __DOMAIN_PASCAL__Tools(__DOMAIN_PASCAL__Client client) {
|
|
16
|
+
this.client = client;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
__JAVA_MICRONAUT_MCP_TOOLS__
|
|
20
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
micronaut:
|
|
2
|
+
application:
|
|
3
|
+
name: __PROJECT_NAME__
|
|
4
|
+
server:
|
|
5
|
+
port: ${SERVER_PORT:9000}
|
|
6
|
+
mcp:
|
|
7
|
+
server:
|
|
8
|
+
transport: HTTP
|
|
9
|
+
endpoint: /mcp
|
|
10
|
+
info:
|
|
11
|
+
name: __PROJECT_NAME__
|
|
12
|
+
version: "0.1.0"
|
|
13
|
+
|
|
14
|
+
llm:
|
|
15
|
+
base-url: "${LLM_BASE_URL:`http://localhost:8080/v1`}"
|
|
16
|
+
model: ${LLM_MODEL:local-model}
|
|
17
|
+
api-key: ${LLM_API_KEY:not-needed}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
package __JAVA_PACKAGE__;
|
|
2
|
+
|
|
3
|
+
import org.springframework.boot.SpringApplication;
|
|
4
|
+
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Minimal runnable Spring Boot + Spring AI application entrypoint for __PROJECT_NAME__.
|
|
8
|
+
*
|
|
9
|
+
* Run: mvn spring-boot:run (or ./gradlew bootRun)
|
|
10
|
+
*/
|
|
11
|
+
@SpringBootApplication
|
|
12
|
+
public class Application {
|
|
13
|
+
|
|
14
|
+
public static void main(String[] args) {
|
|
15
|
+
SpringApplication.run(Application.class, args);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
package __JAVA_PACKAGE__;
|
|
2
|
+
|
|
3
|
+
import java.util.ArrayList;
|
|
4
|
+
import java.util.List;
|
|
5
|
+
import java.util.Objects;
|
|
6
|
+
import java.util.Set;
|
|
7
|
+
import java.util.concurrent.CopyOnWriteArrayList;
|
|
8
|
+
import org.springframework.ai.chat.client.ChatClient;
|
|
9
|
+
import org.springframework.ai.chat.messages.AssistantMessage;
|
|
10
|
+
import org.springframework.ai.chat.messages.Message;
|
|
11
|
+
import org.springframework.ai.chat.messages.UserMessage;
|
|
12
|
+
import org.springframework.ai.openai.OpenAiChatModel;
|
|
13
|
+
import org.springframework.ai.openai.OpenAiChatOptions;
|
|
14
|
+
import org.springframework.ai.openai.api.OpenAiApi;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Checkpointer-backed __DOMAIN_TITLE__ agent powered by Spring AI {@link ChatClient} and {@code @Tool}.
|
|
18
|
+
*/
|
|
19
|
+
public class __DOMAIN_PASCAL__Agent {
|
|
20
|
+
|
|
21
|
+
public static final String DEFAULT_LLM_BASE_URL = "http://localhost:8080/v1";
|
|
22
|
+
public static final String DEFAULT_LLM_MODEL = "local-model";
|
|
23
|
+
|
|
24
|
+
// Keep SYSTEM_PROMPT compact (<= 120 words) and refactor rather than append patches.
|
|
25
|
+
public static final String SYSTEM_PROMPT =
|
|
26
|
+
"You are a helpful __DOMAIN_TITLE__ assistant. Follow AGENTS.md strictly. "
|
|
27
|
+
+ "Ground every factual statement in domain tool outputs and never fabricate data. "
|
|
28
|
+
+ "If a request is vague or missing required identifiers, ask one clear clarifying question without calling tools. "
|
|
29
|
+
+ "If a tool returns an error, reply briefly and honestly without guessing missing values. "
|
|
30
|
+
+ "Politely decline requests outside the __DOMAIN__ domain.";
|
|
31
|
+
|
|
32
|
+
public static final Set<String> DOMAIN_TOOLS = __JAVA_DOMAIN_TOOLS_SET__;
|
|
33
|
+
|
|
34
|
+
private final __DOMAIN_PASCAL__Client client;
|
|
35
|
+
private final ConversationMemory memory;
|
|
36
|
+
private final String baseUrl;
|
|
37
|
+
private final String model;
|
|
38
|
+
private final String apiKey;
|
|
39
|
+
private volatile ChatClient chatClient;
|
|
40
|
+
|
|
41
|
+
public __DOMAIN_PASCAL__Agent(__DOMAIN_PASCAL__Client client) {
|
|
42
|
+
this(client, new ConversationMemory.InMemory(), null, null, null);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public __DOMAIN_PASCAL__Agent(
|
|
46
|
+
__DOMAIN_PASCAL__Client client,
|
|
47
|
+
ConversationMemory memory,
|
|
48
|
+
String baseUrl,
|
|
49
|
+
String model,
|
|
50
|
+
String apiKey) {
|
|
51
|
+
this.client = Objects.requireNonNull(client, "client must not be null");
|
|
52
|
+
this.memory = memory != null ? memory : new ConversationMemory.InMemory();
|
|
53
|
+
this.baseUrl = resolveEnv(baseUrl, "LLM_BASE_URL", DEFAULT_LLM_BASE_URL);
|
|
54
|
+
this.model = resolveEnv(model, "LLM_MODEL", DEFAULT_LLM_MODEL);
|
|
55
|
+
this.apiKey = resolveEnv(apiKey, "LLM_API_KEY", "not-needed");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public static __DOMAIN_PASCAL__Agent create(__DOMAIN_PASCAL__Client client) {
|
|
59
|
+
return new __DOMAIN_PASCAL__Agent(client);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
public ConversationMemory memory() {
|
|
63
|
+
return memory;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public String baseUrl() {
|
|
67
|
+
return baseUrl;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public String model() {
|
|
71
|
+
return model;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public String invokeTool(String toolName, String query) {
|
|
75
|
+
try {
|
|
76
|
+
return switch (toolName) {
|
|
77
|
+
__JAVA_TOOL_DISPATCH__
|
|
78
|
+
default -> "Error: Unknown tool '" + toolName + "'.";
|
|
79
|
+
};
|
|
80
|
+
} catch (RuntimeException exc) {
|
|
81
|
+
return "Error: " + exc.getMessage();
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
public void recordTurn(String threadId, String userInput, String assistantReply) {
|
|
86
|
+
memory.append(threadId, new ConversationMemory.Message("user", userInput));
|
|
87
|
+
memory.append(threadId, new ConversationMemory.Message("assistant", assistantReply));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Execute one conversational turn via Spring AI ChatClient with native tool execution and capture.
|
|
92
|
+
*/
|
|
93
|
+
public TurnOutcome runTurn(String threadId, String userInput) {
|
|
94
|
+
List<Message> messages = new ArrayList<>();
|
|
95
|
+
for (ConversationMemory.Message m : memory.getMessages(threadId)) {
|
|
96
|
+
if ("assistant".equals(m.role())) {
|
|
97
|
+
messages.add(new AssistantMessage(m.content()));
|
|
98
|
+
} else {
|
|
99
|
+
messages.add(new UserMessage(m.content()));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
messages.add(new UserMessage(userInput));
|
|
103
|
+
|
|
104
|
+
List<TurnOutcome.ToolInvocation> captured = new CopyOnWriteArrayList<>();
|
|
105
|
+
__DOMAIN_PASCAL__Tools turnTools = new __DOMAIN_PASCAL__Tools(client, captured);
|
|
106
|
+
|
|
107
|
+
String reply = getOrCreateChatClient()
|
|
108
|
+
.prompt()
|
|
109
|
+
.messages(messages)
|
|
110
|
+
.tools(turnTools)
|
|
111
|
+
.call()
|
|
112
|
+
.content();
|
|
113
|
+
String finalReply = reply != null ? reply.trim() : "";
|
|
114
|
+
recordTurn(threadId, userInput, finalReply);
|
|
115
|
+
return new TurnOutcome(finalReply, List.copyOf(captured), false);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
public String chat(String threadId, String userInput) {
|
|
119
|
+
return runTurn(threadId, userInput).finalResponse();
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
private ChatClient getOrCreateChatClient() {
|
|
123
|
+
ChatClient current = this.chatClient;
|
|
124
|
+
if (current != null) {
|
|
125
|
+
return current;
|
|
126
|
+
}
|
|
127
|
+
synchronized (this) {
|
|
128
|
+
if (this.chatClient == null) {
|
|
129
|
+
// Spring AI OpenAiApi appends /v1/chat/completions automatically.
|
|
130
|
+
String springBaseUrl = baseUrl.endsWith("/v1")
|
|
131
|
+
? baseUrl.substring(0, baseUrl.length() - 3)
|
|
132
|
+
: baseUrl;
|
|
133
|
+
OpenAiApi openAiApi = OpenAiApi.builder()
|
|
134
|
+
.baseUrl(springBaseUrl)
|
|
135
|
+
.apiKey(apiKey)
|
|
136
|
+
.build();
|
|
137
|
+
OpenAiChatModel chatModel = OpenAiChatModel.builder()
|
|
138
|
+
.openAiApi(openAiApi)
|
|
139
|
+
.defaultOptions(OpenAiChatOptions.builder()
|
|
140
|
+
.model(model)
|
|
141
|
+
.temperature(0.0)
|
|
142
|
+
.build())
|
|
143
|
+
.build();
|
|
144
|
+
this.chatClient = ChatClient.builder(chatModel)
|
|
145
|
+
.defaultSystem(SYSTEM_PROMPT)
|
|
146
|
+
.build();
|
|
147
|
+
}
|
|
148
|
+
return this.chatClient;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
private static String resolveEnv(String explicit, String envVar, String fallback) {
|
|
153
|
+
if (explicit != null && !explicit.isBlank()) {
|
|
154
|
+
return explicit;
|
|
155
|
+
}
|
|
156
|
+
String fromEnv = System.getenv(envVar);
|
|
157
|
+
return (fromEnv != null && !fromEnv.isBlank()) ? fromEnv : fallback;
|
|
158
|
+
}
|
|
159
|
+
}
|