@exulu/backend 4.0.0 → 4.1.0
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.
- package/dist/index.cjs +51 -6
- package/dist/index.js +50 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -18648,6 +18648,45 @@ When a tool execution is not approved by the user, do not retry it unless explic
|
|
|
18648
18648
|
};
|
|
18649
18649
|
};
|
|
18650
18650
|
|
|
18651
|
+
// src/utils/agent-glossary.ts
|
|
18652
|
+
init_cjs_shims();
|
|
18653
|
+
function extractGlossaryFromAgentTools(tools) {
|
|
18654
|
+
if (!Array.isArray(tools)) return [];
|
|
18655
|
+
const searchTool = tools.find((t) => t?.id === "agentic_context_search");
|
|
18656
|
+
const entry = searchTool?.config?.find((c) => c?.name === "vocabulary");
|
|
18657
|
+
if (entry === void 0 || entry.variable === void 0 || entry.variable === null || entry.variable === "") {
|
|
18658
|
+
return [];
|
|
18659
|
+
}
|
|
18660
|
+
try {
|
|
18661
|
+
const parsed = typeof entry.variable === "string" ? JSON.parse(entry.variable) : entry.variable;
|
|
18662
|
+
const glossary = parsed?.glossary;
|
|
18663
|
+
if (!Array.isArray(glossary)) return [];
|
|
18664
|
+
return glossary.filter(
|
|
18665
|
+
(g) => !!g && typeof g.term === "string" && typeof g.meaning === "string" && g.term.trim().length > 0
|
|
18666
|
+
);
|
|
18667
|
+
} catch (err) {
|
|
18668
|
+
console.warn(
|
|
18669
|
+
"[EXULU] Failed to parse the agentic_context_search vocabulary config while building agent instructions.",
|
|
18670
|
+
err
|
|
18671
|
+
);
|
|
18672
|
+
return [];
|
|
18673
|
+
}
|
|
18674
|
+
}
|
|
18675
|
+
function formatGlossaryBlock(glossary) {
|
|
18676
|
+
if (!glossary.length) return "";
|
|
18677
|
+
const lines = glossary.map((g) => `${g.term} : ${g.meaning}`).join("\n");
|
|
18678
|
+
return `The organization's documents and internal terminology use the following abbreviations/terms:
|
|
18679
|
+
${lines}`;
|
|
18680
|
+
}
|
|
18681
|
+
function withGlossary(baseInstructions, tools) {
|
|
18682
|
+
const instructions = baseInstructions ?? "";
|
|
18683
|
+
const block = formatGlossaryBlock(extractGlossaryFromAgentTools(tools));
|
|
18684
|
+
if (!block) return instructions;
|
|
18685
|
+
return instructions ? `${block}
|
|
18686
|
+
|
|
18687
|
+
${instructions}` : block;
|
|
18688
|
+
}
|
|
18689
|
+
|
|
18651
18690
|
// src/exulu/agent-as-tool.ts
|
|
18652
18691
|
var createAgentTool = async (instance2, contexts) => {
|
|
18653
18692
|
const agent = await exuluApp.get().agent(instance2);
|
|
@@ -18706,7 +18745,7 @@ var createAgentTool = async (instance2, contexts) => {
|
|
|
18706
18745
|
const response = await generateSync({
|
|
18707
18746
|
agent,
|
|
18708
18747
|
contexts,
|
|
18709
|
-
instructions: agent.instructions,
|
|
18748
|
+
instructions: withGlossary(agent.instructions, agent.tools),
|
|
18710
18749
|
prompt: "The user has asked the following question: " + prompt + " and the following information is available: " + information,
|
|
18711
18750
|
languageModel: resolved.languageModel,
|
|
18712
18751
|
user,
|
|
@@ -21734,7 +21773,7 @@ var recallService = {
|
|
|
21734
21773
|
);
|
|
21735
21774
|
const { text } = await (0, import_ai8.generateText)({
|
|
21736
21775
|
model: resolved.languageModel,
|
|
21737
|
-
system: agent.instructions || void 0,
|
|
21776
|
+
system: withGlossary(agent.instructions, agent.tools) || void 0,
|
|
21738
21777
|
prompt: `${prompt.content}
|
|
21739
21778
|
|
|
21740
21779
|
---
|
|
@@ -26527,9 +26566,12 @@ var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) =>
|
|
|
26527
26566
|
}
|
|
26528
26567
|
const approvedTools = req.body.approvedTools ? typeof req.body.approvedTools === "string" ? JSON.parse(req.body.approvedTools) : req.body.approvedTools : [];
|
|
26529
26568
|
const customInstructions = req.body.customInstructions ? typeof req.body.customInstructions === "string" ? req.body.customInstructions : JSON.stringify(req.body.customInstructions) : "";
|
|
26530
|
-
const instructions =
|
|
26569
|
+
const instructions = withGlossary(
|
|
26570
|
+
customInstructions ? `${agent.instructions}
|
|
26531
26571
|
|
|
26532
|
-
${customInstructions}` : agent.instructions
|
|
26572
|
+
${customInstructions}` : agent.instructions,
|
|
26573
|
+
agent.tools
|
|
26574
|
+
);
|
|
26533
26575
|
if (headers.session) markStreamActive(headers.session);
|
|
26534
26576
|
const turnStartedAt = Date.now();
|
|
26535
26577
|
let result;
|
|
@@ -26665,9 +26707,12 @@ ${customInstructions}` : agent.instructions;
|
|
|
26665
26707
|
return;
|
|
26666
26708
|
} else {
|
|
26667
26709
|
const customInstructions = req.body.customInstructions ? typeof req.body.customInstructions === "string" ? req.body.customInstructions : JSON.stringify(req.body.customInstructions) : "";
|
|
26668
|
-
const instructions =
|
|
26710
|
+
const instructions = withGlossary(
|
|
26711
|
+
customInstructions ? `${agent.instructions}
|
|
26669
26712
|
|
|
26670
|
-
${customInstructions}` : agent.instructions
|
|
26713
|
+
${customInstructions}` : agent.instructions,
|
|
26714
|
+
agent.tools
|
|
26715
|
+
);
|
|
26671
26716
|
let response;
|
|
26672
26717
|
try {
|
|
26673
26718
|
response = await generateSync({
|
package/dist/index.js
CHANGED
|
@@ -9036,6 +9036,44 @@ When a tool execution is not approved by the user, do not retry it unless explic
|
|
|
9036
9036
|
};
|
|
9037
9037
|
};
|
|
9038
9038
|
|
|
9039
|
+
// src/utils/agent-glossary.ts
|
|
9040
|
+
function extractGlossaryFromAgentTools(tools) {
|
|
9041
|
+
if (!Array.isArray(tools)) return [];
|
|
9042
|
+
const searchTool = tools.find((t) => t?.id === "agentic_context_search");
|
|
9043
|
+
const entry = searchTool?.config?.find((c) => c?.name === "vocabulary");
|
|
9044
|
+
if (entry === void 0 || entry.variable === void 0 || entry.variable === null || entry.variable === "") {
|
|
9045
|
+
return [];
|
|
9046
|
+
}
|
|
9047
|
+
try {
|
|
9048
|
+
const parsed = typeof entry.variable === "string" ? JSON.parse(entry.variable) : entry.variable;
|
|
9049
|
+
const glossary = parsed?.glossary;
|
|
9050
|
+
if (!Array.isArray(glossary)) return [];
|
|
9051
|
+
return glossary.filter(
|
|
9052
|
+
(g) => !!g && typeof g.term === "string" && typeof g.meaning === "string" && g.term.trim().length > 0
|
|
9053
|
+
);
|
|
9054
|
+
} catch (err) {
|
|
9055
|
+
console.warn(
|
|
9056
|
+
"[EXULU] Failed to parse the agentic_context_search vocabulary config while building agent instructions.",
|
|
9057
|
+
err
|
|
9058
|
+
);
|
|
9059
|
+
return [];
|
|
9060
|
+
}
|
|
9061
|
+
}
|
|
9062
|
+
function formatGlossaryBlock(glossary) {
|
|
9063
|
+
if (!glossary.length) return "";
|
|
9064
|
+
const lines = glossary.map((g) => `${g.term} : ${g.meaning}`).join("\n");
|
|
9065
|
+
return `The organization's documents and internal terminology use the following abbreviations/terms:
|
|
9066
|
+
${lines}`;
|
|
9067
|
+
}
|
|
9068
|
+
function withGlossary(baseInstructions, tools) {
|
|
9069
|
+
const instructions = baseInstructions ?? "";
|
|
9070
|
+
const block = formatGlossaryBlock(extractGlossaryFromAgentTools(tools));
|
|
9071
|
+
if (!block) return instructions;
|
|
9072
|
+
return instructions ? `${block}
|
|
9073
|
+
|
|
9074
|
+
${instructions}` : block;
|
|
9075
|
+
}
|
|
9076
|
+
|
|
9039
9077
|
// src/exulu/agent-as-tool.ts
|
|
9040
9078
|
var createAgentTool = async (instance, contexts) => {
|
|
9041
9079
|
const agent = await exuluApp.get().agent(instance);
|
|
@@ -9094,7 +9132,7 @@ var createAgentTool = async (instance, contexts) => {
|
|
|
9094
9132
|
const response = await generateSync({
|
|
9095
9133
|
agent,
|
|
9096
9134
|
contexts,
|
|
9097
|
-
instructions: agent.instructions,
|
|
9135
|
+
instructions: withGlossary(agent.instructions, agent.tools),
|
|
9098
9136
|
prompt: "The user has asked the following question: " + prompt + " and the following information is available: " + information,
|
|
9099
9137
|
languageModel: resolved.languageModel,
|
|
9100
9138
|
user,
|
|
@@ -12081,7 +12119,7 @@ var recallService = {
|
|
|
12081
12119
|
);
|
|
12082
12120
|
const { text } = await generateText4({
|
|
12083
12121
|
model: resolved.languageModel,
|
|
12084
|
-
system: agent.instructions || void 0,
|
|
12122
|
+
system: withGlossary(agent.instructions, agent.tools) || void 0,
|
|
12085
12123
|
prompt: `${prompt.content}
|
|
12086
12124
|
|
|
12087
12125
|
---
|
|
@@ -16798,9 +16836,12 @@ var createExpressRoutes = async (app, tools, contexts, config, evals, tracer) =>
|
|
|
16798
16836
|
}
|
|
16799
16837
|
const approvedTools = req.body.approvedTools ? typeof req.body.approvedTools === "string" ? JSON.parse(req.body.approvedTools) : req.body.approvedTools : [];
|
|
16800
16838
|
const customInstructions = req.body.customInstructions ? typeof req.body.customInstructions === "string" ? req.body.customInstructions : JSON.stringify(req.body.customInstructions) : "";
|
|
16801
|
-
const instructions =
|
|
16839
|
+
const instructions = withGlossary(
|
|
16840
|
+
customInstructions ? `${agent.instructions}
|
|
16802
16841
|
|
|
16803
|
-
${customInstructions}` : agent.instructions
|
|
16842
|
+
${customInstructions}` : agent.instructions,
|
|
16843
|
+
agent.tools
|
|
16844
|
+
);
|
|
16804
16845
|
if (headers.session) markStreamActive(headers.session);
|
|
16805
16846
|
const turnStartedAt = Date.now();
|
|
16806
16847
|
let result;
|
|
@@ -16936,9 +16977,12 @@ ${customInstructions}` : agent.instructions;
|
|
|
16936
16977
|
return;
|
|
16937
16978
|
} else {
|
|
16938
16979
|
const customInstructions = req.body.customInstructions ? typeof req.body.customInstructions === "string" ? req.body.customInstructions : JSON.stringify(req.body.customInstructions) : "";
|
|
16939
|
-
const instructions =
|
|
16980
|
+
const instructions = withGlossary(
|
|
16981
|
+
customInstructions ? `${agent.instructions}
|
|
16940
16982
|
|
|
16941
|
-
${customInstructions}` : agent.instructions
|
|
16983
|
+
${customInstructions}` : agent.instructions,
|
|
16984
|
+
agent.tools
|
|
16985
|
+
);
|
|
16942
16986
|
let response;
|
|
16943
16987
|
try {
|
|
16944
16988
|
response = await generateSync({
|