@caretakerai/agent 0.0.34-beta.2 → 0.0.34-beta.3
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 +1 -1
- package/package.json +1 -1
- package/dist/activities/action.d.ts +0 -10
- package/dist/activities/action.js +0 -36
- package/dist/activities/activity.d.ts +0 -25
- package/dist/activities/activity.js +0 -35
- package/dist/activities/index.d.ts +0 -7
- package/dist/activities/index.js +0 -23
- package/dist/activities/instruction.d.ts +0 -12
- package/dist/activities/instruction.js +0 -25
- package/dist/activities/objective.d.ts +0 -12
- package/dist/activities/objective.js +0 -25
- package/dist/activities/observation.d.ts +0 -10
- package/dist/activities/observation.js +0 -36
- package/dist/activities/schema.d.ts +0 -12
- package/dist/activities/schema.js +0 -27
- package/dist/activities/thought.d.ts +0 -10
- package/dist/activities/thought.js +0 -27
- package/dist/agent.d.ts +0 -85
- package/dist/history/index.d.ts +0 -3
- package/dist/history/index.js +0 -19
- package/dist/history/input.d.ts +0 -17
- package/dist/history/input.js +0 -53
- package/dist/history/output.d.ts +0 -9
- package/dist/history/output.js +0 -26
- package/dist/history/transformer.d.ts +0 -4
- package/dist/history/transformer.js +0 -2
- package/dist/index.d.ts +0 -3
- package/dist/index.js +0 -19
package/dist/agent.js
CHANGED
|
@@ -148,7 +148,7 @@ class Agent {
|
|
|
148
148
|
}
|
|
149
149
|
newActivities.push(activity);
|
|
150
150
|
// Remove parsed activity from content
|
|
151
|
-
content = content.replace(transformer.stringify(activity), '');
|
|
151
|
+
content = content.replace(transformer.stringify(activity).content, '');
|
|
152
152
|
}
|
|
153
153
|
if (!newActivities.length) {
|
|
154
154
|
throw new AgentError('No new activities generated!');
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { MessageFieldWithRole, MessageType } from '@langchain/core/messages';
|
|
2
|
-
import type { StringWithAutocomplete } from '@langchain/core/utils/types';
|
|
3
|
-
import type { Activity, ActivityTransformer } from './activity';
|
|
4
|
-
import { ActivityKind } from './activity';
|
|
5
|
-
export declare class ActionTransformer implements ActivityTransformer {
|
|
6
|
-
readonly kind = ActivityKind.Action;
|
|
7
|
-
readonly role: StringWithAutocomplete<'user' | 'assistant' | MessageType>;
|
|
8
|
-
parse(text: string): Activity | null;
|
|
9
|
-
stringify({ input }: Activity): MessageFieldWithRole;
|
|
10
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ActionTransformer = void 0;
|
|
4
|
-
const activity_1 = require("./activity");
|
|
5
|
-
class ActionTransformer {
|
|
6
|
-
kind = activity_1.ActivityKind.Action;
|
|
7
|
-
role = 'assistant';
|
|
8
|
-
parse(text) {
|
|
9
|
-
const pattern = /<BEGIN\s+ACTION>(.*?)<END\s+ACTION>/is;
|
|
10
|
-
const match = text.match(pattern);
|
|
11
|
-
if (!match) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
const input = match[1].trim()
|
|
15
|
-
.replace(/^```graphql?\s*/i, '') // Remove opening ```graphql tag with optional whitespace
|
|
16
|
-
.replace(/\s*```\s*$/, '') // Remove closing ``` with optional whitespace
|
|
17
|
-
.trim();
|
|
18
|
-
return {
|
|
19
|
-
kind: this.kind,
|
|
20
|
-
input,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
stringify({ input }) {
|
|
24
|
-
return {
|
|
25
|
-
role: this.role,
|
|
26
|
-
content: `
|
|
27
|
-
<BEGIN ${this.kind}>
|
|
28
|
-
\`\`\`graphql
|
|
29
|
-
${input}
|
|
30
|
-
\`\`\`
|
|
31
|
-
<END ${this.kind}>
|
|
32
|
-
`.trim(),
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.ActionTransformer = ActionTransformer;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { StringWithAutocomplete } from '@langchain/core/dist/utils/types';
|
|
2
|
-
import { MessageFieldWithRole, MessageType } from '@langchain/core/messages';
|
|
3
|
-
export declare const ACTIVITY_SEP = "\n\n";
|
|
4
|
-
/**
|
|
5
|
-
* Enum representing the kinds of activities that an agent can perform.
|
|
6
|
-
*/
|
|
7
|
-
export declare enum ActivityKind {
|
|
8
|
-
/** An observation made by the agent. */
|
|
9
|
-
Observation = "OBSERVATION",
|
|
10
|
-
/** A thought process of the agent. */
|
|
11
|
-
Thought = "THOUGHT",
|
|
12
|
-
/** An action taken by the agent. */
|
|
13
|
-
Action = "ACTION"
|
|
14
|
-
}
|
|
15
|
-
export type Activity = {
|
|
16
|
-
kind: ActivityKind | string;
|
|
17
|
-
input: string;
|
|
18
|
-
};
|
|
19
|
-
export type ActivityTransformer = {
|
|
20
|
-
kind: string;
|
|
21
|
-
role: StringWithAutocomplete<'user' | 'assistant' | MessageType>;
|
|
22
|
-
parse(text: string): Activity | null;
|
|
23
|
-
stringify(activity: Activity): MessageFieldWithRole;
|
|
24
|
-
};
|
|
25
|
-
export declare function stringify(activities: Activity[], transformers: ActivityTransformer[]): MessageFieldWithRole[];
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringify = exports.ActivityKind = exports.ACTIVITY_SEP = void 0;
|
|
4
|
-
exports.ACTIVITY_SEP = '\n\n';
|
|
5
|
-
/**
|
|
6
|
-
* Enum representing the kinds of activities that an agent can perform.
|
|
7
|
-
*/
|
|
8
|
-
var ActivityKind;
|
|
9
|
-
(function (ActivityKind) {
|
|
10
|
-
/** An observation made by the agent. */
|
|
11
|
-
ActivityKind["Observation"] = "OBSERVATION";
|
|
12
|
-
/** A thought process of the agent. */
|
|
13
|
-
ActivityKind["Thought"] = "THOUGHT";
|
|
14
|
-
/** An action taken by the agent. */
|
|
15
|
-
ActivityKind["Action"] = "ACTION";
|
|
16
|
-
})(ActivityKind || (exports.ActivityKind = ActivityKind = {}));
|
|
17
|
-
function stringify(activities, transformers) {
|
|
18
|
-
return activities.reduce((messages, activity) => {
|
|
19
|
-
const transformer = transformers.find(({ kind }) => kind === activity.kind);
|
|
20
|
-
if (!transformer) {
|
|
21
|
-
throw new Error(`No transformer found for activity kind: ${activity.kind}`);
|
|
22
|
-
}
|
|
23
|
-
const message = transformer.stringify(activity);
|
|
24
|
-
const lastMessage = messages.at(-1);
|
|
25
|
-
// Combine with previous message if same role
|
|
26
|
-
if (lastMessage?.role === message.role) {
|
|
27
|
-
lastMessage.content = `${lastMessage.content}${exports.ACTIVITY_SEP}${message.content}`;
|
|
28
|
-
return messages;
|
|
29
|
-
}
|
|
30
|
-
// Otherwise add as new message
|
|
31
|
-
messages.push(message);
|
|
32
|
-
return messages;
|
|
33
|
-
}, []);
|
|
34
|
-
}
|
|
35
|
-
exports.stringify = stringify;
|
package/dist/activities/index.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./activity"), exports);
|
|
18
|
-
__exportStar(require("./observation"), exports);
|
|
19
|
-
__exportStar(require("./thought"), exports);
|
|
20
|
-
__exportStar(require("./action"), exports);
|
|
21
|
-
__exportStar(require("./objective"), exports);
|
|
22
|
-
__exportStar(require("./schema"), exports);
|
|
23
|
-
__exportStar(require("./instruction"), exports);
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { MessageFieldWithRole, MessageType } from '@langchain/core/messages';
|
|
2
|
-
import type { StringWithAutocomplete } from '@langchain/core/utils/types';
|
|
3
|
-
import type { Activity, ActivityTransformer } from './activity';
|
|
4
|
-
export declare class InstructionTransformer implements ActivityTransformer {
|
|
5
|
-
readonly kind = "INSTRUCTION";
|
|
6
|
-
readonly role: StringWithAutocomplete<'user' | 'assistant' | MessageType>;
|
|
7
|
-
parse(text: string): Activity | null;
|
|
8
|
-
stringify({ input }: Activity): MessageFieldWithRole;
|
|
9
|
-
}
|
|
10
|
-
export declare class OpenAIOSeriesInstructionTransformer extends InstructionTransformer {
|
|
11
|
-
role: StringWithAutocomplete<'user' | 'assistant' | MessageType>;
|
|
12
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenAIOSeriesInstructionTransformer = exports.InstructionTransformer = void 0;
|
|
4
|
-
class InstructionTransformer {
|
|
5
|
-
kind = 'INSTRUCTION';
|
|
6
|
-
role = 'system';
|
|
7
|
-
parse(text) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
stringify({ input }) {
|
|
11
|
-
return {
|
|
12
|
-
role: this.role,
|
|
13
|
-
content: `
|
|
14
|
-
<BEGIN ${this.kind}>
|
|
15
|
-
${input}
|
|
16
|
-
<END ${this.kind}>
|
|
17
|
-
`.trim(),
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.InstructionTransformer = InstructionTransformer;
|
|
22
|
-
class OpenAIOSeriesInstructionTransformer extends InstructionTransformer {
|
|
23
|
-
role = 'developer';
|
|
24
|
-
}
|
|
25
|
-
exports.OpenAIOSeriesInstructionTransformer = OpenAIOSeriesInstructionTransformer;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { MessageFieldWithRole, MessageType } from '@langchain/core/messages';
|
|
2
|
-
import type { StringWithAutocomplete } from '@langchain/core/utils/types';
|
|
3
|
-
import type { Activity, ActivityTransformer } from './activity';
|
|
4
|
-
export declare class ObjectiveTransformer implements ActivityTransformer {
|
|
5
|
-
readonly kind = "OBJECTIVE";
|
|
6
|
-
readonly role: StringWithAutocomplete<'user' | 'assistant' | MessageType>;
|
|
7
|
-
parse(text: string): Activity | null;
|
|
8
|
-
stringify({ input }: Activity): MessageFieldWithRole;
|
|
9
|
-
}
|
|
10
|
-
export declare class OpenAIOSeriesObjectiveTransformer extends ObjectiveTransformer {
|
|
11
|
-
role: StringWithAutocomplete<'user' | 'assistant' | MessageType>;
|
|
12
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenAIOSeriesObjectiveTransformer = exports.ObjectiveTransformer = void 0;
|
|
4
|
-
class ObjectiveTransformer {
|
|
5
|
-
kind = 'OBJECTIVE';
|
|
6
|
-
role = 'system';
|
|
7
|
-
parse(text) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
stringify({ input }) {
|
|
11
|
-
return {
|
|
12
|
-
role: this.role,
|
|
13
|
-
content: `
|
|
14
|
-
<BEGIN ${this.kind}>
|
|
15
|
-
${input}
|
|
16
|
-
<END ${this.kind}>
|
|
17
|
-
`.trim(),
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
exports.ObjectiveTransformer = ObjectiveTransformer;
|
|
22
|
-
class OpenAIOSeriesObjectiveTransformer extends ObjectiveTransformer {
|
|
23
|
-
role = 'developer';
|
|
24
|
-
}
|
|
25
|
-
exports.OpenAIOSeriesObjectiveTransformer = OpenAIOSeriesObjectiveTransformer;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { MessageFieldWithRole, MessageType } from '@langchain/core/messages';
|
|
2
|
-
import type { StringWithAutocomplete } from '@langchain/core/utils/types';
|
|
3
|
-
import type { Activity, ActivityTransformer } from './activity';
|
|
4
|
-
import { ActivityKind } from './activity';
|
|
5
|
-
export declare class ObservationTransformer implements ActivityTransformer {
|
|
6
|
-
readonly kind = ActivityKind.Observation;
|
|
7
|
-
readonly role: StringWithAutocomplete<'user' | 'assistant' | MessageType>;
|
|
8
|
-
parse(text: string): Activity | null;
|
|
9
|
-
stringify({ input }: Activity): MessageFieldWithRole;
|
|
10
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ObservationTransformer = void 0;
|
|
4
|
-
const activity_1 = require("./activity");
|
|
5
|
-
class ObservationTransformer {
|
|
6
|
-
kind = activity_1.ActivityKind.Observation;
|
|
7
|
-
role = 'user';
|
|
8
|
-
parse(text) {
|
|
9
|
-
const pattern = /<BEGIN\s+OBSERVATION>(.*?)<END\s+OBSERVATION>/is;
|
|
10
|
-
const match = text.match(pattern);
|
|
11
|
-
if (!match) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
const input = match[1].trim()
|
|
15
|
-
.replace(/^```yaml?\s*/i, '') // Remove opening ```yaml with optional whitespace
|
|
16
|
-
.replace(/\s*```\s*$/, '') // Remove closing ``` with optional whitespace
|
|
17
|
-
.trim();
|
|
18
|
-
return {
|
|
19
|
-
kind: this.kind,
|
|
20
|
-
input,
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
stringify({ input }) {
|
|
24
|
-
return {
|
|
25
|
-
role: this.role,
|
|
26
|
-
content: `
|
|
27
|
-
<BEGIN ${this.kind}>
|
|
28
|
-
\`\`\`yaml
|
|
29
|
-
${input}
|
|
30
|
-
\`\`\`
|
|
31
|
-
<END ${this.kind}>
|
|
32
|
-
`.trim(),
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
exports.ObservationTransformer = ObservationTransformer;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { MessageFieldWithRole, MessageType } from '@langchain/core/messages';
|
|
2
|
-
import type { StringWithAutocomplete } from '@langchain/core/utils/types';
|
|
3
|
-
import type { Activity, ActivityTransformer } from './activity';
|
|
4
|
-
export declare class SchemaTransformer implements ActivityTransformer {
|
|
5
|
-
readonly kind = "SCHEMA";
|
|
6
|
-
readonly role: StringWithAutocomplete<'user' | 'assistant' | MessageType>;
|
|
7
|
-
parse(text: string): Activity | null;
|
|
8
|
-
stringify({ input }: Activity): MessageFieldWithRole;
|
|
9
|
-
}
|
|
10
|
-
export declare class OpenAIOSeriesSchemaTransformer extends SchemaTransformer {
|
|
11
|
-
role: StringWithAutocomplete<'user' | 'assistant' | MessageType>;
|
|
12
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenAIOSeriesSchemaTransformer = exports.SchemaTransformer = void 0;
|
|
4
|
-
class SchemaTransformer {
|
|
5
|
-
kind = 'SCHEMA';
|
|
6
|
-
role = 'system';
|
|
7
|
-
parse(text) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
stringify({ input }) {
|
|
11
|
-
return {
|
|
12
|
-
role: this.role,
|
|
13
|
-
content: `
|
|
14
|
-
<BEGIN ${this.kind}>
|
|
15
|
-
\`\`\`graphql
|
|
16
|
-
${input}
|
|
17
|
-
\`\`\`
|
|
18
|
-
<END ${this.kind}>
|
|
19
|
-
`.trim(),
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
exports.SchemaTransformer = SchemaTransformer;
|
|
24
|
-
class OpenAIOSeriesSchemaTransformer extends SchemaTransformer {
|
|
25
|
-
role = 'developer';
|
|
26
|
-
}
|
|
27
|
-
exports.OpenAIOSeriesSchemaTransformer = OpenAIOSeriesSchemaTransformer;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { MessageFieldWithRole, MessageType } from '@langchain/core/messages';
|
|
2
|
-
import type { StringWithAutocomplete } from '@langchain/core/utils/types';
|
|
3
|
-
import type { Activity, ActivityTransformer } from './activity';
|
|
4
|
-
import { ActivityKind } from './activity';
|
|
5
|
-
export declare class ThoughtTransformer implements ActivityTransformer {
|
|
6
|
-
readonly kind = ActivityKind.Thought;
|
|
7
|
-
readonly role: StringWithAutocomplete<'user' | 'assistant' | MessageType>;
|
|
8
|
-
parse(text: string): Activity | null;
|
|
9
|
-
stringify({ input }: Activity): MessageFieldWithRole;
|
|
10
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ThoughtTransformer = void 0;
|
|
4
|
-
const activity_1 = require("./activity");
|
|
5
|
-
class ThoughtTransformer {
|
|
6
|
-
kind = activity_1.ActivityKind.Thought;
|
|
7
|
-
role = 'assistant';
|
|
8
|
-
parse(text) {
|
|
9
|
-
const pattern = /<BEGIN\s+THOUGHT>(.*?)<END\s+THOUGHT>/is;
|
|
10
|
-
const match = text.match(pattern);
|
|
11
|
-
if (!match) {
|
|
12
|
-
return null;
|
|
13
|
-
}
|
|
14
|
-
const input = match[1].trim();
|
|
15
|
-
return {
|
|
16
|
-
kind: this.kind,
|
|
17
|
-
input,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
stringify({ input }) {
|
|
21
|
-
return {
|
|
22
|
-
role: 'assistant',
|
|
23
|
-
content: `<BEGIN ${this.kind}>\n${input}\n<END ${this.kind}>`,
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.ThoughtTransformer = ThoughtTransformer;
|
package/dist/agent.d.ts
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { Logger } from 'pino';
|
|
2
|
-
import { PromptTemplate } from '@langchain/core/prompts';
|
|
3
|
-
import { BaseLanguageModel } from '@langchain/core/language_models/base';
|
|
4
|
-
import type { TypeSource, IResolvers } from '@graphql-tools/utils';
|
|
5
|
-
import { ExecutionResult, GraphQLSchema } from 'graphql';
|
|
6
|
-
import { HistoryTransformer } from './history/transformer';
|
|
7
|
-
import { Activity, ActivityTransformer } from './activities/activity';
|
|
8
|
-
type GraphQLExecutor = (query: string) => Promise<ExecutionResult>;
|
|
9
|
-
/**
|
|
10
|
-
* Parameters for initializing an Agent.
|
|
11
|
-
*/
|
|
12
|
-
interface AgentPrams {
|
|
13
|
-
/** The name of the agent. */
|
|
14
|
-
name?: string;
|
|
15
|
-
/** A description of the agent. */
|
|
16
|
-
description?: string;
|
|
17
|
-
/** The language model the agent will use. */
|
|
18
|
-
llm: BaseLanguageModel;
|
|
19
|
-
/** A GraphQL type definitions document. */
|
|
20
|
-
typeDefs: TypeSource;
|
|
21
|
-
/** A GraphQL resolvers. Will be ignored if custom executor is used. Optional. */
|
|
22
|
-
resolvers?: IResolvers;
|
|
23
|
-
/** The custom GraphQL executor to handle agent action. Optional. */
|
|
24
|
-
executor?: GraphQLExecutor;
|
|
25
|
-
/** The history of activities performed by the agent. Optional. */
|
|
26
|
-
history?: Activity[];
|
|
27
|
-
/** Examples of activities to guide the agent. Optional. */
|
|
28
|
-
examples?: Activity[];
|
|
29
|
-
/** The objective or goal the agent is trying to achieve. Optional. */
|
|
30
|
-
objective?: string;
|
|
31
|
-
/** Completion instruction for the LLM. Optional. */
|
|
32
|
-
instruction?: string;
|
|
33
|
-
/** The maximum number of iterations the agent can perform. Optional. */
|
|
34
|
-
maxIterations?: number;
|
|
35
|
-
/** The maximum number of retries for actions. Optional. */
|
|
36
|
-
maxRetries?: number;
|
|
37
|
-
/** The list of transformers that convert activities into LLM messages. */
|
|
38
|
-
transformers?: ActivityTransformer[];
|
|
39
|
-
/** The pipeline of history filter applied to activities before prompting LLM. */
|
|
40
|
-
inputTransformers?: HistoryTransformer[];
|
|
41
|
-
/** The pipeline of history filter applied to activities generated by the LLM. */
|
|
42
|
-
outputTransformers?: HistoryTransformer[];
|
|
43
|
-
/** The template for generating prompts for the agent. Optional. */
|
|
44
|
-
signal?: AbortSignal;
|
|
45
|
-
/** The template for generating prompts for the agent. Optional. */
|
|
46
|
-
template?: PromptTemplate;
|
|
47
|
-
/** A list of strings that, if generated by the agent, should cause it to stop. Optional. */
|
|
48
|
-
stop?: string[];
|
|
49
|
-
/** The logger the agent will use for outputting information. Optional. */
|
|
50
|
-
logger?: Logger;
|
|
51
|
-
}
|
|
52
|
-
export declare class AgentError extends Error {
|
|
53
|
-
constructor(message: string);
|
|
54
|
-
}
|
|
55
|
-
export declare class AgentRetryError extends AgentError {
|
|
56
|
-
errors: Error[];
|
|
57
|
-
constructor(message: string, errors: Error[]);
|
|
58
|
-
}
|
|
59
|
-
export declare class Agent implements AgentPrams {
|
|
60
|
-
name: string;
|
|
61
|
-
description: string;
|
|
62
|
-
llm: BaseLanguageModel;
|
|
63
|
-
typeDefs: TypeSource;
|
|
64
|
-
resolvers: IResolvers;
|
|
65
|
-
history: Activity[];
|
|
66
|
-
objective: string;
|
|
67
|
-
instruction: string;
|
|
68
|
-
maxIterations: number;
|
|
69
|
-
maxRetries: number;
|
|
70
|
-
signal: AbortSignal;
|
|
71
|
-
transformers: ActivityTransformer[];
|
|
72
|
-
inputTransformers: HistoryTransformer[];
|
|
73
|
-
outputTransformers: HistoryTransformer[];
|
|
74
|
-
logger: Logger;
|
|
75
|
-
executor?: GraphQLExecutor;
|
|
76
|
-
readonly schema: GraphQLSchema;
|
|
77
|
-
static defaults: Partial<AgentPrams>;
|
|
78
|
-
constructor(params: AgentPrams);
|
|
79
|
-
private addActivities;
|
|
80
|
-
cancel(reason?: any): void;
|
|
81
|
-
transform(history: Activity[]): Promise<Activity[]>;
|
|
82
|
-
transformAndExecute(): Promise<void>;
|
|
83
|
-
invoke(): Promise<void>;
|
|
84
|
-
}
|
|
85
|
-
export {};
|
package/dist/history/index.d.ts
DELETED
package/dist/history/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./transformer"), exports);
|
|
18
|
-
__exportStar(require("./input"), exports);
|
|
19
|
-
__exportStar(require("./output"), exports);
|
package/dist/history/input.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Activity } from '../activities/activity';
|
|
2
|
-
import { HistoryTransformer } from './transformer';
|
|
3
|
-
/**
|
|
4
|
-
* Transformer that validates the sequence of activities follows the pattern:
|
|
5
|
-
* Observation -> Thought -> Action -> Observation -> ...
|
|
6
|
-
*/
|
|
7
|
-
export declare class ValidateSequenceTransformer implements HistoryTransformer {
|
|
8
|
-
transform(activities: Activity[]): Promise<Activity[]>;
|
|
9
|
-
private static validateSequence;
|
|
10
|
-
}
|
|
11
|
-
/**
|
|
12
|
-
* Transformer that validates that Actions are always followed by Observations.
|
|
13
|
-
* Applicable for OpenAI O series models that prevents generating thoughts
|
|
14
|
-
*/
|
|
15
|
-
export declare class OpenAIOValidateSequenceTransformer implements HistoryTransformer {
|
|
16
|
-
transform(activities: Activity[]): Promise<Activity[]>;
|
|
17
|
-
}
|
package/dist/history/input.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OpenAIOValidateSequenceTransformer = exports.ValidateSequenceTransformer = void 0;
|
|
4
|
-
const activity_1 = require("../activities/activity");
|
|
5
|
-
/**
|
|
6
|
-
* Transformer that validates the sequence of activities follows the pattern:
|
|
7
|
-
* Observation -> Thought -> Action -> Observation -> ...
|
|
8
|
-
*/
|
|
9
|
-
class ValidateSequenceTransformer {
|
|
10
|
-
async transform(activities) {
|
|
11
|
-
// Skip validation if there are less than 2 activities
|
|
12
|
-
if (activities.length < 2) {
|
|
13
|
-
return activities;
|
|
14
|
-
}
|
|
15
|
-
ValidateSequenceTransformer.validateSequence(activities);
|
|
16
|
-
return activities;
|
|
17
|
-
}
|
|
18
|
-
static validateSequence(activities) {
|
|
19
|
-
activities.slice(0, -1).forEach((activity, index) => {
|
|
20
|
-
const next = activities[index + 1];
|
|
21
|
-
if (activity.kind === activity_1.ActivityKind.Observation && next.kind !== activity_1.ActivityKind.Thought) {
|
|
22
|
-
throw new Error(`Observation at index ${index} must be followed by Thought`);
|
|
23
|
-
}
|
|
24
|
-
if (activity.kind === activity_1.ActivityKind.Thought && next.kind !== activity_1.ActivityKind.Action) {
|
|
25
|
-
throw new Error(`Thought at index ${index} must be followed by Action`);
|
|
26
|
-
}
|
|
27
|
-
if (activity.kind === activity_1.ActivityKind.Action && next.kind !== activity_1.ActivityKind.Observation) {
|
|
28
|
-
throw new Error(`Action at index ${index} must be followed by Observation`);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
exports.ValidateSequenceTransformer = ValidateSequenceTransformer;
|
|
34
|
-
/**
|
|
35
|
-
* Transformer that validates that Actions are always followed by Observations.
|
|
36
|
-
* Applicable for OpenAI O series models that prevents generating thoughts
|
|
37
|
-
*/
|
|
38
|
-
class OpenAIOValidateSequenceTransformer {
|
|
39
|
-
async transform(activities) {
|
|
40
|
-
// Skip validation if there are less than 2 activities
|
|
41
|
-
if (activities.length < 2) {
|
|
42
|
-
return activities;
|
|
43
|
-
}
|
|
44
|
-
activities.slice(0, -1).forEach((activity, index) => {
|
|
45
|
-
const next = activities[index + 1];
|
|
46
|
-
if (activity.kind === activity_1.ActivityKind.Action && next.kind !== activity_1.ActivityKind.Observation) {
|
|
47
|
-
throw new Error(`Action at index ${index} must be followed by Observation`);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
return activities;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
exports.OpenAIOValidateSequenceTransformer = OpenAIOValidateSequenceTransformer;
|
package/dist/history/output.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Activity } from '../activities/activity';
|
|
2
|
-
import { HistoryTransformer } from './transformer';
|
|
3
|
-
/**
|
|
4
|
-
* Transformer that ensures there is at most one thought and one action,
|
|
5
|
-
* arranged in Thought -> Action order
|
|
6
|
-
*/
|
|
7
|
-
export declare class OrderedNewActivitiesTransformer implements HistoryTransformer {
|
|
8
|
-
transform(activities: Activity[]): Promise<Activity[]>;
|
|
9
|
-
}
|
package/dist/history/output.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.OrderedNewActivitiesTransformer = void 0;
|
|
4
|
-
const activity_1 = require("../activities/activity");
|
|
5
|
-
/**
|
|
6
|
-
* Transformer that ensures there is at most one thought and one action,
|
|
7
|
-
* arranged in Thought -> Action order
|
|
8
|
-
*/
|
|
9
|
-
class OrderedNewActivitiesTransformer {
|
|
10
|
-
async transform(activities) {
|
|
11
|
-
// Find the last thought and action
|
|
12
|
-
const lastThought = activities.find(a => a.kind === activity_1.ActivityKind.Thought);
|
|
13
|
-
const lastAction = activities.find(a => a.kind === activity_1.ActivityKind.Action);
|
|
14
|
-
const result = [];
|
|
15
|
-
// Add thought first if it exists
|
|
16
|
-
if (lastThought) {
|
|
17
|
-
result.push(lastThought);
|
|
18
|
-
}
|
|
19
|
-
// Add action second if it exists
|
|
20
|
-
if (lastAction) {
|
|
21
|
-
result.push(lastAction);
|
|
22
|
-
}
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
exports.OrderedNewActivitiesTransformer = OrderedNewActivitiesTransformer;
|
package/dist/index.d.ts
DELETED
package/dist/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./agent"), exports);
|
|
18
|
-
__exportStar(require("./activities"), exports);
|
|
19
|
-
__exportStar(require("./history"), exports);
|