openloops 0.1.31 → 0.1.33
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/clients/llm-client.d.ts +5 -0
- package/dist/clients/llm-client.js +73 -15
- package/dist/clients/llm-client.mjs +73 -15
- package/dist/clients/llm-error.d.ts +9 -0
- package/dist/clients/llm-error.js +69 -0
- package/dist/clients/llm-error.mjs +45 -0
- package/dist/clients/llm-types.d.ts +61 -0
- package/dist/clients/llm-types.js +16 -0
- package/dist/clients/llm-types.mjs +0 -0
- package/dist/clients/pi-ai-adapter.d.ts +7 -0
- package/dist/clients/pi-ai-adapter.js +137 -0
- package/dist/clients/pi-ai-adapter.mjs +113 -0
- package/dist/{agent → harness}/agent-loop.d.ts +11 -1
- package/dist/{agent → harness}/agent-state.js +1 -1
- package/dist/{agent → harness}/agent-state.mjs +1 -1
- package/dist/{agent → harness}/agent.d.ts +34 -3
- package/dist/harness/agent.js +546 -0
- package/dist/harness/agent.mjs +530 -0
- package/dist/{agent → harness}/index.js +5 -5
- package/dist/harness/native-tools.d.ts +23 -0
- package/dist/harness/native-tools.js +251 -0
- package/dist/harness/native-tools.mjs +227 -0
- package/dist/harness/tool-catalog.d.ts +16 -0
- package/dist/harness/tool-catalog.js +85 -0
- package/dist/harness/tool-catalog.mjs +59 -0
- package/dist/harness/tool-pipeline.d.ts +42 -0
- package/dist/harness/tool-pipeline.js +200 -0
- package/dist/harness/tool-pipeline.mjs +177 -0
- package/dist/harness/utils/describe-shape.d.ts +2 -0
- package/dist/harness/utils/describe-shape.js +56 -0
- package/dist/harness/utils/describe-shape.mjs +32 -0
- package/dist/harness/utils/grounding.d.ts +6 -0
- package/dist/harness/utils/grounding.js +79 -0
- package/dist/harness/utils/grounding.mjs +53 -0
- package/dist/harness/workspace.d.ts +44 -0
- package/dist/harness/workspace.js +95 -0
- package/dist/harness/workspace.mjs +78 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/dist/loops/agi/index.d.ts +1 -0
- package/dist/loops/agi/index.js +22 -0
- package/dist/loops/agi/index.mjs +1 -0
- package/dist/loops/agi/loop.d.ts +24 -0
- package/dist/loops/agi/loop.js +220 -0
- package/dist/loops/agi/loop.mjs +197 -0
- package/dist/loops/agi/skills/reasoning-engine.d.ts +14 -0
- package/dist/loops/agi/skills/reasoning-engine.js +94 -0
- package/dist/loops/agi/skills/reasoning-engine.mjs +71 -0
- package/dist/loops/index.d.ts +1 -0
- package/dist/loops/index.js +3 -1
- package/dist/loops/index.mjs +1 -0
- package/dist/loops/plan-execute/plan-execute-loop.d.ts +2 -1
- package/dist/loops/plan-execute/plan-execute-loop.js +90 -35
- package/dist/loops/plan-execute/plan-execute-loop.mjs +80 -25
- package/dist/loops/shared/skills/action-planner.js +7 -4
- package/dist/loops/shared/skills/action-planner.mjs +7 -4
- package/dist/loops/shared/skills/final-responder.js +4 -3
- package/dist/loops/shared/skills/final-responder.mjs +4 -3
- package/dist/loops/shared/skills/state-observer.js +6 -2
- package/dist/loops/shared/skills/state-observer.mjs +6 -2
- package/dist/services/chats/entities/chat-message.entity.d.ts +4 -1
- package/dist/services/chats/entities/chat-message.entity.js +7 -3
- package/dist/services/chats/entities/chat-message.entity.mjs +7 -3
- package/dist/services/chats/entities/chat.entity.d.ts +10 -11
- package/dist/services/chats/entities/chat.entity.js +17 -21
- package/dist/services/chats/entities/chat.entity.mjs +17 -21
- package/dist/services/chats/lambdas/get-chat-by-id/get-chat-by-id.use-case.d.ts +2 -0
- package/dist/services/chats/lambdas/get-chat-by-id/get-chat-by-id.use-case.js +4 -4
- package/dist/services/chats/lambdas/get-chat-by-id/get-chat-by-id.use-case.mjs +2 -2
- package/dist/services/tasks/entities/agent-action.entity.d.ts +111 -0
- package/dist/services/tasks/entities/agent-action.entity.js +271 -0
- package/dist/services/tasks/entities/agent-action.entity.mjs +247 -0
- package/dist/services/tasks/entities/agent-task.entity.d.ts +176 -0
- package/dist/services/tasks/entities/agent-task.entity.js +695 -0
- package/dist/services/tasks/entities/agent-task.entity.mjs +662 -0
- package/dist/services/tasks/entities/index.d.ts +2 -0
- package/dist/services/tasks/entities/index.js +24 -0
- package/dist/services/tasks/entities/index.mjs +2 -0
- package/dist/services/tasks/index.d.ts +3 -0
- package/dist/services/tasks/index.js +26 -0
- package/dist/services/tasks/index.mjs +3 -0
- package/dist/services/tasks/lambdas/create-agent-action/create-agent-action.use-case.d.ts +14 -0
- package/dist/services/tasks/lambdas/create-agent-action/create-agent-action.use-case.js +60 -0
- package/dist/services/tasks/lambdas/create-agent-action/create-agent-action.use-case.mjs +31 -0
- package/dist/services/tasks/lambdas/create-agent-action/index.d.ts +1 -0
- package/dist/services/tasks/lambdas/create-agent-action/index.js +22 -0
- package/dist/services/tasks/lambdas/create-agent-action/index.mjs +1 -0
- package/dist/services/tasks/lambdas/create-agent-task/create-agent-task.use-case.d.ts +14 -0
- package/dist/services/tasks/lambdas/create-agent-task/create-agent-task.use-case.js +60 -0
- package/dist/services/tasks/lambdas/create-agent-task/create-agent-task.use-case.mjs +31 -0
- package/dist/services/tasks/lambdas/create-agent-task/index.d.ts +1 -0
- package/dist/services/tasks/lambdas/create-agent-task/index.js +22 -0
- package/dist/services/tasks/lambdas/create-agent-task/index.mjs +1 -0
- package/dist/services/tasks/lambdas/get-agent-task-by-id/get-agent-task-by-id.use-case.d.ts +14 -0
- package/dist/services/tasks/lambdas/get-agent-task-by-id/get-agent-task-by-id.use-case.js +55 -0
- package/dist/services/tasks/lambdas/get-agent-task-by-id/get-agent-task-by-id.use-case.mjs +26 -0
- package/dist/services/tasks/lambdas/get-agent-task-by-id/index.d.ts +1 -0
- package/dist/services/tasks/lambdas/get-agent-task-by-id/index.js +22 -0
- package/dist/services/tasks/lambdas/get-agent-task-by-id/index.mjs +1 -0
- package/dist/services/tasks/lambdas/index.d.ts +7 -0
- package/dist/services/tasks/lambdas/index.js +46 -0
- package/dist/services/tasks/lambdas/index.mjs +17 -0
- package/dist/services/tasks/lambdas/list-agent-actions-by-task/index.d.ts +1 -0
- package/dist/services/tasks/lambdas/list-agent-actions-by-task/index.js +22 -0
- package/dist/services/tasks/lambdas/list-agent-actions-by-task/index.mjs +1 -0
- package/dist/services/tasks/lambdas/list-agent-actions-by-task/list-agent-actions-by-task.use-case.d.ts +16 -0
- package/dist/services/tasks/lambdas/list-agent-actions-by-task/list-agent-actions-by-task.use-case.js +62 -0
- package/dist/services/tasks/lambdas/list-agent-actions-by-task/list-agent-actions-by-task.use-case.mjs +33 -0
- package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/index.d.ts +1 -0
- package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/index.js +22 -0
- package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/index.mjs +1 -0
- package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/list-agent-tasks-by-chat.use-case.d.ts +16 -0
- package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/list-agent-tasks-by-chat.use-case.js +62 -0
- package/dist/services/tasks/lambdas/list-agent-tasks-by-chat/list-agent-tasks-by-chat.use-case.mjs +33 -0
- package/dist/services/tasks/lambdas/update-agent-action/index.d.ts +1 -0
- package/dist/services/tasks/lambdas/update-agent-action/index.js +22 -0
- package/dist/services/tasks/lambdas/update-agent-action/index.mjs +1 -0
- package/dist/services/tasks/lambdas/update-agent-action/update-agent-action.use-case.d.ts +15 -0
- package/dist/services/tasks/lambdas/update-agent-action/update-agent-action.use-case.js +67 -0
- package/dist/services/tasks/lambdas/update-agent-action/update-agent-action.use-case.mjs +38 -0
- package/dist/services/tasks/lambdas/update-agent-task/index.d.ts +1 -0
- package/dist/services/tasks/lambdas/update-agent-task/index.js +22 -0
- package/dist/services/tasks/lambdas/update-agent-task/index.mjs +1 -0
- package/dist/services/tasks/lambdas/update-agent-task/update-agent-task.use-case.d.ts +15 -0
- package/dist/services/tasks/lambdas/update-agent-task/update-agent-task.use-case.js +67 -0
- package/dist/services/tasks/lambdas/update-agent-task/update-agent-task.use-case.mjs +38 -0
- package/dist/services/tasks/module.d.ts +15 -0
- package/dist/services/tasks/module.js +76 -0
- package/dist/services/tasks/module.mjs +47 -0
- package/dist/services/tasks/repositories/agent-action.repository.d.ts +8 -0
- package/dist/services/tasks/repositories/agent-action.repository.js +62 -0
- package/dist/services/tasks/repositories/agent-action.repository.mjs +33 -0
- package/dist/services/tasks/repositories/agent-task.repository.d.ts +9 -0
- package/dist/services/tasks/repositories/agent-task.repository.js +65 -0
- package/dist/services/tasks/repositories/agent-task.repository.mjs +36 -0
- package/dist/services/tasks/repositories/index.d.ts +2 -0
- package/dist/services/tasks/repositories/index.js +24 -0
- package/dist/services/tasks/repositories/index.mjs +2 -0
- package/dist/services/traces/entities/agent-trace-entry.entity.d.ts +30 -0
- package/dist/services/traces/entities/agent-trace-entry.entity.js +85 -0
- package/dist/services/traces/entities/agent-trace-entry.entity.mjs +62 -0
- package/dist/services/traces/entities/index.d.ts +1 -0
- package/dist/services/traces/entities/index.js +22 -0
- package/dist/services/traces/entities/index.mjs +1 -0
- package/dist/services/traces/index.d.ts +3 -0
- package/dist/services/traces/index.js +26 -0
- package/dist/services/traces/index.mjs +3 -0
- package/dist/services/traces/lambdas/create-agent-traces/create-agent-traces.use-case.d.ts +16 -0
- package/dist/services/traces/lambdas/create-agent-traces/create-agent-traces.use-case.js +62 -0
- package/dist/services/traces/lambdas/create-agent-traces/create-agent-traces.use-case.mjs +33 -0
- package/dist/services/traces/lambdas/create-agent-traces/index.d.ts +1 -0
- package/dist/services/traces/lambdas/create-agent-traces/index.js +22 -0
- package/dist/services/traces/lambdas/create-agent-traces/index.mjs +1 -0
- package/dist/services/traces/lambdas/index.d.ts +2 -0
- package/dist/services/traces/lambdas/index.js +31 -0
- package/dist/services/traces/lambdas/index.mjs +7 -0
- package/dist/services/traces/lambdas/list-agent-traces-by-chat/index.d.ts +1 -0
- package/dist/services/traces/lambdas/list-agent-traces-by-chat/index.js +22 -0
- package/dist/services/traces/lambdas/list-agent-traces-by-chat/index.mjs +1 -0
- package/dist/services/traces/lambdas/list-agent-traces-by-chat/list-agent-traces-by-chat.use-case.d.ts +18 -0
- package/dist/services/traces/lambdas/list-agent-traces-by-chat/list-agent-traces-by-chat.use-case.js +67 -0
- package/dist/services/traces/lambdas/list-agent-traces-by-chat/list-agent-traces-by-chat.use-case.mjs +38 -0
- package/dist/services/traces/module.d.ts +5 -0
- package/dist/services/traces/module.js +41 -0
- package/dist/services/traces/module.mjs +17 -0
- package/dist/services/traces/repositories/agent-trace.repository.d.ts +7 -0
- package/dist/services/traces/repositories/agent-trace.repository.js +55 -0
- package/dist/services/traces/repositories/agent-trace.repository.mjs +26 -0
- package/dist/services/traces/repositories/index.d.ts +1 -0
- package/dist/services/traces/repositories/index.js +22 -0
- package/dist/services/traces/repositories/index.mjs +1 -0
- package/dist/services/workspaces/entities/index.d.ts +1 -0
- package/dist/services/workspaces/entities/index.js +22 -0
- package/dist/services/workspaces/entities/index.mjs +1 -0
- package/dist/services/workspaces/entities/workspace-item.entity.d.ts +33 -0
- package/dist/services/workspaces/entities/workspace-item.entity.js +95 -0
- package/dist/services/workspaces/entities/workspace-item.entity.mjs +72 -0
- package/dist/services/workspaces/index.d.ts +3 -0
- package/dist/services/workspaces/index.js +26 -0
- package/dist/services/workspaces/index.mjs +3 -0
- package/dist/services/workspaces/lambdas/delete-workspace-item/delete-workspace-item.use-case.d.ts +17 -0
- package/dist/services/workspaces/lambdas/delete-workspace-item/delete-workspace-item.use-case.js +68 -0
- package/dist/services/workspaces/lambdas/delete-workspace-item/delete-workspace-item.use-case.mjs +39 -0
- package/dist/services/workspaces/lambdas/delete-workspace-item/index.d.ts +1 -0
- package/dist/services/workspaces/lambdas/delete-workspace-item/index.js +22 -0
- package/dist/services/workspaces/lambdas/delete-workspace-item/index.mjs +1 -0
- package/dist/services/workspaces/lambdas/get-workspace-item/get-workspace-item.use-case.d.ts +17 -0
- package/dist/services/workspaces/lambdas/get-workspace-item/get-workspace-item.use-case.js +67 -0
- package/dist/services/workspaces/lambdas/get-workspace-item/get-workspace-item.use-case.mjs +38 -0
- package/dist/services/workspaces/lambdas/get-workspace-item/index.d.ts +1 -0
- package/dist/services/workspaces/lambdas/get-workspace-item/index.js +22 -0
- package/dist/services/workspaces/lambdas/get-workspace-item/index.mjs +1 -0
- package/dist/services/workspaces/lambdas/index.d.ts +5 -0
- package/dist/services/workspaces/lambdas/index.js +40 -0
- package/dist/services/workspaces/lambdas/index.mjs +13 -0
- package/dist/services/workspaces/lambdas/list-workspace-items/index.d.ts +1 -0
- package/dist/services/workspaces/lambdas/list-workspace-items/index.js +22 -0
- package/dist/services/workspaces/lambdas/list-workspace-items/index.mjs +1 -0
- package/dist/services/workspaces/lambdas/list-workspace-items/list-workspace-items.use-case.d.ts +18 -0
- package/dist/services/workspaces/lambdas/list-workspace-items/list-workspace-items.use-case.js +69 -0
- package/dist/services/workspaces/lambdas/list-workspace-items/list-workspace-items.use-case.mjs +40 -0
- package/dist/services/workspaces/lambdas/save-workspace-item/index.d.ts +1 -0
- package/dist/services/workspaces/lambdas/save-workspace-item/index.js +22 -0
- package/dist/services/workspaces/lambdas/save-workspace-item/index.mjs +1 -0
- package/dist/services/workspaces/lambdas/save-workspace-item/save-workspace-item.use-case.d.ts +14 -0
- package/dist/services/workspaces/lambdas/save-workspace-item/save-workspace-item.use-case.js +76 -0
- package/dist/services/workspaces/lambdas/save-workspace-item/save-workspace-item.use-case.mjs +47 -0
- package/dist/services/workspaces/lambdas/search-workspace-items/index.d.ts +1 -0
- package/dist/services/workspaces/lambdas/search-workspace-items/index.js +22 -0
- package/dist/services/workspaces/lambdas/search-workspace-items/index.mjs +1 -0
- package/dist/services/workspaces/lambdas/search-workspace-items/search-workspace-items.use-case.d.ts +19 -0
- package/dist/services/workspaces/lambdas/search-workspace-items/search-workspace-items.use-case.js +73 -0
- package/dist/services/workspaces/lambdas/search-workspace-items/search-workspace-items.use-case.mjs +44 -0
- package/dist/services/workspaces/module.d.ts +11 -0
- package/dist/services/workspaces/module.js +62 -0
- package/dist/services/workspaces/module.mjs +35 -0
- package/dist/services/workspaces/repositories/index.d.ts +1 -0
- package/dist/services/workspaces/repositories/index.js +22 -0
- package/dist/services/workspaces/repositories/index.mjs +1 -0
- package/dist/services/workspaces/repositories/workspace-item.repository.d.ts +18 -0
- package/dist/services/workspaces/repositories/workspace-item.repository.js +74 -0
- package/dist/services/workspaces/repositories/workspace-item.repository.mjs +45 -0
- package/dist/skills/runtime-context.d.ts +8 -0
- package/dist/skills/runtime-context.js +65 -0
- package/dist/skills/runtime-context.mjs +42 -0
- package/dist/skills/skill.d.ts +7 -0
- package/dist/skills/skill.js +26 -60
- package/dist/skills/skill.mjs +26 -60
- package/dist/tools/tool.d.ts +6 -0
- package/dist/tools/tool.js +56 -0
- package/dist/tools/tool.mjs +56 -0
- package/package.json +3 -3
- package/dist/agent/agent.js +0 -327
- package/dist/agent/agent.mjs +0 -303
- package/dist/services/chats/entities/agent-action.entity.d.ts +0 -58
- package/dist/services/chats/entities/agent-action.entity.js +0 -151
- package/dist/services/chats/entities/agent-action.entity.mjs +0 -128
- package/dist/services/chats/entities/agent-task.entity.d.ts +0 -59
- package/dist/services/chats/entities/agent-task.entity.js +0 -231
- package/dist/services/chats/entities/agent-task.entity.mjs +0 -207
- package/dist/services/chats/entities/chat-context.entity.d.ts +0 -39
- package/dist/services/chats/entities/chat-context.entity.js +0 -70
- package/dist/services/chats/entities/chat-context.entity.mjs +0 -47
- /package/dist/{agent → harness}/agent-loop.js +0 -0
- /package/dist/{agent → harness}/agent-loop.mjs +0 -0
- /package/dist/{agent → harness}/agent-state.d.ts +0 -0
- /package/dist/{agent → harness}/index.d.ts +0 -0
- /package/dist/{agent → harness}/index.mjs +0 -0
- /package/dist/{agent → harness}/utils/rank-tools-by-keywords.d.ts +0 -0
- /package/dist/{agent → harness}/utils/rank-tools-by-keywords.js +0 -0
- /package/dist/{agent → harness}/utils/rank-tools-by-keywords.mjs +0 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var workspace_exports = {};
|
|
20
|
+
__export(workspace_exports, {
|
|
21
|
+
AgentWorkspace: () => AgentWorkspace
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(workspace_exports);
|
|
24
|
+
var import_workspaces = require("../services/workspaces/index.js");
|
|
25
|
+
class AgentWorkspace {
|
|
26
|
+
constructor(chatId, currentUser, answerId) {
|
|
27
|
+
this.chatId = chatId;
|
|
28
|
+
this.currentUser = currentUser;
|
|
29
|
+
this.answerId = answerId;
|
|
30
|
+
}
|
|
31
|
+
chatId;
|
|
32
|
+
currentUser;
|
|
33
|
+
answerId;
|
|
34
|
+
async save(input) {
|
|
35
|
+
const { data } = await (0, import_workspaces.saveWorkspaceItem)({
|
|
36
|
+
payload: {
|
|
37
|
+
chatId: this.chatId,
|
|
38
|
+
taskId: input.taskId,
|
|
39
|
+
kind: input.kind ?? "note",
|
|
40
|
+
name: input.name,
|
|
41
|
+
description: input.description,
|
|
42
|
+
content: input.content,
|
|
43
|
+
source: input.source,
|
|
44
|
+
truncated: input.truncated,
|
|
45
|
+
answerId: this.answerId
|
|
46
|
+
},
|
|
47
|
+
currentUser: this.currentUser
|
|
48
|
+
});
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
async get(name, opts) {
|
|
52
|
+
const { data } = await (0, import_workspaces.getWorkspaceItem)({
|
|
53
|
+
chatId: this.chatId,
|
|
54
|
+
name,
|
|
55
|
+
taskId: opts?.taskId,
|
|
56
|
+
includeContent: opts?.includeContent,
|
|
57
|
+
currentUser: this.currentUser
|
|
58
|
+
});
|
|
59
|
+
return data;
|
|
60
|
+
}
|
|
61
|
+
async list(filters) {
|
|
62
|
+
const { data } = await (0, import_workspaces.listWorkspaceItems)({
|
|
63
|
+
chatId: this.chatId,
|
|
64
|
+
taskId: filters?.taskId,
|
|
65
|
+
kind: filters?.kind,
|
|
66
|
+
options: filters?.limit ? { limit: filters.limit } : void 0,
|
|
67
|
+
currentUser: this.currentUser
|
|
68
|
+
});
|
|
69
|
+
return data;
|
|
70
|
+
}
|
|
71
|
+
async search(query, filters) {
|
|
72
|
+
const { data } = await (0, import_workspaces.searchWorkspaceItems)({
|
|
73
|
+
chatId: this.chatId,
|
|
74
|
+
query,
|
|
75
|
+
taskId: filters?.taskId,
|
|
76
|
+
kind: filters?.kind,
|
|
77
|
+
options: filters?.limit ? { limit: filters.limit } : void 0,
|
|
78
|
+
currentUser: this.currentUser
|
|
79
|
+
});
|
|
80
|
+
return data;
|
|
81
|
+
}
|
|
82
|
+
async remove(name, opts) {
|
|
83
|
+
const { data } = await (0, import_workspaces.deleteWorkspaceItem)({
|
|
84
|
+
chatId: this.chatId,
|
|
85
|
+
name,
|
|
86
|
+
taskId: opts?.taskId,
|
|
87
|
+
currentUser: this.currentUser
|
|
88
|
+
});
|
|
89
|
+
return data.deletedCount;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
93
|
+
0 && (module.exports = {
|
|
94
|
+
AgentWorkspace
|
|
95
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import "../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import {
|
|
3
|
+
saveWorkspaceItem,
|
|
4
|
+
getWorkspaceItem,
|
|
5
|
+
listWorkspaceItems,
|
|
6
|
+
searchWorkspaceItems,
|
|
7
|
+
deleteWorkspaceItem
|
|
8
|
+
} from "../services/workspaces/index.js";
|
|
9
|
+
class AgentWorkspace {
|
|
10
|
+
constructor(chatId, currentUser, answerId) {
|
|
11
|
+
this.chatId = chatId;
|
|
12
|
+
this.currentUser = currentUser;
|
|
13
|
+
this.answerId = answerId;
|
|
14
|
+
}
|
|
15
|
+
chatId;
|
|
16
|
+
currentUser;
|
|
17
|
+
answerId;
|
|
18
|
+
async save(input) {
|
|
19
|
+
const { data } = await saveWorkspaceItem({
|
|
20
|
+
payload: {
|
|
21
|
+
chatId: this.chatId,
|
|
22
|
+
taskId: input.taskId,
|
|
23
|
+
kind: input.kind ?? "note",
|
|
24
|
+
name: input.name,
|
|
25
|
+
description: input.description,
|
|
26
|
+
content: input.content,
|
|
27
|
+
source: input.source,
|
|
28
|
+
truncated: input.truncated,
|
|
29
|
+
answerId: this.answerId
|
|
30
|
+
},
|
|
31
|
+
currentUser: this.currentUser
|
|
32
|
+
});
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
async get(name, opts) {
|
|
36
|
+
const { data } = await getWorkspaceItem({
|
|
37
|
+
chatId: this.chatId,
|
|
38
|
+
name,
|
|
39
|
+
taskId: opts?.taskId,
|
|
40
|
+
includeContent: opts?.includeContent,
|
|
41
|
+
currentUser: this.currentUser
|
|
42
|
+
});
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
45
|
+
async list(filters) {
|
|
46
|
+
const { data } = await listWorkspaceItems({
|
|
47
|
+
chatId: this.chatId,
|
|
48
|
+
taskId: filters?.taskId,
|
|
49
|
+
kind: filters?.kind,
|
|
50
|
+
options: filters?.limit ? { limit: filters.limit } : void 0,
|
|
51
|
+
currentUser: this.currentUser
|
|
52
|
+
});
|
|
53
|
+
return data;
|
|
54
|
+
}
|
|
55
|
+
async search(query, filters) {
|
|
56
|
+
const { data } = await searchWorkspaceItems({
|
|
57
|
+
chatId: this.chatId,
|
|
58
|
+
query,
|
|
59
|
+
taskId: filters?.taskId,
|
|
60
|
+
kind: filters?.kind,
|
|
61
|
+
options: filters?.limit ? { limit: filters.limit } : void 0,
|
|
62
|
+
currentUser: this.currentUser
|
|
63
|
+
});
|
|
64
|
+
return data;
|
|
65
|
+
}
|
|
66
|
+
async remove(name, opts) {
|
|
67
|
+
const { data } = await deleteWorkspaceItem({
|
|
68
|
+
chatId: this.chatId,
|
|
69
|
+
name,
|
|
70
|
+
taskId: opts?.taskId,
|
|
71
|
+
currentUser: this.currentUser
|
|
72
|
+
});
|
|
73
|
+
return data.deletedCount;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export {
|
|
77
|
+
AgentWorkspace
|
|
78
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './
|
|
1
|
+
export * from './harness';
|
package/dist/index.js
CHANGED
|
@@ -15,8 +15,8 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
15
15
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
16
|
var index_exports = {};
|
|
17
17
|
module.exports = __toCommonJS(index_exports);
|
|
18
|
-
__reExport(index_exports, require("./
|
|
18
|
+
__reExport(index_exports, require("./harness"), module.exports);
|
|
19
19
|
// Annotate the CommonJS export names for ESM import in node:
|
|
20
20
|
0 && (module.exports = {
|
|
21
|
-
...require("./
|
|
21
|
+
...require("./harness")
|
|
22
22
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./
|
|
1
|
+
export * from "./harness";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './loop';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
15
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
16
|
+
var agi_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(agi_exports);
|
|
18
|
+
__reExport(agi_exports, require("./loop"), module.exports);
|
|
19
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
20
|
+
0 && (module.exports = {
|
|
21
|
+
...require("./loop")
|
|
22
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./loop";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { AgentLoop, RunContext } from '../../harness/index.js';
|
|
2
|
+
export declare class AgiLoop extends AgentLoop {
|
|
3
|
+
get initialNode(): (ctx: RunContext) => Promise<void>;
|
|
4
|
+
get nodes(): {
|
|
5
|
+
fast_responder: (ctx: RunContext) => Promise<void>;
|
|
6
|
+
reasoning_engine: (ctx: RunContext) => Promise<void>;
|
|
7
|
+
execution_loop: (ctx: RunContext) => Promise<void>;
|
|
8
|
+
request_confirmation: (ctx: RunContext) => Promise<void>;
|
|
9
|
+
confirmation_gate: (ctx: RunContext) => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
get name(): string;
|
|
12
|
+
get version(): string;
|
|
13
|
+
get author(): {
|
|
14
|
+
name: string;
|
|
15
|
+
email: string;
|
|
16
|
+
website: string;
|
|
17
|
+
};
|
|
18
|
+
private context;
|
|
19
|
+
private fastResponder;
|
|
20
|
+
private reasoningEngine;
|
|
21
|
+
private executionLoop;
|
|
22
|
+
private requestConfirmation;
|
|
23
|
+
private confirmationGate;
|
|
24
|
+
}
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var loop_exports = {};
|
|
20
|
+
__export(loop_exports, {
|
|
21
|
+
AgiLoop: () => AgiLoop
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(loop_exports);
|
|
24
|
+
var import_harness = require("../../harness/index.js");
|
|
25
|
+
var import_agent_task = require("../../services/tasks/entities/agent-task.entity.js");
|
|
26
|
+
var import_skills = require("../shared/skills");
|
|
27
|
+
var import_grounding = require("../../harness/utils/grounding.js");
|
|
28
|
+
var import_reasoning_engine = require("./skills/reasoning-engine");
|
|
29
|
+
const MAX_TURNS = 20;
|
|
30
|
+
const MAX_TOOL_CALLS = 40;
|
|
31
|
+
const WARN_SAME_TOOL = 3;
|
|
32
|
+
const MAX_SAME_TOOL = 6;
|
|
33
|
+
const MAX_ANSWER_REJECTIONS = 1;
|
|
34
|
+
const WARN_WORKSPACE_TURNS = 3;
|
|
35
|
+
const MAX_WORKSPACE_TURNS = 7;
|
|
36
|
+
const SUMMARY_CHARS = 400;
|
|
37
|
+
const BLOCK_DUPLICATES = false;
|
|
38
|
+
class AgiLoop extends import_harness.AgentLoop {
|
|
39
|
+
get initialNode() {
|
|
40
|
+
return this.nodes.fast_responder;
|
|
41
|
+
}
|
|
42
|
+
get nodes() {
|
|
43
|
+
return {
|
|
44
|
+
fast_responder: this.fastResponder,
|
|
45
|
+
reasoning_engine: this.reasoningEngine,
|
|
46
|
+
execution_loop: this.executionLoop,
|
|
47
|
+
request_confirmation: this.requestConfirmation,
|
|
48
|
+
confirmation_gate: this.confirmationGate
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
get name() {
|
|
52
|
+
return "agi";
|
|
53
|
+
}
|
|
54
|
+
get version() {
|
|
55
|
+
return "1.0.0";
|
|
56
|
+
}
|
|
57
|
+
get author() {
|
|
58
|
+
return {
|
|
59
|
+
name: "Jose Barcos",
|
|
60
|
+
email: "jose@openloops.xyz",
|
|
61
|
+
website: "https://openloops.xyz/jose"
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
context(ctx) {
|
|
65
|
+
const agentIdentity = ctx.identity;
|
|
66
|
+
const chatHistory = ctx.chat.lastHistoryMessages();
|
|
67
|
+
return {
|
|
68
|
+
...agentIdentity && Object.keys(agentIdentity)?.length ? { agentIdentity } : {},
|
|
69
|
+
...chatHistory?.length ? { chat_history: chatHistory } : {}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
async fastResponder(ctx) {
|
|
73
|
+
ctx.chat.state?.setCurrentActivity("Analyzing requirement...");
|
|
74
|
+
const chat_history = ctx.chat.lastHistoryMessages();
|
|
75
|
+
const agentIdentity = ctx.identity;
|
|
76
|
+
const result = await import_skills.fastResponder.run({
|
|
77
|
+
...ctx.skillParams,
|
|
78
|
+
contextInjection: {
|
|
79
|
+
...agentIdentity && Object.keys(agentIdentity)?.length ? { agentIdentity } : {},
|
|
80
|
+
...chat_history?.length ? { chat_history } : {}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
ctx.chat.state?.setLanguage(result.detected_language);
|
|
84
|
+
if (!result.can_answer) {
|
|
85
|
+
ctx.setNextNode(this.nodes.reasoning_engine);
|
|
86
|
+
} else {
|
|
87
|
+
ctx.chat.state?.setStatus(import_harness.AgentStatus.IDLE);
|
|
88
|
+
ctx.setNextNode(this.nodes.fast_responder);
|
|
89
|
+
ctx.reply(result.answer ?? "");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
async reasoningEngine(ctx) {
|
|
93
|
+
ctx.chat.state?.setCurrentActivity("Thinking...");
|
|
94
|
+
const task = ctx.task ?? ctx.chat.createTask(ctx.currentMessage);
|
|
95
|
+
task.answerQuestion(ctx.currentMessage);
|
|
96
|
+
const streak = task.sameToolStreak;
|
|
97
|
+
const exhausted = task.turnCount >= MAX_TURNS || task.toolCallCount >= MAX_TOOL_CALLS;
|
|
98
|
+
const workspaceTurns = task.workspaceStreak;
|
|
99
|
+
const stuck = streak.count >= MAX_SAME_TOOL;
|
|
100
|
+
const lost = workspaceTurns >= MAX_WORKSPACE_TURNS;
|
|
101
|
+
const warning = streak.count >= WARN_SAME_TOOL ? `You ran ${streak.name} ${streak.count} turns in a row. Do not repeat it with small rewordings: follow what its results suggest, change approach, or tell the user what is missing.` : workspaceTurns >= WARN_WORKSPACE_TURNS && !lost ? `You spent ${workspaceTurns} turns in a row only reading and saving notes. Stop handling data by hand: locate what you need with read_context using 'find', then act with a tool, or tell the user what is missing.` : void 0;
|
|
102
|
+
const stopReason = exhausted ? "The task reached its limit of turns or tool calls" : stuck ? `The same tool (${streak.name}) was called ${streak.count} turns in a row without getting anywhere` : lost ? `${workspaceTurns} turns in a row went into reading and saving notes without running any tool` : void 0;
|
|
103
|
+
const lastCompletedTask = ctx.chat.lastCompletedTask();
|
|
104
|
+
const catalog = await ctx.toolCatalog();
|
|
105
|
+
const result = await import_reasoning_engine.reasoningEngine.run({
|
|
106
|
+
...ctx.skillParams,
|
|
107
|
+
history: task.history({
|
|
108
|
+
budget: { turns_left: MAX_TURNS - task.turnCount, tool_calls_left: MAX_TOOL_CALLS - task.toolCallCount },
|
|
109
|
+
...warning ? { warning } : {},
|
|
110
|
+
...task.known ? { known: task.known } : {},
|
|
111
|
+
...task.schemas ? { schemas: task.schemas } : {},
|
|
112
|
+
...stopReason ? { stop_reason: stopReason } : {}
|
|
113
|
+
}),
|
|
114
|
+
tools: catalog.tools,
|
|
115
|
+
toolChoice: "none",
|
|
116
|
+
contextInjection: {
|
|
117
|
+
...this.context(ctx),
|
|
118
|
+
...catalog.context,
|
|
119
|
+
...lastCompletedTask ? { last_completed_task: { goal: lastCompletedTask.goal, summary: lastCompletedTask.summary } } : {}
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
if (result.opening) task.opening = result.opening;
|
|
123
|
+
task.addTurn(result, { author: "reasoning_engine", declaredTools: catalog.tools.map((tool) => tool.name), invoker: (0, import_agent_task.findInvoker)(catalog.tools) });
|
|
124
|
+
if (stopReason) {
|
|
125
|
+
const answer = task.forceAnswer(`I could not finish the task: ${stopReason}.`);
|
|
126
|
+
ctx.reply(answer);
|
|
127
|
+
task.summary = answer.slice(0, SUMMARY_CHARS);
|
|
128
|
+
ctx.chat.failTask(task.id);
|
|
129
|
+
ctx.chat.state?.setStatus(import_harness.AgentStatus.IDLE);
|
|
130
|
+
ctx.setNextNode(this.nodes.fast_responder);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
ctx.setNextNode(this.nodes.execution_loop);
|
|
134
|
+
}
|
|
135
|
+
async executionLoop(ctx) {
|
|
136
|
+
const task = ctx.task;
|
|
137
|
+
const ready = task.readyActions;
|
|
138
|
+
const blocked = ready.filter((action) => ctx.requiresApproval(action));
|
|
139
|
+
const runnable = ready.filter((action) => !blocked.includes(action));
|
|
140
|
+
if (runnable.length) {
|
|
141
|
+
ctx.chat.state?.setCurrentActivity(`Running ${runnable.map((action) => action.name).join(", ")}...`);
|
|
142
|
+
await Promise.all(runnable.map((action) => ctx.runAction(action, { blockDuplicates: BLOCK_DUPLICATES })));
|
|
143
|
+
}
|
|
144
|
+
if (blocked.length) {
|
|
145
|
+
ctx.setNextNode(this.nodes.request_confirmation);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const question = task.pendingQuestion;
|
|
149
|
+
if (question) {
|
|
150
|
+
ctx.chat.state?.setStatus(import_harness.AgentStatus.AWAITING_USER_INPUT);
|
|
151
|
+
ctx.setNextNode(this.nodes.reasoning_engine);
|
|
152
|
+
ctx.reply(question);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
const answer = task.pendingAnswer;
|
|
156
|
+
if (answer !== void 0) {
|
|
157
|
+
const invented = task.rejectedAnswers < MAX_ANSWER_REJECTIONS ? await (0, import_grounding.ungroundedIdentifiers)(task, ctx.workspace, [answer]) : [];
|
|
158
|
+
if (invented.length) {
|
|
159
|
+
task.rejectAnswer(`Your answer cites the identifier${invented.length > 1 ? "s" : ""} ${invented.map((id) => `"${id}"`).join(", ")}, which ${invented.length > 1 ? "were" : "was"} ${import_grounding.UNGROUNDED_PHRASE}. Do not state values you did not get from a result or from the user: remove ${invented.length > 1 ? "them" : "it"}, or obtain ${invented.length > 1 ? "them" : "it"} with a tool, and answer again.`);
|
|
160
|
+
ctx.setNextNode(this.nodes.reasoning_engine);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
task.deliverAnswer();
|
|
164
|
+
ctx.reply(answer);
|
|
165
|
+
ctx.chat.completeTask(task.id, answer.slice(0, SUMMARY_CHARS));
|
|
166
|
+
ctx.chat.state?.setStatus(import_harness.AgentStatus.IDLE);
|
|
167
|
+
ctx.setNextNode(this.nodes.fast_responder);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
ctx.setNextNode(this.nodes.reasoning_engine);
|
|
171
|
+
}
|
|
172
|
+
async requestConfirmation(ctx) {
|
|
173
|
+
const task = ctx.task;
|
|
174
|
+
const pending = task.readyActions.filter((action) => ctx.requiresApproval(action));
|
|
175
|
+
const catalog = await ctx.toolCatalog();
|
|
176
|
+
const result = await import_reasoning_engine.reasoningEngine.run({
|
|
177
|
+
...ctx.skillParams,
|
|
178
|
+
history: task.history({ pending_confirmation: pending.map((action) => action.promptView()) }),
|
|
179
|
+
tools: catalog.tools,
|
|
180
|
+
toolChoice: "none",
|
|
181
|
+
contextInjection: { ...this.context(ctx), ...catalog.context }
|
|
182
|
+
});
|
|
183
|
+
const question = import_agent_task.AgentTask.answerFrom(result) ?? `Do you confirm that I run ${pending.map((action) => action.name).join(", ")}?`;
|
|
184
|
+
ctx.chat.state?.setStatus(import_harness.AgentStatus.AWAITING_USER_CONFIRMATION);
|
|
185
|
+
ctx.setNextNode(this.nodes.confirmation_gate);
|
|
186
|
+
ctx.reply(question);
|
|
187
|
+
}
|
|
188
|
+
async confirmationGate(ctx) {
|
|
189
|
+
const task = ctx.task;
|
|
190
|
+
const result = await import_skills.confirmationGate.run({
|
|
191
|
+
...ctx.skillParams,
|
|
192
|
+
contextInjection: {
|
|
193
|
+
...ctx.chat.lastAnswer ? { pending_confirmation: ctx.chat.lastAnswer } : {}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
switch (result.decision) {
|
|
197
|
+
case "CONFIRMED":
|
|
198
|
+
task.approvePending();
|
|
199
|
+
ctx.chat.state?.setStatus(import_harness.AgentStatus.PROCESSING);
|
|
200
|
+
ctx.setNextNode(this.nodes.execution_loop);
|
|
201
|
+
break;
|
|
202
|
+
case "DECLINED":
|
|
203
|
+
ctx.chat.cancelTask(task.id);
|
|
204
|
+
ctx.chat.state?.setStatus(import_harness.AgentStatus.IDLE);
|
|
205
|
+
ctx.setNextNode(this.nodes.fast_responder);
|
|
206
|
+
ctx.reply(result.acknowledgement);
|
|
207
|
+
break;
|
|
208
|
+
case "UNCLEAR":
|
|
209
|
+
default:
|
|
210
|
+
ctx.chat.state?.setStatus(import_harness.AgentStatus.AWAITING_USER_CONFIRMATION);
|
|
211
|
+
ctx.setNextNode(this.nodes.confirmation_gate);
|
|
212
|
+
ctx.reply(result.clarification_prompt);
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
218
|
+
0 && (module.exports = {
|
|
219
|
+
AgiLoop
|
|
220
|
+
});
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import "../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { AgentLoop, AgentStatus } from "../../harness/index.js";
|
|
3
|
+
import { AgentTask, findInvoker } from "../../services/tasks/entities/agent-task.entity.js";
|
|
4
|
+
import { fastResponder, confirmationGate } from "../shared/skills";
|
|
5
|
+
import { ungroundedIdentifiers, UNGROUNDED_PHRASE } from "../../harness/utils/grounding.js";
|
|
6
|
+
import { reasoningEngine } from "./skills/reasoning-engine";
|
|
7
|
+
const MAX_TURNS = 20;
|
|
8
|
+
const MAX_TOOL_CALLS = 40;
|
|
9
|
+
const WARN_SAME_TOOL = 3;
|
|
10
|
+
const MAX_SAME_TOOL = 6;
|
|
11
|
+
const MAX_ANSWER_REJECTIONS = 1;
|
|
12
|
+
const WARN_WORKSPACE_TURNS = 3;
|
|
13
|
+
const MAX_WORKSPACE_TURNS = 7;
|
|
14
|
+
const SUMMARY_CHARS = 400;
|
|
15
|
+
const BLOCK_DUPLICATES = false;
|
|
16
|
+
class AgiLoop extends AgentLoop {
|
|
17
|
+
get initialNode() {
|
|
18
|
+
return this.nodes.fast_responder;
|
|
19
|
+
}
|
|
20
|
+
get nodes() {
|
|
21
|
+
return {
|
|
22
|
+
fast_responder: this.fastResponder,
|
|
23
|
+
reasoning_engine: this.reasoningEngine,
|
|
24
|
+
execution_loop: this.executionLoop,
|
|
25
|
+
request_confirmation: this.requestConfirmation,
|
|
26
|
+
confirmation_gate: this.confirmationGate
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
get name() {
|
|
30
|
+
return "agi";
|
|
31
|
+
}
|
|
32
|
+
get version() {
|
|
33
|
+
return "1.0.0";
|
|
34
|
+
}
|
|
35
|
+
get author() {
|
|
36
|
+
return {
|
|
37
|
+
name: "Jose Barcos",
|
|
38
|
+
email: "jose@openloops.xyz",
|
|
39
|
+
website: "https://openloops.xyz/jose"
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
context(ctx) {
|
|
43
|
+
const agentIdentity = ctx.identity;
|
|
44
|
+
const chatHistory = ctx.chat.lastHistoryMessages();
|
|
45
|
+
return {
|
|
46
|
+
...agentIdentity && Object.keys(agentIdentity)?.length ? { agentIdentity } : {},
|
|
47
|
+
...chatHistory?.length ? { chat_history: chatHistory } : {}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async fastResponder(ctx) {
|
|
51
|
+
ctx.chat.state?.setCurrentActivity("Analyzing requirement...");
|
|
52
|
+
const chat_history = ctx.chat.lastHistoryMessages();
|
|
53
|
+
const agentIdentity = ctx.identity;
|
|
54
|
+
const result = await fastResponder.run({
|
|
55
|
+
...ctx.skillParams,
|
|
56
|
+
contextInjection: {
|
|
57
|
+
...agentIdentity && Object.keys(agentIdentity)?.length ? { agentIdentity } : {},
|
|
58
|
+
...chat_history?.length ? { chat_history } : {}
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
ctx.chat.state?.setLanguage(result.detected_language);
|
|
62
|
+
if (!result.can_answer) {
|
|
63
|
+
ctx.setNextNode(this.nodes.reasoning_engine);
|
|
64
|
+
} else {
|
|
65
|
+
ctx.chat.state?.setStatus(AgentStatus.IDLE);
|
|
66
|
+
ctx.setNextNode(this.nodes.fast_responder);
|
|
67
|
+
ctx.reply(result.answer ?? "");
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async reasoningEngine(ctx) {
|
|
71
|
+
ctx.chat.state?.setCurrentActivity("Thinking...");
|
|
72
|
+
const task = ctx.task ?? ctx.chat.createTask(ctx.currentMessage);
|
|
73
|
+
task.answerQuestion(ctx.currentMessage);
|
|
74
|
+
const streak = task.sameToolStreak;
|
|
75
|
+
const exhausted = task.turnCount >= MAX_TURNS || task.toolCallCount >= MAX_TOOL_CALLS;
|
|
76
|
+
const workspaceTurns = task.workspaceStreak;
|
|
77
|
+
const stuck = streak.count >= MAX_SAME_TOOL;
|
|
78
|
+
const lost = workspaceTurns >= MAX_WORKSPACE_TURNS;
|
|
79
|
+
const warning = streak.count >= WARN_SAME_TOOL ? `You ran ${streak.name} ${streak.count} turns in a row. Do not repeat it with small rewordings: follow what its results suggest, change approach, or tell the user what is missing.` : workspaceTurns >= WARN_WORKSPACE_TURNS && !lost ? `You spent ${workspaceTurns} turns in a row only reading and saving notes. Stop handling data by hand: locate what you need with read_context using 'find', then act with a tool, or tell the user what is missing.` : void 0;
|
|
80
|
+
const stopReason = exhausted ? "The task reached its limit of turns or tool calls" : stuck ? `The same tool (${streak.name}) was called ${streak.count} turns in a row without getting anywhere` : lost ? `${workspaceTurns} turns in a row went into reading and saving notes without running any tool` : void 0;
|
|
81
|
+
const lastCompletedTask = ctx.chat.lastCompletedTask();
|
|
82
|
+
const catalog = await ctx.toolCatalog();
|
|
83
|
+
const result = await reasoningEngine.run({
|
|
84
|
+
...ctx.skillParams,
|
|
85
|
+
history: task.history({
|
|
86
|
+
budget: { turns_left: MAX_TURNS - task.turnCount, tool_calls_left: MAX_TOOL_CALLS - task.toolCallCount },
|
|
87
|
+
...warning ? { warning } : {},
|
|
88
|
+
...task.known ? { known: task.known } : {},
|
|
89
|
+
...task.schemas ? { schemas: task.schemas } : {},
|
|
90
|
+
...stopReason ? { stop_reason: stopReason } : {}
|
|
91
|
+
}),
|
|
92
|
+
tools: catalog.tools,
|
|
93
|
+
toolChoice: "none",
|
|
94
|
+
contextInjection: {
|
|
95
|
+
...this.context(ctx),
|
|
96
|
+
...catalog.context,
|
|
97
|
+
...lastCompletedTask ? { last_completed_task: { goal: lastCompletedTask.goal, summary: lastCompletedTask.summary } } : {}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
if (result.opening) task.opening = result.opening;
|
|
101
|
+
task.addTurn(result, { author: "reasoning_engine", declaredTools: catalog.tools.map((tool) => tool.name), invoker: findInvoker(catalog.tools) });
|
|
102
|
+
if (stopReason) {
|
|
103
|
+
const answer = task.forceAnswer(`I could not finish the task: ${stopReason}.`);
|
|
104
|
+
ctx.reply(answer);
|
|
105
|
+
task.summary = answer.slice(0, SUMMARY_CHARS);
|
|
106
|
+
ctx.chat.failTask(task.id);
|
|
107
|
+
ctx.chat.state?.setStatus(AgentStatus.IDLE);
|
|
108
|
+
ctx.setNextNode(this.nodes.fast_responder);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
ctx.setNextNode(this.nodes.execution_loop);
|
|
112
|
+
}
|
|
113
|
+
async executionLoop(ctx) {
|
|
114
|
+
const task = ctx.task;
|
|
115
|
+
const ready = task.readyActions;
|
|
116
|
+
const blocked = ready.filter((action) => ctx.requiresApproval(action));
|
|
117
|
+
const runnable = ready.filter((action) => !blocked.includes(action));
|
|
118
|
+
if (runnable.length) {
|
|
119
|
+
ctx.chat.state?.setCurrentActivity(`Running ${runnable.map((action) => action.name).join(", ")}...`);
|
|
120
|
+
await Promise.all(runnable.map((action) => ctx.runAction(action, { blockDuplicates: BLOCK_DUPLICATES })));
|
|
121
|
+
}
|
|
122
|
+
if (blocked.length) {
|
|
123
|
+
ctx.setNextNode(this.nodes.request_confirmation);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
const question = task.pendingQuestion;
|
|
127
|
+
if (question) {
|
|
128
|
+
ctx.chat.state?.setStatus(AgentStatus.AWAITING_USER_INPUT);
|
|
129
|
+
ctx.setNextNode(this.nodes.reasoning_engine);
|
|
130
|
+
ctx.reply(question);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const answer = task.pendingAnswer;
|
|
134
|
+
if (answer !== void 0) {
|
|
135
|
+
const invented = task.rejectedAnswers < MAX_ANSWER_REJECTIONS ? await ungroundedIdentifiers(task, ctx.workspace, [answer]) : [];
|
|
136
|
+
if (invented.length) {
|
|
137
|
+
task.rejectAnswer(`Your answer cites the identifier${invented.length > 1 ? "s" : ""} ${invented.map((id) => `"${id}"`).join(", ")}, which ${invented.length > 1 ? "were" : "was"} ${UNGROUNDED_PHRASE}. Do not state values you did not get from a result or from the user: remove ${invented.length > 1 ? "them" : "it"}, or obtain ${invented.length > 1 ? "them" : "it"} with a tool, and answer again.`);
|
|
138
|
+
ctx.setNextNode(this.nodes.reasoning_engine);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
task.deliverAnswer();
|
|
142
|
+
ctx.reply(answer);
|
|
143
|
+
ctx.chat.completeTask(task.id, answer.slice(0, SUMMARY_CHARS));
|
|
144
|
+
ctx.chat.state?.setStatus(AgentStatus.IDLE);
|
|
145
|
+
ctx.setNextNode(this.nodes.fast_responder);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
ctx.setNextNode(this.nodes.reasoning_engine);
|
|
149
|
+
}
|
|
150
|
+
async requestConfirmation(ctx) {
|
|
151
|
+
const task = ctx.task;
|
|
152
|
+
const pending = task.readyActions.filter((action) => ctx.requiresApproval(action));
|
|
153
|
+
const catalog = await ctx.toolCatalog();
|
|
154
|
+
const result = await reasoningEngine.run({
|
|
155
|
+
...ctx.skillParams,
|
|
156
|
+
history: task.history({ pending_confirmation: pending.map((action) => action.promptView()) }),
|
|
157
|
+
tools: catalog.tools,
|
|
158
|
+
toolChoice: "none",
|
|
159
|
+
contextInjection: { ...this.context(ctx), ...catalog.context }
|
|
160
|
+
});
|
|
161
|
+
const question = AgentTask.answerFrom(result) ?? `Do you confirm that I run ${pending.map((action) => action.name).join(", ")}?`;
|
|
162
|
+
ctx.chat.state?.setStatus(AgentStatus.AWAITING_USER_CONFIRMATION);
|
|
163
|
+
ctx.setNextNode(this.nodes.confirmation_gate);
|
|
164
|
+
ctx.reply(question);
|
|
165
|
+
}
|
|
166
|
+
async confirmationGate(ctx) {
|
|
167
|
+
const task = ctx.task;
|
|
168
|
+
const result = await confirmationGate.run({
|
|
169
|
+
...ctx.skillParams,
|
|
170
|
+
contextInjection: {
|
|
171
|
+
...ctx.chat.lastAnswer ? { pending_confirmation: ctx.chat.lastAnswer } : {}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
switch (result.decision) {
|
|
175
|
+
case "CONFIRMED":
|
|
176
|
+
task.approvePending();
|
|
177
|
+
ctx.chat.state?.setStatus(AgentStatus.PROCESSING);
|
|
178
|
+
ctx.setNextNode(this.nodes.execution_loop);
|
|
179
|
+
break;
|
|
180
|
+
case "DECLINED":
|
|
181
|
+
ctx.chat.cancelTask(task.id);
|
|
182
|
+
ctx.chat.state?.setStatus(AgentStatus.IDLE);
|
|
183
|
+
ctx.setNextNode(this.nodes.fast_responder);
|
|
184
|
+
ctx.reply(result.acknowledgement);
|
|
185
|
+
break;
|
|
186
|
+
case "UNCLEAR":
|
|
187
|
+
default:
|
|
188
|
+
ctx.chat.state?.setStatus(AgentStatus.AWAITING_USER_CONFIRMATION);
|
|
189
|
+
ctx.setNextNode(this.nodes.confirmation_gate);
|
|
190
|
+
ctx.reply(result.clarification_prompt);
|
|
191
|
+
break;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
export {
|
|
196
|
+
AgiLoop
|
|
197
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Skill } from '../../../skills/skill.js';
|
|
2
|
+
export type ResponseSchema = {
|
|
3
|
+
reasoning: string;
|
|
4
|
+
state: Record<string, any>;
|
|
5
|
+
actions: {
|
|
6
|
+
tool: string;
|
|
7
|
+
arguments?: Record<string, any>;
|
|
8
|
+
}[];
|
|
9
|
+
learned?: {
|
|
10
|
+
key: string;
|
|
11
|
+
value: string;
|
|
12
|
+
}[];
|
|
13
|
+
};
|
|
14
|
+
export declare const reasoningEngine: Skill<ResponseSchema>;
|