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