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,247 @@
|
|
|
1
|
+
import "../../../chunk-CF3WOMB3.mjs";
|
|
2
|
+
import { ObjectId } from "mongodb";
|
|
3
|
+
import { Logger } from "../../../common/logger/index.js";
|
|
4
|
+
import { BaseEntity } from "../../../common/base/base.entity.js";
|
|
5
|
+
function stubNote(ref) {
|
|
6
|
+
return `Partial view: the preview is only the beginning of the result. Do not take values from it as the ones you need. Load them with read_context using name "${ref}": add "path" for a section, or "find" with the text to locate an entity by name inside the result. You cannot compare long lists by eye.`;
|
|
7
|
+
}
|
|
8
|
+
const CLEARABLE_FIELDS = ["error", "startedAt", "completedAt", "outputRef", "outputChars", "outputStub"];
|
|
9
|
+
function truncateForPrompt(value, maxChars = 3e3) {
|
|
10
|
+
if (value === void 0 || value === null) return value;
|
|
11
|
+
const text = typeof value === "string" ? value : JSON.stringify(value);
|
|
12
|
+
if (text.length <= maxChars) return value;
|
|
13
|
+
return { truncated: true, total_chars: text.length, preview: text.slice(0, maxChars) };
|
|
14
|
+
}
|
|
15
|
+
class AgentAction extends BaseEntity {
|
|
16
|
+
constructor(props, chatId, taskId, name, stepId, args, dependsOn, status, output, error, reasoning, retries, author, approved, outputRef, outputChars, startedAt, completedAt, answerId, callId, turn, outputStub, requestedName) {
|
|
17
|
+
super(props);
|
|
18
|
+
this.props = props;
|
|
19
|
+
this.chatId = chatId;
|
|
20
|
+
this.taskId = taskId;
|
|
21
|
+
this.name = name;
|
|
22
|
+
this.stepId = stepId;
|
|
23
|
+
this.args = args;
|
|
24
|
+
this.dependsOn = dependsOn;
|
|
25
|
+
this.status = status;
|
|
26
|
+
this.output = output;
|
|
27
|
+
this.error = error;
|
|
28
|
+
this.reasoning = reasoning;
|
|
29
|
+
this.retries = retries;
|
|
30
|
+
this.author = author;
|
|
31
|
+
this.approved = approved;
|
|
32
|
+
this.outputRef = outputRef;
|
|
33
|
+
this.outputChars = outputChars;
|
|
34
|
+
this.startedAt = startedAt;
|
|
35
|
+
this.completedAt = completedAt;
|
|
36
|
+
this.answerId = answerId;
|
|
37
|
+
this.callId = callId;
|
|
38
|
+
this.turn = turn;
|
|
39
|
+
this.outputStub = outputStub;
|
|
40
|
+
this.requestedName = requestedName;
|
|
41
|
+
}
|
|
42
|
+
props;
|
|
43
|
+
chatId;
|
|
44
|
+
taskId;
|
|
45
|
+
name;
|
|
46
|
+
stepId;
|
|
47
|
+
args;
|
|
48
|
+
dependsOn;
|
|
49
|
+
status;
|
|
50
|
+
output;
|
|
51
|
+
error;
|
|
52
|
+
reasoning;
|
|
53
|
+
retries;
|
|
54
|
+
author;
|
|
55
|
+
approved;
|
|
56
|
+
outputRef;
|
|
57
|
+
outputChars;
|
|
58
|
+
startedAt;
|
|
59
|
+
completedAt;
|
|
60
|
+
answerId;
|
|
61
|
+
callId;
|
|
62
|
+
turn;
|
|
63
|
+
outputStub;
|
|
64
|
+
requestedName;
|
|
65
|
+
logger = new Logger();
|
|
66
|
+
static factory(action) {
|
|
67
|
+
const actionId = action._id && ObjectId.isValid(action._id) ? new ObjectId(action._id) : new ObjectId();
|
|
68
|
+
return AgentAction.fromJSON({ ...action, _id: actionId, status: action.status ?? "pending" });
|
|
69
|
+
}
|
|
70
|
+
static fromJSON(props) {
|
|
71
|
+
return new AgentAction(
|
|
72
|
+
props,
|
|
73
|
+
BaseEntity.toObjectId(props.chatId),
|
|
74
|
+
BaseEntity.toObjectId(props.taskId),
|
|
75
|
+
props.name,
|
|
76
|
+
props.stepId,
|
|
77
|
+
props.args,
|
|
78
|
+
props.dependsOn,
|
|
79
|
+
props.status,
|
|
80
|
+
props.output,
|
|
81
|
+
props.error,
|
|
82
|
+
props.reasoning,
|
|
83
|
+
props.retries,
|
|
84
|
+
props.author,
|
|
85
|
+
props.approved,
|
|
86
|
+
props.outputRef,
|
|
87
|
+
props.outputChars,
|
|
88
|
+
props.startedAt,
|
|
89
|
+
props.completedAt,
|
|
90
|
+
BaseEntity.toObjectId(props.answerId),
|
|
91
|
+
props.callId,
|
|
92
|
+
props.turn,
|
|
93
|
+
props.outputStub,
|
|
94
|
+
props.requestedName
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
toJSON() {
|
|
98
|
+
return {
|
|
99
|
+
...super.toJSON(),
|
|
100
|
+
chatId: this.chatId,
|
|
101
|
+
taskId: this.taskId,
|
|
102
|
+
name: this.name,
|
|
103
|
+
stepId: this.stepId,
|
|
104
|
+
args: this.args,
|
|
105
|
+
dependsOn: this.dependsOn,
|
|
106
|
+
status: this.status,
|
|
107
|
+
output: this.outputStub ?? this.structuredOutput,
|
|
108
|
+
error: this.error,
|
|
109
|
+
reasoning: this.reasoning,
|
|
110
|
+
retries: this.retries,
|
|
111
|
+
author: this.author,
|
|
112
|
+
approved: this.approved,
|
|
113
|
+
outputRef: this.outputRef,
|
|
114
|
+
outputChars: this.outputChars,
|
|
115
|
+
startedAt: this.startedAt,
|
|
116
|
+
completedAt: this.completedAt,
|
|
117
|
+
answerId: this.answerId,
|
|
118
|
+
callId: this.callId,
|
|
119
|
+
turn: this.turn,
|
|
120
|
+
outputStub: this.outputStub,
|
|
121
|
+
requestedName: this.requestedName
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
get id() {
|
|
125
|
+
return this._id.toString();
|
|
126
|
+
}
|
|
127
|
+
get isReady() {
|
|
128
|
+
return this.status === "pending";
|
|
129
|
+
}
|
|
130
|
+
get isTerminal() {
|
|
131
|
+
return this.status === "completed" || this.status === "failed";
|
|
132
|
+
}
|
|
133
|
+
get canRetry() {
|
|
134
|
+
return this.status === "failed" && this.error?.retryable !== false;
|
|
135
|
+
}
|
|
136
|
+
static unwrap(value) {
|
|
137
|
+
return value?.structuredContent ? value.structuredContent : value;
|
|
138
|
+
}
|
|
139
|
+
get structuredOutput() {
|
|
140
|
+
return AgentAction.unwrap(this.output);
|
|
141
|
+
}
|
|
142
|
+
observationOutput(stale, maxChars) {
|
|
143
|
+
if (this.outputStub) return stale ? this.outputStub : this.structuredOutput;
|
|
144
|
+
if (this.outputRef) return this.structuredOutput;
|
|
145
|
+
return truncateForPrompt(this.structuredOutput, maxChars);
|
|
146
|
+
}
|
|
147
|
+
get clearedFields() {
|
|
148
|
+
return CLEARABLE_FIELDS.reduce((acc, field) => {
|
|
149
|
+
if (this[field] === void 0) acc[field] = "";
|
|
150
|
+
return acc;
|
|
151
|
+
}, {});
|
|
152
|
+
}
|
|
153
|
+
promptView(maxChars = 3e3) {
|
|
154
|
+
return {
|
|
155
|
+
ref: this.stepId ?? this.id,
|
|
156
|
+
tool: this.name,
|
|
157
|
+
args: this.args,
|
|
158
|
+
status: this.status,
|
|
159
|
+
output: this.observationOutput(false, maxChars),
|
|
160
|
+
error: this.error ? { message: this.error.message } : void 0
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
dependenciesSatisfiedBy(completedRefs) {
|
|
164
|
+
if (!this.dependsOn?.length) return true;
|
|
165
|
+
return this.dependsOn.every((ref) => completedRefs.has(ref));
|
|
166
|
+
}
|
|
167
|
+
approve() {
|
|
168
|
+
this.approved = true;
|
|
169
|
+
}
|
|
170
|
+
markRunning() {
|
|
171
|
+
this.status = "running";
|
|
172
|
+
this.startedAt = /* @__PURE__ */ new Date();
|
|
173
|
+
}
|
|
174
|
+
markCompleted(output) {
|
|
175
|
+
this.status = "completed";
|
|
176
|
+
this.output = output;
|
|
177
|
+
this.error = void 0;
|
|
178
|
+
this.completedAt = /* @__PURE__ */ new Date();
|
|
179
|
+
}
|
|
180
|
+
markFailed(error) {
|
|
181
|
+
this.status = "failed";
|
|
182
|
+
this.error = error;
|
|
183
|
+
this.completedAt = /* @__PURE__ */ new Date();
|
|
184
|
+
}
|
|
185
|
+
markSkipped() {
|
|
186
|
+
this.status = "skipped";
|
|
187
|
+
this.completedAt = /* @__PURE__ */ new Date();
|
|
188
|
+
}
|
|
189
|
+
static stubOf(offloaded) {
|
|
190
|
+
return {
|
|
191
|
+
workspace_ref: offloaded.ref,
|
|
192
|
+
total_chars: offloaded.totalChars,
|
|
193
|
+
outline: offloaded.outline,
|
|
194
|
+
preview: offloaded.preview,
|
|
195
|
+
note: stubNote(offloaded.ref)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
offloadOutput(offloaded) {
|
|
199
|
+
this.outputRef = offloaded.ref;
|
|
200
|
+
this.outputChars = offloaded.totalChars;
|
|
201
|
+
this.outputStub = void 0;
|
|
202
|
+
this.output = AgentAction.stubOf(offloaded);
|
|
203
|
+
}
|
|
204
|
+
keepOutputWithStub(offloaded) {
|
|
205
|
+
this.outputRef = offloaded.ref;
|
|
206
|
+
this.outputChars = offloaded.totalChars;
|
|
207
|
+
this.outputStub = AgentAction.stubOf(offloaded);
|
|
208
|
+
}
|
|
209
|
+
incrementRetries() {
|
|
210
|
+
this.retries = (this.retries ?? 0) + 1;
|
|
211
|
+
return this.retries;
|
|
212
|
+
}
|
|
213
|
+
resetForRetry() {
|
|
214
|
+
this.status = "pending";
|
|
215
|
+
this.error = void 0;
|
|
216
|
+
this.startedAt = void 0;
|
|
217
|
+
this.completedAt = void 0;
|
|
218
|
+
}
|
|
219
|
+
async runTool(tool, args, baseParams) {
|
|
220
|
+
if (!tool) {
|
|
221
|
+
this.markFailed({ message: `Tool "${this.name}" not found`, retryable: false });
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
const validationErrors = tool.validate(args);
|
|
225
|
+
if (validationErrors.length) {
|
|
226
|
+
this.logger.debug({ tool: tool.name, args, validationErrors }, "[Agent Action] Invalid arguments");
|
|
227
|
+
this.markFailed({ message: `Invalid arguments: ${validationErrors.join("; ")}`, retryable: false });
|
|
228
|
+
return this;
|
|
229
|
+
}
|
|
230
|
+
this.logger.debug({
|
|
231
|
+
tool: tool.name,
|
|
232
|
+
args
|
|
233
|
+
}, "[Agent Action] Running tool");
|
|
234
|
+
this.markRunning();
|
|
235
|
+
try {
|
|
236
|
+
const result = await tool.run({ ...args, ...baseParams });
|
|
237
|
+
this.markCompleted(result?.data);
|
|
238
|
+
} catch (error) {
|
|
239
|
+
this.markFailed({ message: error?.message ?? String(error), retryable: error?.retryable !== false });
|
|
240
|
+
}
|
|
241
|
+
return this;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
export {
|
|
245
|
+
AgentAction,
|
|
246
|
+
truncateForPrompt
|
|
247
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import { ObjectId } from 'mongodb';
|
|
2
|
+
import { BaseEntity, BaseEntityProps } from '../../../common/base/base.entity.js';
|
|
3
|
+
import type { LLMMessage } from '../../../clients/llm-types.js';
|
|
4
|
+
import { AgentAction, ActionDescriptor } from './agent-action.entity';
|
|
5
|
+
export declare enum TaskStatus {
|
|
6
|
+
PENDING = "pending",
|
|
7
|
+
IN_PROGRESS = "in_progress",
|
|
8
|
+
AWAITING_USER = "awaiting_user",
|
|
9
|
+
COMPLETED = "completed",
|
|
10
|
+
PAUSED = "paused",
|
|
11
|
+
ABANDONED = "abandoned",
|
|
12
|
+
CANCELLED = "cancelled",
|
|
13
|
+
FAILED = "failed"
|
|
14
|
+
}
|
|
15
|
+
export interface AgentTaskProps extends BaseEntityProps {
|
|
16
|
+
chatId?: string | ObjectId;
|
|
17
|
+
status?: TaskStatus;
|
|
18
|
+
goal?: string;
|
|
19
|
+
nextNode?: string;
|
|
20
|
+
threadId?: string;
|
|
21
|
+
previousTaskId?: string;
|
|
22
|
+
summary?: string;
|
|
23
|
+
loopName?: string;
|
|
24
|
+
planCount?: number;
|
|
25
|
+
planOffset?: number;
|
|
26
|
+
executedOffset?: number;
|
|
27
|
+
scratch?: Record<string, any>;
|
|
28
|
+
opening?: string;
|
|
29
|
+
turns?: TurnRecord[];
|
|
30
|
+
known?: Record<string, string>;
|
|
31
|
+
schemas?: Record<string, ToolSchemaSummary>;
|
|
32
|
+
}
|
|
33
|
+
export interface ToolSchemaSummary {
|
|
34
|
+
required: string[];
|
|
35
|
+
optional: string[];
|
|
36
|
+
}
|
|
37
|
+
export interface TurnRecord {
|
|
38
|
+
turn: number;
|
|
39
|
+
reasoning?: string;
|
|
40
|
+
state?: Record<string, any>;
|
|
41
|
+
}
|
|
42
|
+
export interface ActionRequest {
|
|
43
|
+
tool?: string;
|
|
44
|
+
arguments?: Record<string, any> | string;
|
|
45
|
+
}
|
|
46
|
+
export interface TurnOutput {
|
|
47
|
+
reasoning?: string;
|
|
48
|
+
state?: Record<string, any>;
|
|
49
|
+
actions?: ActionRequest[];
|
|
50
|
+
learned?: {
|
|
51
|
+
key?: string;
|
|
52
|
+
value?: any;
|
|
53
|
+
}[];
|
|
54
|
+
}
|
|
55
|
+
export interface PlanStepDescriptor {
|
|
56
|
+
stepId: string | number;
|
|
57
|
+
name: string;
|
|
58
|
+
args?: Record<string, any>;
|
|
59
|
+
dependsOn?: Array<string | number>;
|
|
60
|
+
reasoning?: string;
|
|
61
|
+
}
|
|
62
|
+
export interface RefSources {
|
|
63
|
+
stepOutput?: (action: AgentAction) => any;
|
|
64
|
+
context?: (name: string) => any;
|
|
65
|
+
}
|
|
66
|
+
export interface CollectedRefs {
|
|
67
|
+
steps: string[];
|
|
68
|
+
contexts: string[];
|
|
69
|
+
}
|
|
70
|
+
export declare const ASK_USER = "ask_user";
|
|
71
|
+
export declare const SEARCH_TOOLS = "search_tools";
|
|
72
|
+
export declare const RESPOND = "respond";
|
|
73
|
+
export declare const NATIVE_TOOL_NAMES: string[];
|
|
74
|
+
export declare function resolveToolName(name: string, declared: string[]): string | undefined;
|
|
75
|
+
export declare function findInvoker(tools: {
|
|
76
|
+
name: string;
|
|
77
|
+
parameters?: Record<string, any>;
|
|
78
|
+
}[]): string | undefined;
|
|
79
|
+
export declare function seenHiddenTool(written: string, invoker: string, schemas?: Record<string, unknown>): string | undefined;
|
|
80
|
+
export declare function stableStringify(value: any): string;
|
|
81
|
+
export declare function readPath(value: any, path?: string): any;
|
|
82
|
+
export declare class AgentTask extends BaseEntity {
|
|
83
|
+
private readonly props;
|
|
84
|
+
chatId?: ObjectId | undefined;
|
|
85
|
+
status?: TaskStatus | undefined;
|
|
86
|
+
goal?: string | undefined;
|
|
87
|
+
nextNode?: string | undefined;
|
|
88
|
+
threadId?: string | undefined;
|
|
89
|
+
previousTaskId?: string | undefined;
|
|
90
|
+
summary?: string | undefined;
|
|
91
|
+
loopName?: string | undefined;
|
|
92
|
+
planCount: number;
|
|
93
|
+
planOffset: number;
|
|
94
|
+
executedOffset: number;
|
|
95
|
+
scratch?: Record<string, any> | undefined;
|
|
96
|
+
opening?: string | undefined;
|
|
97
|
+
turns: TurnRecord[];
|
|
98
|
+
known?: Record<string, string> | undefined;
|
|
99
|
+
schemas?: Record<string, ToolSchemaSummary> | undefined;
|
|
100
|
+
static factory(task: AgentTaskProps): AgentTask;
|
|
101
|
+
static fromJSON(props: AgentTaskProps): AgentTask;
|
|
102
|
+
static collectRefs(value: any): CollectedRefs;
|
|
103
|
+
actions: AgentAction[];
|
|
104
|
+
hydrated: boolean;
|
|
105
|
+
constructor(props: AgentTaskProps, chatId?: ObjectId | undefined, status?: TaskStatus | undefined, goal?: string | undefined, nextNode?: string | undefined, threadId?: string | undefined, previousTaskId?: string | undefined, summary?: string | undefined, loopName?: string | undefined, planCount?: number, planOffset?: number, executedOffset?: number, scratch?: Record<string, any> | undefined, opening?: string | undefined, turns?: TurnRecord[], known?: Record<string, string> | undefined, schemas?: Record<string, ToolSchemaSummary> | undefined);
|
|
106
|
+
toJSON(): AgentTaskProps;
|
|
107
|
+
get id(): string;
|
|
108
|
+
get clearedFields(): Record<string, ''>;
|
|
109
|
+
setActions(actions: AgentAction[]): void;
|
|
110
|
+
setScratch(key: string, value: any): void;
|
|
111
|
+
getScratch<T = any>(key: string): T | undefined;
|
|
112
|
+
clearScratch(key: string): void;
|
|
113
|
+
addAction(descriptor: ActionDescriptor): AgentAction;
|
|
114
|
+
addPlan(steps: PlanStepDescriptor[], author?: string): AgentAction[];
|
|
115
|
+
skipPending(): number;
|
|
116
|
+
approvePending(): number;
|
|
117
|
+
getAction(ref: string): AgentAction | undefined;
|
|
118
|
+
findLastByName(name: string): AgentAction | undefined;
|
|
119
|
+
findExecuted(name: string | undefined, args: Record<string, any> | undefined, opts?: {
|
|
120
|
+
status?: 'completed' | 'failed';
|
|
121
|
+
exclude?: AgentAction;
|
|
122
|
+
}): AgentAction | undefined;
|
|
123
|
+
hasExecuted(name?: string, args?: Record<string, any>): boolean;
|
|
124
|
+
get readyActions(): AgentAction[];
|
|
125
|
+
get pendingQuestion(): string | undefined;
|
|
126
|
+
get turnCount(): number;
|
|
127
|
+
get toolCallCount(): number;
|
|
128
|
+
answerQuestion(answer: string): boolean;
|
|
129
|
+
get state(): Record<string, any> | undefined;
|
|
130
|
+
get pendingAnswer(): string | undefined;
|
|
131
|
+
get rejectedAnswers(): number;
|
|
132
|
+
rejectAnswer(message: string): void;
|
|
133
|
+
forceAnswer(fallback: string): string;
|
|
134
|
+
static answerFrom(output: TurnOutput): string | undefined;
|
|
135
|
+
deliverAnswer(): void;
|
|
136
|
+
remember(learned: any): void;
|
|
137
|
+
learnSchemas(output: any): void;
|
|
138
|
+
addTurn(output: TurnOutput, opts?: {
|
|
139
|
+
author?: string;
|
|
140
|
+
declaredTools?: string[];
|
|
141
|
+
invoker?: string;
|
|
142
|
+
}): AgentAction[];
|
|
143
|
+
history(notice?: Record<string, any>): LLMMessage[];
|
|
144
|
+
get workspaceStreak(): number;
|
|
145
|
+
get sameToolStreak(): {
|
|
146
|
+
name?: string;
|
|
147
|
+
count: number;
|
|
148
|
+
};
|
|
149
|
+
get discoveredToolNames(): string[];
|
|
150
|
+
get failedActions(): AgentAction[];
|
|
151
|
+
get executedActions(): AgentAction[];
|
|
152
|
+
get lastExecutedAction(): AgentAction | undefined;
|
|
153
|
+
get replanCount(): number;
|
|
154
|
+
get executedSinceOpen(): number;
|
|
155
|
+
executionHistory(maxChars?: number): {
|
|
156
|
+
ref: string;
|
|
157
|
+
tool: string | undefined;
|
|
158
|
+
args: Record<string, any> | undefined;
|
|
159
|
+
status: import("./agent-action.entity").ActionStatus | undefined;
|
|
160
|
+
output: any;
|
|
161
|
+
error: {
|
|
162
|
+
message: string;
|
|
163
|
+
} | undefined;
|
|
164
|
+
}[];
|
|
165
|
+
setNextNode(node?: string): void;
|
|
166
|
+
complete(summary?: string): void;
|
|
167
|
+
fail(): void;
|
|
168
|
+
cancel(): void;
|
|
169
|
+
pause(): void;
|
|
170
|
+
reopen(): void;
|
|
171
|
+
findActionByRef(ref: string): AgentAction | undefined;
|
|
172
|
+
referencedActions(value: any): AgentAction[];
|
|
173
|
+
resolveArgs(action: AgentAction, sources: RefSources, unresolved?: string[]): any;
|
|
174
|
+
private resolveValue;
|
|
175
|
+
private readStepValue;
|
|
176
|
+
}
|