@aigne/core 0.4.201-4 → 0.4.201-6
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/lib/cjs/llm-decision-agent.js +3 -46
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/runnable-type.js +2 -0
- package/lib/cjs/utils/union.js +2 -0
- package/lib/esm/llm-decision-agent.js +5 -48
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/runnable-type.js +1 -0
- package/lib/esm/utils/union.js +1 -0
- package/lib/types/data-type-schema.d.ts +10 -3
- package/lib/types/llm-decision-agent.d.ts +6 -12
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/runnable-type.d.ts +3 -0
- package/lib/types/utils/union.d.ts +2 -0
- package/package.json +1 -1
|
@@ -15,11 +15,9 @@ var LLMDecisionAgent_1;
|
|
|
15
15
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
16
|
exports.LLMDecisionAgent = void 0;
|
|
17
17
|
exports.createLLMDecisionAgentDefinition = createLLMDecisionAgentDefinition;
|
|
18
|
-
const lodash_1 = require("lodash");
|
|
19
18
|
const nanoid_1 = require("nanoid");
|
|
20
19
|
const tsyringe_1 = require("tsyringe");
|
|
21
20
|
const constants_1 = require("./constants");
|
|
22
|
-
const data_type_schema_1 = require("./data-type-schema");
|
|
23
21
|
const llm_model_1 = require("./llm-model");
|
|
24
22
|
const runnable_1 = require("./runnable");
|
|
25
23
|
const utils_1 = require("./utils");
|
|
@@ -83,27 +81,8 @@ let LLMDecisionAgent = LLMDecisionAgent_1 = class LLMDecisionAgent extends runna
|
|
|
83
81
|
const caseToCall = cases.find((i) => i.name === functionNameToCall);
|
|
84
82
|
if (!caseToCall)
|
|
85
83
|
throw new Error('Case not found');
|
|
86
|
-
// NOTE: 将 input 转换为 variables,其中 key 为 inputId,value 为 input 的值
|
|
87
|
-
const variables = Object.fromEntries(utils_1.OrderedRecord.map(this.definition.inputs, (i) => {
|
|
88
|
-
const value = input[i.name || i.id];
|
|
89
|
-
if ((0, lodash_1.isNil)(value))
|
|
90
|
-
return null;
|
|
91
|
-
return [i.id, value];
|
|
92
|
-
}).filter(utils_1.isNonNullable));
|
|
93
|
-
const inputForCase = Object.fromEntries(Object.entries(caseToCall.input ?? {})
|
|
94
|
-
.map(([inputId, { from, fromVariableId, fromVariablePropPath }]) => {
|
|
95
|
-
const targetInput = utils_1.OrderedRecord.find(caseToCall.runnable.definition.inputs, (i) => i.id === inputId);
|
|
96
|
-
if (!targetInput?.name)
|
|
97
|
-
return null;
|
|
98
|
-
if (from !== 'variable' || !fromVariableId)
|
|
99
|
-
return null;
|
|
100
|
-
const v = variables[fromVariableId];
|
|
101
|
-
const value = fromVariablePropPath?.length ? (0, lodash_1.get)(v, fromVariablePropPath) : v;
|
|
102
|
-
return [targetInput.name, value];
|
|
103
|
-
})
|
|
104
|
-
.filter(utils_1.isNonNullable));
|
|
105
84
|
// TODO: check result structure and omit undefined values
|
|
106
|
-
return (await caseToCall.runnable.run(
|
|
85
|
+
return (await caseToCall.runnable.run(input, options));
|
|
107
86
|
}
|
|
108
87
|
};
|
|
109
88
|
exports.LLMDecisionAgent = LLMDecisionAgent;
|
|
@@ -115,7 +94,6 @@ exports.LLMDecisionAgent = LLMDecisionAgent = LLMDecisionAgent_1 = __decorate([
|
|
|
115
94
|
__metadata("design:paramtypes", [Object, llm_model_1.LLMModel, Object])
|
|
116
95
|
], LLMDecisionAgent);
|
|
117
96
|
function createLLMDecisionAgentDefinition(options) {
|
|
118
|
-
const inputs = (0, data_type_schema_1.SchemaToDataType)(options.inputs);
|
|
119
97
|
const messages = utils_1.OrderedRecord.fromArray([
|
|
120
98
|
{
|
|
121
99
|
id: (0, nanoid_1.nanoid)(),
|
|
@@ -128,34 +106,13 @@ function createLLMDecisionAgentDefinition(options) {
|
|
|
128
106
|
name: c.name || c.runnable.name,
|
|
129
107
|
description: c.description,
|
|
130
108
|
runnable: { id: c.runnable.id },
|
|
131
|
-
// TODO: pass input from decision to case runnable
|
|
132
|
-
input: Object.fromEntries(utils_1.OrderedRecord.map(c.runnable.definition.inputs, (inputOfCase) => {
|
|
133
|
-
const i = c.input?.[inputOfCase.name || inputOfCase.id];
|
|
134
|
-
if (!i) {
|
|
135
|
-
if (inputOfCase.required) {
|
|
136
|
-
throw new Error(`Input ${inputOfCase.name || inputOfCase.id} for case ${c.runnable.name || c.runnable.id} is required`);
|
|
137
|
-
}
|
|
138
|
-
// ignore optional input
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
const inputFromDecision = utils_1.OrderedRecord.find(inputs, (input) => input.name === i.fromVariable);
|
|
142
|
-
if (!inputFromDecision)
|
|
143
|
-
throw new Error(`Input ${i.fromVariable} not found`);
|
|
144
|
-
return [
|
|
145
|
-
inputOfCase.id,
|
|
146
|
-
{
|
|
147
|
-
from: 'variable',
|
|
148
|
-
fromVariableId: inputFromDecision.id,
|
|
149
|
-
fromVariablePropPath: i.fromVariablePropPath,
|
|
150
|
-
},
|
|
151
|
-
];
|
|
152
|
-
}).filter(utils_1.isNonNullable)),
|
|
153
109
|
})));
|
|
154
110
|
return {
|
|
155
111
|
id: options.id || options.name || (0, nanoid_1.nanoid)(),
|
|
156
112
|
name: options.name,
|
|
157
113
|
type: 'llm_decision_agent',
|
|
158
|
-
inputs
|
|
114
|
+
// TODO: decision agent inputs should be the intersection of all case inputs
|
|
115
|
+
inputs: utils_1.OrderedRecord.fromArray([]),
|
|
159
116
|
// TODO: decision agent outputs should be the union of all case outputs
|
|
160
117
|
outputs: utils_1.OrderedRecord.fromArray([]),
|
|
161
118
|
messages,
|