@saltcorn/agents 0.3.1 → 0.3.3
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/common.js +6 -4
- package/package.json +1 -1
- package/skills/FTSRetrieval.js +2 -2
- package/skills/ModelContextProtocol.js +67 -0
- package/skills/Table.js +9 -6
package/common.js
CHANGED
|
@@ -13,6 +13,7 @@ const get_skills = () => {
|
|
|
13
13
|
require("./skills/Table"),
|
|
14
14
|
require("./skills/PreloadData"),
|
|
15
15
|
require("./skills/GenerateImage"),
|
|
16
|
+
require("./skills/ModelContextProtocol"),
|
|
16
17
|
//require("./skills/AdaptiveFeedback"),
|
|
17
18
|
];
|
|
18
19
|
};
|
|
@@ -151,10 +152,10 @@ const process_interaction = async (
|
|
|
151
152
|
//console.log("complArgs", JSON.stringify(complArgs, null, 2));
|
|
152
153
|
|
|
153
154
|
const answer = await getState().functions.llm_generate.run("", complArgs);
|
|
154
|
-
|
|
155
|
+
console.log("answer", answer);
|
|
155
156
|
|
|
156
157
|
const responses = [];
|
|
157
|
-
if (typeof answer === "object" && answer.image_calls) {
|
|
158
|
+
if (answer && typeof answer === "object" && answer.image_calls) {
|
|
158
159
|
for (const image_call of answer.image_calls) {
|
|
159
160
|
const tool = find_image_tool(config);
|
|
160
161
|
let prcRes;
|
|
@@ -197,12 +198,13 @@ const process_interaction = async (
|
|
|
197
198
|
]
|
|
198
199
|
: [{ role: "assistant", content: answer }],
|
|
199
200
|
});
|
|
200
|
-
if (typeof answer === "object" && answer.tool_calls) {
|
|
201
|
+
if (answer && typeof answer === "object" && (answer.tool_calls || answer.mcp_calls)) {
|
|
201
202
|
if (answer.content)
|
|
202
203
|
responses.push(wrapSegment(md.render(answer.content), agent_label));
|
|
203
204
|
//const actions = [];
|
|
204
205
|
let hasResult = false;
|
|
205
|
-
|
|
206
|
+
if ((answer.mcp_calls || []).length && !answer.content) hasResult = true;
|
|
207
|
+
for (const tool_call of answer.tool_calls || []) {
|
|
206
208
|
console.log("call function", tool_call.function);
|
|
207
209
|
|
|
208
210
|
await addToContext(run, {
|
package/package.json
CHANGED
package/skills/FTSRetrieval.js
CHANGED
|
@@ -25,7 +25,7 @@ class RetrievalByFullTextSearch {
|
|
|
25
25
|
if (this.mode === "Tool")
|
|
26
26
|
return `Use the ${this.toolName} tool to search the ${
|
|
27
27
|
this.table_name
|
|
28
|
-
} database by a search phrase which will locate rows where any field match that query.${
|
|
28
|
+
} database by a search phrase (using the syntax of web search engines) which will locate rows where any field match that query.${
|
|
29
29
|
this.list_view
|
|
30
30
|
? ` When the tool call returns rows, do not describe them or repeat the information to the user. The results are already displayed to the user automatically.`
|
|
31
31
|
: ""
|
|
@@ -161,7 +161,7 @@ class RetrievalByFullTextSearch {
|
|
|
161
161
|
properties: {
|
|
162
162
|
phrase: {
|
|
163
163
|
type: "string",
|
|
164
|
-
description: "The phrase to search the table with",
|
|
164
|
+
description: "The phrase to search the table with. The search phrase is the synatx used by web search engines: use double quotes for exact match, unquoted text for words in any order, dash (minus sign) to exclude a word. Do not use SQL or any other formal query language.",
|
|
165
165
|
},
|
|
166
166
|
},
|
|
167
167
|
},
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
const { div, pre } = require("@saltcorn/markup/tags");
|
|
2
|
+
const Workflow = require("@saltcorn/data/models/workflow");
|
|
3
|
+
const Form = require("@saltcorn/data/models/form");
|
|
4
|
+
const Table = require("@saltcorn/data/models/table");
|
|
5
|
+
const File = require("@saltcorn/data/models/file");
|
|
6
|
+
const View = require("@saltcorn/data/models/view");
|
|
7
|
+
const { getState } = require("@saltcorn/data/db/state");
|
|
8
|
+
const db = require("@saltcorn/data/db");
|
|
9
|
+
const { eval_expression } = require("@saltcorn/data/models/expression");
|
|
10
|
+
const { interpolate } = require("@saltcorn/data/utils");
|
|
11
|
+
|
|
12
|
+
class ModelContextProtocol {
|
|
13
|
+
static skill_name = "Model Context Protocol";
|
|
14
|
+
|
|
15
|
+
get skill_label() {
|
|
16
|
+
return `Model Context Protocol: ${this.server_label}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
constructor(cfg) {
|
|
20
|
+
Object.assign(this, cfg);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static async configFields() {
|
|
24
|
+
return [
|
|
25
|
+
{
|
|
26
|
+
name: "server_label",
|
|
27
|
+
label: "Server label",
|
|
28
|
+
type: "String",
|
|
29
|
+
required: true,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "server_url",
|
|
33
|
+
label: "Server URL",
|
|
34
|
+
type: "String",
|
|
35
|
+
required: true,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "header_key",
|
|
39
|
+
label: "Header key",
|
|
40
|
+
type: "String",
|
|
41
|
+
sublabel:
|
|
42
|
+
"Optional, for authorization. Which HTTP header should be set? For example <code>Authorization</code>",
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "header_value",
|
|
46
|
+
label: "Header value",
|
|
47
|
+
type: "String",
|
|
48
|
+
sublabel:
|
|
49
|
+
"Optional, for authorization. What is the value of the HTTP header? For example <code>Bearer {api_key}</code>",
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
provideTools() {
|
|
55
|
+
const tool = {
|
|
56
|
+
type: "mcp",
|
|
57
|
+
server_label: this.server_label,
|
|
58
|
+
server_url: this.server_url,
|
|
59
|
+
require_approval: "never",
|
|
60
|
+
};
|
|
61
|
+
if (this.header_key && this.header_value)
|
|
62
|
+
tool.headers = { [this.header_key]: this.header_value };
|
|
63
|
+
return tool;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
module.exports = ModelContextProtocol;
|
package/skills/Table.js
CHANGED
|
@@ -21,9 +21,11 @@ class TableToSkill {
|
|
|
21
21
|
systemPrompt() {
|
|
22
22
|
return `Use the query_${this.table_name} tool to search the ${
|
|
23
23
|
this.table_name
|
|
24
|
-
} database by a search phrase which will locate rows where any field match that query.${
|
|
25
|
-
this.
|
|
26
|
-
|
|
24
|
+
} database by specific fields or a search phrase which will locate rows where any field match that query.${
|
|
25
|
+
this.list_view
|
|
26
|
+
? ` When the tool call returns rows, do not describe them or repeat the information to the user. The results are already displayed to the user automatically.`
|
|
27
|
+
: ""
|
|
28
|
+
}${this.add_sys_prompt ? ` ${this.add_sys_prompt}` : ""}`;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
static async configFields() {
|
|
@@ -78,7 +80,7 @@ class TableToSkill {
|
|
|
78
80
|
name: "add_sys_prompt",
|
|
79
81
|
label: "Additional system prompt",
|
|
80
82
|
type: "String",
|
|
81
|
-
fieldview: "textarea"
|
|
83
|
+
fieldview: "textarea",
|
|
82
84
|
},
|
|
83
85
|
];
|
|
84
86
|
}
|
|
@@ -173,11 +175,12 @@ class TableToSkill {
|
|
|
173
175
|
{
|
|
174
176
|
type: "object",
|
|
175
177
|
description:
|
|
176
|
-
"Search the table by a phrase matched against any string field",
|
|
178
|
+
"Search the table by a phrase matched against any string field, using the syntax of web search engines",
|
|
177
179
|
properties: {
|
|
178
180
|
full_text_search: {
|
|
179
181
|
type: "string",
|
|
180
|
-
description:
|
|
182
|
+
description:
|
|
183
|
+
"A phrase to search the table with. The search phrase is the synatx used by web search engines: use double quotes for exact match, unquoted text for words in any order, dash (minus sign) to exclude a word. Do not use SQL or any other formal query language.",
|
|
181
184
|
},
|
|
182
185
|
},
|
|
183
186
|
},
|