@caretakerai/agent 0.0.37 → 0.0.38-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 +19 -19
  2. package/package.json +1 -1
package/dist/agent.js CHANGED
@@ -159,30 +159,25 @@ class Agent {
159
159
  let 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];
169
164
  // 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);
165
+ const latestActionIndex = history.findLastIndex(activity => activity.kind === activity_1.ActivityKind.Action);
166
+ const latestObservationIndex = history.findLastIndex(activity => activity.kind === activity_1.ActivityKind.Observation);
172
167
  // Execute action if latest action has later index than latest observation
173
168
  if (latestActionIndex > latestObservationIndex) {
174
169
  try {
175
170
  // Get action source
176
- const { input: source } = combinedHistory[latestActionIndex];
171
+ const { input: source } = history[latestActionIndex];
177
172
  // Prefer custom executor is specified
178
173
  const result = this.executor
179
174
  ? await this.executor(source)
180
175
  : 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
- });
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
+ }];
186
181
  if (result.errors) {
187
182
  retryErrors.push(...result.errors);
188
183
  continue;
@@ -192,10 +187,11 @@ class Agent {
192
187
  }
193
188
  catch (e) {
194
189
  const err = e;
195
- outputHistory.push({
196
- kind: activity_1.ActivityKind.Observation,
197
- input: err.toString(),
198
- });
190
+ // Recreate output history with only the latest observation
191
+ outputHistory = [{
192
+ kind: activity_1.ActivityKind.Observation,
193
+ input: err.toString(),
194
+ }];
199
195
  const message = `Retry ${i + 1} due to action error: ${err}`;
200
196
  this.logger.debug(message);
201
197
  retryErrors.push(err);
@@ -203,7 +199,11 @@ class Agent {
203
199
  }
204
200
  }
205
201
  // Generate new activities if no action needs execution
206
- const inputHistory = [...history, ...outputHistory];
202
+ let inputHistory = [...history, ...outputHistory];
203
+ // Apply transformers to input history before LLM inference
204
+ for (const transformer of this.inputTransformers) {
205
+ inputHistory = await transformer.transform(inputHistory);
206
+ }
207
207
  try {
208
208
  let newActivities = await this.transform(inputHistory);
209
209
  // 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.38-beta.0",
4
4
  "description": "Single framework for building text-agents",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",