@caretakerai/agent 0.0.38-beta.0 → 0.0.39-beta.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/dist/agent.js +11 -17
- package/package.json +1 -1
package/dist/agent.js
CHANGED
|
@@ -156,50 +156,44 @@ class Agent {
|
|
|
156
156
|
return newActivities;
|
|
157
157
|
}
|
|
158
158
|
async transformAndExecute() {
|
|
159
|
-
|
|
159
|
+
const outputHistory = [];
|
|
160
160
|
const retryErrors = [];
|
|
161
161
|
// Prepare chat messages
|
|
162
162
|
const history = [...this.history];
|
|
163
163
|
for (let i = 0; i < this.maxRetries; ++i) {
|
|
164
|
+
let inputHistory = [...history, ...outputHistory];
|
|
164
165
|
// Find the latest action and observation indices
|
|
165
|
-
const latestActionIndex =
|
|
166
|
-
const latestObservationIndex =
|
|
166
|
+
const latestActionIndex = inputHistory.findLastIndex(activity => activity.kind === activity_1.ActivityKind.Action);
|
|
167
|
+
const latestObservationIndex = inputHistory.findLastIndex(activity => activity.kind === activity_1.ActivityKind.Observation);
|
|
167
168
|
// Execute action if latest action has later index than latest observation
|
|
168
169
|
if (latestActionIndex > latestObservationIndex) {
|
|
169
170
|
try {
|
|
170
171
|
// Get action source
|
|
171
|
-
const { input: source } =
|
|
172
|
+
const { input: source } = inputHistory[latestActionIndex];
|
|
172
173
|
// Prefer custom executor is specified
|
|
173
174
|
const result = this.executor
|
|
174
175
|
? await this.executor(source)
|
|
175
176
|
: await (0, graphql_1.graphql)({ schema: this.schema, source });
|
|
176
|
-
// Recreate output history with only the latest observation
|
|
177
|
-
outputHistory = [{
|
|
178
|
-
kind: activity_1.ActivityKind.Observation,
|
|
179
|
-
input: (0, yaml_1.stringify)(result),
|
|
180
|
-
}];
|
|
181
177
|
if (result.errors) {
|
|
182
178
|
retryErrors.push(...result.errors);
|
|
183
|
-
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
outputHistory.push({
|
|
182
|
+
kind: activity_1.ActivityKind.Observation,
|
|
183
|
+
input: (0, yaml_1.stringify)(result),
|
|
184
|
+
});
|
|
184
185
|
}
|
|
185
186
|
// Continue to next iteration to check for more actions or generate new activities
|
|
186
187
|
continue;
|
|
187
188
|
}
|
|
188
189
|
catch (e) {
|
|
189
190
|
const err = e;
|
|
190
|
-
// Recreate output history with only the latest observation
|
|
191
|
-
outputHistory = [{
|
|
192
|
-
kind: activity_1.ActivityKind.Observation,
|
|
193
|
-
input: err.toString(),
|
|
194
|
-
}];
|
|
195
191
|
const message = `Retry ${i + 1} due to action error: ${err}`;
|
|
196
192
|
this.logger.debug(message);
|
|
197
193
|
retryErrors.push(err);
|
|
198
194
|
continue;
|
|
199
195
|
}
|
|
200
196
|
}
|
|
201
|
-
// Generate new activities if no action needs execution
|
|
202
|
-
let inputHistory = [...history, ...outputHistory];
|
|
203
197
|
// Apply transformers to input history before LLM inference
|
|
204
198
|
for (const transformer of this.inputTransformers) {
|
|
205
199
|
inputHistory = await transformer.transform(inputHistory);
|