@adminforth/agent 1.2.1 → 1.3.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/agent/systemPrompt.ts +8 -0
- package/agent/tools/fetchToolSchema.ts +1 -1
- package/build.log +2 -2
- package/custom/SessionsHistory.vue +1 -1
- package/custom/chat.ts +13 -0
- package/custom/skills/mutate_data/SKILL.md +24 -2
- package/custom/useAgentStore.ts +6 -1
- package/dist/agent/systemPrompt.js +8 -0
- package/dist/agent/tools/fetchToolSchema.js +1 -1
- package/dist/custom/SessionsHistory.vue +1 -1
- package/dist/custom/chat.ts +13 -0
- package/dist/custom/skills/mutate_data/SKILL.md +24 -2
- package/dist/custom/useAgentStore.ts +6 -1
- package/package.json +1 -1
package/agent/systemPrompt.ts
CHANGED
|
@@ -26,6 +26,9 @@ export const DEFAULT_AGENT_SYSTEM_PROMPT = [
|
|
|
26
26
|
"Do not add extra explanations or suggestions unless the user asks.",
|
|
27
27
|
"Adapt to the user's tone and style of speaking, mirroring their vibe and wording.",
|
|
28
28
|
"if the user speaks casually, you should respond casually too",
|
|
29
|
+
"Never mutate data without a fresh user confirmation for that exact mutation.",
|
|
30
|
+
"A previous confirmation does not carry over to later create, update, delete, or action calls.",
|
|
31
|
+
"Each separate mutation or explicitly described batch needs its own confirmation immediately before the tool call.",
|
|
29
32
|
|
|
30
33
|
|
|
31
34
|
].join(" ");
|
|
@@ -59,8 +62,13 @@ export async function buildAgentSystemPrompt(adminforth: IAdminForth) {
|
|
|
59
62
|
"You have next default skills which you can fallback to if primary skill set does not provide a good skill:\n" +
|
|
60
63
|
formatSkills(defaultSkills, "skill_name"),
|
|
61
64
|
"Before using any skill, call fetch_skill to load its full instructions.",
|
|
65
|
+
"The fetched skill response starts with 'Tools mentioned in this skill'. Read that list first.",
|
|
62
66
|
"You can use get_resource immediately to inspect resource structure and column names.",
|
|
67
|
+
"If the user wants to create, update, delete, or run actions on records, load mutate_data first.",
|
|
68
|
+
"If the user wants to fetch records, load fetch_data first. If the user wants analytics or charts, load data-analytics first.",
|
|
63
69
|
"Only call fetch_tool_schema for tool names that are explicitly mentioned in a fetched skill and are not already available as base tools.",
|
|
70
|
+
"If a fetched skill lists a non-base tool you need, call fetch_tool_schema for it immediately instead of telling the user the tool is unavailable.",
|
|
71
|
+
"For example: for record creation load mutate_data, read its tool list, call fetch_tool_schema for create_record, and then use create_record after confirmation.",
|
|
64
72
|
"When fetch_tool_schema succeeds, that tool becomes available on the next step.",
|
|
65
73
|
"Try to call as many tools as possible in parallel in one step.",
|
|
66
74
|
];
|
|
@@ -43,7 +43,7 @@ export async function createFetchToolSchemaTool(
|
|
|
43
43
|
{
|
|
44
44
|
name: "fetch_tool_schema",
|
|
45
45
|
description:
|
|
46
|
-
"Fetch the schema for an API-based AdminForth tool by name and load it for later use.",
|
|
46
|
+
"Fetch the schema for an API-based AdminForth tool by name and load it for later use. Use this right after fetch_skill when the skill mentions non-base tools.",
|
|
47
47
|
schema: fetchToolSchemaSchema,
|
|
48
48
|
},
|
|
49
49
|
);
|
package/build.log
CHANGED
|
@@ -29,5 +29,5 @@ custom/skills/fetch_data/SKILL.md
|
|
|
29
29
|
custom/skills/mutate_data/
|
|
30
30
|
custom/skills/mutate_data/SKILL.md
|
|
31
31
|
|
|
32
|
-
sent
|
|
33
|
-
total size is
|
|
32
|
+
sent 169,588 bytes received 413 bytes 340,002.00 bytes/sec
|
|
33
|
+
total size is 167,914 speedup is 0.99
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"
|
|
7
7
|
>
|
|
8
8
|
<h3 :class="h3Style">{{ $t('Chat history') }}</h3>
|
|
9
|
-
<Button @click="agentStore.createPreSession(); agentStore.setSessionHistoryOpen(false)" :disabled="agentStore.isResponseInProgress" class="w-[360px] mx-4 my-2 mb-4 rounded-3xl text-gray-800 dark:text-gray-200">
|
|
9
|
+
<Button @click="agentStore.createPreSession(); agentStore.setSessionHistoryOpen(false); agentStore.focusTextInput();" :disabled="agentStore.isResponseInProgress" class="w-[360px] mx-4 my-2 mb-4 rounded-3xl text-gray-800 dark:text-gray-200">
|
|
10
10
|
<IconPlusOutline class="w-5 h-5" />
|
|
11
11
|
{{ $t('New chat') }}
|
|
12
12
|
</Button>
|
package/custom/chat.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is used to fix circular module initialization between ai and @ai-sdk/vue
|
|
3
|
+
* These files are depending on each other, but vite put them in different chunks, so they are not initialized at the same time, which causes the circular module initialization issue
|
|
4
|
+
* So I get rid of the @ai-sdk/vue only fixes are:
|
|
5
|
+
* 1) Change vite config to put these files in the same chunk
|
|
6
|
+
* 2) Get rid of the circular module initialization by moving the Chat class to this file
|
|
7
|
+
*
|
|
8
|
+
* Maybe there is a better way to fix this issue
|
|
9
|
+
*
|
|
10
|
+
* If you were updating "ai" package and plugin broke, probably you need to update this file as well
|
|
11
|
+
* Or resolve the circular module initialization issue in a better way
|
|
12
|
+
*/
|
|
13
|
+
|
|
1
14
|
import {
|
|
2
15
|
AbstractChat,
|
|
3
16
|
ChatInit as BaseChatInit,
|
|
@@ -2,6 +2,16 @@ name: mutate_data
|
|
|
2
2
|
description: Create/update/delete some record of resource or call actions on one or multiple records
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
# Involved tools
|
|
6
|
+
|
|
7
|
+
Use `create_record` for creating records.
|
|
8
|
+
|
|
9
|
+
Use `update_record` for editing records.
|
|
10
|
+
|
|
11
|
+
Use `delete_record` for deleting records.
|
|
12
|
+
|
|
13
|
+
Use `start_custom_action` and `start_custom_bulk_action` for resource actions.
|
|
14
|
+
|
|
5
15
|
# General rules
|
|
6
16
|
|
|
7
17
|
- if there is a dedicated action for some routine (result of `get_resource` tool call, field actions), prefer this to manual updating of records, for example, if you want to approve some comment, prefer calling `approve` action instead of updating `approved` field of comment record (because in action there might be some additional logic like sending notification to user, updating some counters and so on)
|
|
@@ -16,7 +26,19 @@ And in the same message ask user for final confirmation.
|
|
|
16
26
|
|
|
17
27
|
When creating new record, show user all data which you gona create and in same message ask for confirmation.
|
|
18
28
|
|
|
19
|
-
Accept any positive confirmation from user like "yes", "sure", "+", anything non-negative call to action, can be considered as confirmation.
|
|
29
|
+
Accept any positive confirmation from user like "yes", "sure", "+", anything non-negative call to action, can be considered as confirmation.
|
|
30
|
+
|
|
31
|
+
A confirmation is valid only for the exact mutation plan from the immediately previous assistant message.
|
|
32
|
+
|
|
33
|
+
Never reuse an older confirmation for a later mutation.
|
|
34
|
+
|
|
35
|
+
After one mutation is executed, confirmation is consumed and reset.
|
|
36
|
+
|
|
37
|
+
If you want to perform another create/update/delete/action after that, ask for confirmation again even if the user previously said "yes".
|
|
38
|
+
|
|
39
|
+
If the mutation plan changes in any way (different record, different fields, different values, different number of records, different action), the old confirmation is invalid and you must ask again.
|
|
40
|
+
|
|
41
|
+
If you are creating or deleting multiple records in one batch, you may ask once only for that exact batch, but you must list the whole batch explicitly in the confirmation message. Any extra record outside that described batch requires a new confirmation.
|
|
20
42
|
|
|
21
43
|
# Calling actions
|
|
22
44
|
|
|
@@ -105,4 +127,4 @@ I am going to create user:
|
|
|
105
127
|
View [John Doe](/admin/resource/users/show/421) # 421 is id of new created record
|
|
106
128
|
|
|
107
129
|
Are you sure?
|
|
108
|
-
```
|
|
130
|
+
```
|
package/custom/useAgentStore.ts
CHANGED
|
@@ -155,10 +155,14 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
155
155
|
function openChat() {
|
|
156
156
|
isChatOpen.value = true;
|
|
157
157
|
nextTick(() => {
|
|
158
|
-
|
|
158
|
+
focusTextInput();
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
function focusTextInput() {
|
|
163
|
+
textInput.value?.focus();
|
|
164
|
+
}
|
|
165
|
+
|
|
162
166
|
function setIsChatOpen(isOpen: boolean) {
|
|
163
167
|
isOpen ? openChat() : closeChat();
|
|
164
168
|
}
|
|
@@ -354,5 +358,6 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
354
358
|
setIsTeleportedToBody,
|
|
355
359
|
chatWidth,
|
|
356
360
|
setChatWidth,
|
|
361
|
+
focusTextInput
|
|
357
362
|
}
|
|
358
363
|
})
|
|
@@ -25,6 +25,9 @@ export const DEFAULT_AGENT_SYSTEM_PROMPT = [
|
|
|
25
25
|
"Do not add extra explanations or suggestions unless the user asks.",
|
|
26
26
|
"Adapt to the user's tone and style of speaking, mirroring their vibe and wording.",
|
|
27
27
|
"if the user speaks casually, you should respond casually too",
|
|
28
|
+
"Never mutate data without a fresh user confirmation for that exact mutation.",
|
|
29
|
+
"A previous confirmation does not carry over to later create, update, delete, or action calls.",
|
|
30
|
+
"Each separate mutation or explicitly described batch needs its own confirmation immediately before the tool call.",
|
|
28
31
|
].join(" ");
|
|
29
32
|
function formatResources(resources) {
|
|
30
33
|
return resources
|
|
@@ -54,8 +57,13 @@ export function buildAgentSystemPrompt(adminforth) {
|
|
|
54
57
|
"You have next default skills which you can fallback to if primary skill set does not provide a good skill:\n" +
|
|
55
58
|
formatSkills(defaultSkills, "skill_name"),
|
|
56
59
|
"Before using any skill, call fetch_skill to load its full instructions.",
|
|
60
|
+
"The fetched skill response starts with 'Tools mentioned in this skill'. Read that list first.",
|
|
57
61
|
"You can use get_resource immediately to inspect resource structure and column names.",
|
|
62
|
+
"If the user wants to create, update, delete, or run actions on records, load mutate_data first.",
|
|
63
|
+
"If the user wants to fetch records, load fetch_data first. If the user wants analytics or charts, load data-analytics first.",
|
|
58
64
|
"Only call fetch_tool_schema for tool names that are explicitly mentioned in a fetched skill and are not already available as base tools.",
|
|
65
|
+
"If a fetched skill lists a non-base tool you need, call fetch_tool_schema for it immediately instead of telling the user the tool is unavailable.",
|
|
66
|
+
"For example: for record creation load mutate_data, read its tool list, call fetch_tool_schema for create_record, and then use create_record after confirmation.",
|
|
59
67
|
"When fetch_tool_schema succeeds, that tool becomes available on the next step.",
|
|
60
68
|
"Try to call as many tools as possible in parallel in one step.",
|
|
61
69
|
];
|
|
@@ -29,7 +29,7 @@ export function createFetchToolSchemaTool(apiBasedTools) {
|
|
|
29
29
|
return JSON.stringify(Object.assign({ status: 200, name: toolName }, serializeApiBasedTool(toolDefinition)), null, 2);
|
|
30
30
|
}), {
|
|
31
31
|
name: "fetch_tool_schema",
|
|
32
|
-
description: "Fetch the schema for an API-based AdminForth tool by name and load it for later use.",
|
|
32
|
+
description: "Fetch the schema for an API-based AdminForth tool by name and load it for later use. Use this right after fetch_skill when the skill mentions non-base tools.",
|
|
33
33
|
schema: fetchToolSchemaSchema,
|
|
34
34
|
});
|
|
35
35
|
});
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"
|
|
7
7
|
>
|
|
8
8
|
<h3 :class="h3Style">{{ $t('Chat history') }}</h3>
|
|
9
|
-
<Button @click="agentStore.createPreSession(); agentStore.setSessionHistoryOpen(false)" :disabled="agentStore.isResponseInProgress" class="w-[360px] mx-4 my-2 mb-4 rounded-3xl text-gray-800 dark:text-gray-200">
|
|
9
|
+
<Button @click="agentStore.createPreSession(); agentStore.setSessionHistoryOpen(false); agentStore.focusTextInput();" :disabled="agentStore.isResponseInProgress" class="w-[360px] mx-4 my-2 mb-4 rounded-3xl text-gray-800 dark:text-gray-200">
|
|
10
10
|
<IconPlusOutline class="w-5 h-5" />
|
|
11
11
|
{{ $t('New chat') }}
|
|
12
12
|
</Button>
|
package/dist/custom/chat.ts
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is used to fix circular module initialization between ai and @ai-sdk/vue
|
|
3
|
+
* These files are depending on each other, but vite put them in different chunks, so they are not initialized at the same time, which causes the circular module initialization issue
|
|
4
|
+
* So I get rid of the @ai-sdk/vue only fixes are:
|
|
5
|
+
* 1) Change vite config to put these files in the same chunk
|
|
6
|
+
* 2) Get rid of the circular module initialization by moving the Chat class to this file
|
|
7
|
+
*
|
|
8
|
+
* Maybe there is a better way to fix this issue
|
|
9
|
+
*
|
|
10
|
+
* If you were updating "ai" package and plugin broke, probably you need to update this file as well
|
|
11
|
+
* Or resolve the circular module initialization issue in a better way
|
|
12
|
+
*/
|
|
13
|
+
|
|
1
14
|
import {
|
|
2
15
|
AbstractChat,
|
|
3
16
|
ChatInit as BaseChatInit,
|
|
@@ -2,6 +2,16 @@ name: mutate_data
|
|
|
2
2
|
description: Create/update/delete some record of resource or call actions on one or multiple records
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
+
# Involved tools
|
|
6
|
+
|
|
7
|
+
Use `create_record` for creating records.
|
|
8
|
+
|
|
9
|
+
Use `update_record` for editing records.
|
|
10
|
+
|
|
11
|
+
Use `delete_record` for deleting records.
|
|
12
|
+
|
|
13
|
+
Use `start_custom_action` and `start_custom_bulk_action` for resource actions.
|
|
14
|
+
|
|
5
15
|
# General rules
|
|
6
16
|
|
|
7
17
|
- if there is a dedicated action for some routine (result of `get_resource` tool call, field actions), prefer this to manual updating of records, for example, if you want to approve some comment, prefer calling `approve` action instead of updating `approved` field of comment record (because in action there might be some additional logic like sending notification to user, updating some counters and so on)
|
|
@@ -16,7 +26,19 @@ And in the same message ask user for final confirmation.
|
|
|
16
26
|
|
|
17
27
|
When creating new record, show user all data which you gona create and in same message ask for confirmation.
|
|
18
28
|
|
|
19
|
-
Accept any positive confirmation from user like "yes", "sure", "+", anything non-negative call to action, can be considered as confirmation.
|
|
29
|
+
Accept any positive confirmation from user like "yes", "sure", "+", anything non-negative call to action, can be considered as confirmation.
|
|
30
|
+
|
|
31
|
+
A confirmation is valid only for the exact mutation plan from the immediately previous assistant message.
|
|
32
|
+
|
|
33
|
+
Never reuse an older confirmation for a later mutation.
|
|
34
|
+
|
|
35
|
+
After one mutation is executed, confirmation is consumed and reset.
|
|
36
|
+
|
|
37
|
+
If you want to perform another create/update/delete/action after that, ask for confirmation again even if the user previously said "yes".
|
|
38
|
+
|
|
39
|
+
If the mutation plan changes in any way (different record, different fields, different values, different number of records, different action), the old confirmation is invalid and you must ask again.
|
|
40
|
+
|
|
41
|
+
If you are creating or deleting multiple records in one batch, you may ask once only for that exact batch, but you must list the whole batch explicitly in the confirmation message. Any extra record outside that described batch requires a new confirmation.
|
|
20
42
|
|
|
21
43
|
# Calling actions
|
|
22
44
|
|
|
@@ -105,4 +127,4 @@ I am going to create user:
|
|
|
105
127
|
View [John Doe](/admin/resource/users/show/421) # 421 is id of new created record
|
|
106
128
|
|
|
107
129
|
Are you sure?
|
|
108
|
-
```
|
|
130
|
+
```
|
|
@@ -155,10 +155,14 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
155
155
|
function openChat() {
|
|
156
156
|
isChatOpen.value = true;
|
|
157
157
|
nextTick(() => {
|
|
158
|
-
|
|
158
|
+
focusTextInput();
|
|
159
159
|
});
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
+
function focusTextInput() {
|
|
163
|
+
textInput.value?.focus();
|
|
164
|
+
}
|
|
165
|
+
|
|
162
166
|
function setIsChatOpen(isOpen: boolean) {
|
|
163
167
|
isOpen ? openChat() : closeChat();
|
|
164
168
|
}
|
|
@@ -354,5 +358,6 @@ export const useAgentStore = defineStore('agent', () => {
|
|
|
354
358
|
setIsTeleportedToBody,
|
|
355
359
|
chatWidth,
|
|
356
360
|
setChatWidth,
|
|
361
|
+
focusTextInput
|
|
357
362
|
}
|
|
358
363
|
})
|