beeai-framework 0.1.6 → 0.1.8
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/README.md +35 -29
- package/dist/adapters/amazon-bedrock/backend/chat.d.cts +1 -1
- package/dist/adapters/amazon-bedrock/backend/chat.d.ts +1 -1
- package/dist/adapters/amazon-bedrock/backend/embedding.d.cts +1 -1
- package/dist/adapters/amazon-bedrock/backend/embedding.d.ts +1 -1
- package/dist/adapters/anthropic/backend/chat.d.cts +1 -1
- package/dist/adapters/anthropic/backend/chat.d.ts +1 -1
- package/dist/adapters/anthropic/backend/embedding.d.cts +1 -1
- package/dist/adapters/anthropic/backend/embedding.d.ts +1 -1
- package/dist/adapters/azure-openai/backend/chat.d.cts +1 -1
- package/dist/adapters/azure-openai/backend/chat.d.ts +1 -1
- package/dist/adapters/azure-openai/backend/embedding.d.cts +1 -1
- package/dist/adapters/azure-openai/backend/embedding.d.ts +1 -1
- package/dist/adapters/dummy/backend/chat.d.cts +1 -1
- package/dist/adapters/dummy/backend/chat.d.ts +1 -1
- package/dist/adapters/dummy/backend/embedding.d.cts +1 -1
- package/dist/adapters/dummy/backend/embedding.d.ts +1 -1
- package/dist/adapters/google-vertex/backend/chat.d.cts +1 -1
- package/dist/adapters/google-vertex/backend/chat.d.ts +1 -1
- package/dist/adapters/google-vertex/backend/embedding.d.cts +1 -1
- package/dist/adapters/google-vertex/backend/embedding.d.ts +1 -1
- package/dist/adapters/groq/backend/chat.d.cts +1 -1
- package/dist/adapters/groq/backend/chat.d.ts +1 -1
- package/dist/adapters/groq/backend/embedding.d.cts +1 -1
- package/dist/adapters/groq/backend/embedding.d.ts +1 -1
- package/dist/adapters/langchain/backend/chat.d.cts +1 -1
- package/dist/adapters/langchain/backend/chat.d.ts +1 -1
- package/dist/adapters/langchain/backend/embedding.d.cts +1 -1
- package/dist/adapters/langchain/backend/embedding.d.ts +1 -1
- package/dist/adapters/langchain/tools.d.cts +1 -1
- package/dist/adapters/langchain/tools.d.ts +1 -1
- package/dist/adapters/ollama/backend/chat.d.cts +1 -1
- package/dist/adapters/ollama/backend/chat.d.ts +1 -1
- package/dist/adapters/ollama/backend/embedding.d.cts +1 -1
- package/dist/adapters/ollama/backend/embedding.d.ts +1 -1
- package/dist/adapters/openai/backend/chat.d.cts +1 -1
- package/dist/adapters/openai/backend/chat.d.ts +1 -1
- package/dist/adapters/openai/backend/client.cjs +9 -2
- package/dist/adapters/openai/backend/client.cjs.map +1 -1
- package/dist/adapters/openai/backend/client.js +9 -2
- package/dist/adapters/openai/backend/client.js.map +1 -1
- package/dist/adapters/openai/backend/embedding.d.cts +1 -1
- package/dist/adapters/openai/backend/embedding.d.ts +1 -1
- package/dist/adapters/vercel/backend/chat.cjs +0 -1
- package/dist/adapters/vercel/backend/chat.cjs.map +1 -1
- package/dist/adapters/vercel/backend/chat.d.cts +1 -1
- package/dist/adapters/vercel/backend/chat.d.ts +1 -1
- package/dist/adapters/vercel/backend/chat.js +0 -1
- package/dist/adapters/vercel/backend/chat.js.map +1 -1
- package/dist/adapters/vercel/backend/embedding.d.cts +1 -1
- package/dist/adapters/vercel/backend/embedding.d.ts +1 -1
- package/dist/adapters/watsonx/backend/chat.cjs +6 -2
- package/dist/adapters/watsonx/backend/chat.cjs.map +1 -1
- package/dist/adapters/watsonx/backend/chat.d.cts +2 -2
- package/dist/adapters/watsonx/backend/chat.d.ts +2 -2
- package/dist/adapters/watsonx/backend/chat.js +6 -2
- package/dist/adapters/watsonx/backend/chat.js.map +1 -1
- package/dist/adapters/watsonx/backend/embedding.d.cts +1 -1
- package/dist/adapters/watsonx/backend/embedding.d.ts +1 -1
- package/dist/agent-COg8SPbf.d.cts +84 -0
- package/dist/agent-Dv5YSk8H.d.ts +84 -0
- package/dist/agents/base.d.cts +2 -2
- package/dist/agents/base.d.ts +2 -2
- package/dist/agents/experimental/remote/agent.cjs +25 -18
- package/dist/agents/experimental/remote/agent.cjs.map +1 -1
- package/dist/agents/experimental/remote/agent.d.cts +6 -5
- package/dist/agents/experimental/remote/agent.d.ts +6 -5
- package/dist/agents/experimental/remote/agent.js +26 -19
- package/dist/agents/experimental/remote/agent.js.map +1 -1
- package/dist/agents/experimental/replan/agent.d.cts +2 -2
- package/dist/agents/experimental/replan/agent.d.ts +2 -2
- package/dist/agents/experimental/replan/prompts.d.cts +1 -1
- package/dist/agents/experimental/replan/prompts.d.ts +1 -1
- package/dist/agents/experimental/streamlit/agent.d.cts +2 -2
- package/dist/agents/experimental/streamlit/agent.d.ts +2 -2
- package/dist/agents/{bee → react}/agent.cjs +5 -5
- package/dist/agents/react/agent.cjs.map +1 -0
- package/dist/agents/{bee → react}/agent.d.cts +3 -3
- package/dist/agents/{bee → react}/agent.d.ts +3 -3
- package/dist/agents/{bee → react}/agent.js +5 -5
- package/dist/agents/react/agent.js.map +1 -0
- package/dist/agents/{bee → react}/prompts.cjs +18 -18
- package/dist/agents/react/prompts.cjs.map +1 -0
- package/dist/agents/{bee → react}/prompts.d.cts +10 -10
- package/dist/agents/{bee → react}/prompts.d.ts +10 -10
- package/dist/agents/{bee → react}/prompts.js +10 -10
- package/dist/agents/react/prompts.js.map +1 -0
- package/dist/agents/{bee → react}/runners/base.cjs +1 -1
- package/dist/agents/{bee → react}/runners/base.cjs.map +1 -1
- package/dist/agents/{bee → react}/runners/base.d.cts +3 -3
- package/dist/agents/{bee → react}/runners/base.d.ts +3 -3
- package/dist/agents/{bee → react}/runners/base.js +1 -1
- package/dist/agents/{bee → react}/runners/base.js.map +1 -1
- package/dist/agents/{bee → react}/runners/deep-think/prompts.cjs +14 -14
- package/dist/agents/react/runners/deep-think/prompts.cjs.map +1 -0
- package/dist/agents/{bee/runners/granite → react/runners/deep-think}/prompts.d.cts +8 -8
- package/dist/agents/{bee/runners/granite → react/runners/deep-think}/prompts.d.ts +8 -8
- package/dist/agents/{bee → react}/runners/deep-think/prompts.js +9 -9
- package/dist/agents/react/runners/deep-think/prompts.js.map +1 -0
- package/dist/agents/{bee → react}/runners/deep-think/runner.cjs +10 -10
- package/dist/agents/react/runners/deep-think/runner.cjs.map +1 -0
- package/dist/agents/{bee → react}/runners/deep-think/runner.d.cts +6 -6
- package/dist/agents/{bee → react}/runners/deep-think/runner.d.ts +6 -6
- package/dist/agents/{bee → react}/runners/deep-think/runner.js +12 -12
- package/dist/agents/react/runners/deep-think/runner.js.map +1 -0
- package/dist/agents/{bee → react}/runners/default/runner.cjs +10 -10
- package/dist/agents/react/runners/default/runner.cjs.map +1 -0
- package/dist/agents/{bee → react}/runners/default/runner.d.cts +9 -9
- package/dist/agents/{bee → react}/runners/default/runner.d.ts +9 -9
- package/dist/agents/{bee → react}/runners/default/runner.js +11 -11
- package/dist/agents/react/runners/default/runner.js.map +1 -0
- package/dist/agents/{bee → react}/runners/default/runner.spec.cjs +5 -5
- package/dist/agents/react/runners/default/runner.spec.cjs.map +1 -0
- package/dist/agents/{bee → react}/runners/default/runner.spec.js +6 -6
- package/dist/agents/react/runners/default/runner.spec.js.map +1 -0
- package/dist/agents/{bee → react}/runners/granite/prompts.cjs +14 -14
- package/dist/agents/react/runners/granite/prompts.cjs.map +1 -0
- package/dist/agents/{bee/runners/deep-think → react/runners/granite}/prompts.d.cts +8 -8
- package/dist/agents/{bee/runners/deep-think → react/runners/granite}/prompts.d.ts +8 -8
- package/dist/agents/{bee → react}/runners/granite/prompts.js +9 -9
- package/dist/agents/react/runners/granite/prompts.js.map +1 -0
- package/dist/agents/{bee → react}/runners/granite/runner.cjs +10 -10
- package/dist/agents/react/runners/granite/runner.cjs.map +1 -0
- package/dist/agents/{bee → react}/runners/granite/runner.d.cts +6 -6
- package/dist/agents/{bee → react}/runners/granite/runner.d.ts +6 -6
- package/dist/agents/{bee → react}/runners/granite/runner.js +12 -12
- package/dist/agents/react/runners/granite/runner.js.map +1 -0
- package/dist/agents/{bee → react}/types.d.cts +46 -46
- package/dist/agents/{bee → react}/types.d.ts +46 -46
- package/dist/agents/toolCalling/agent.cjs +208 -0
- package/dist/agents/toolCalling/agent.cjs.map +1 -0
- package/dist/agents/toolCalling/agent.d.cts +70 -0
- package/dist/agents/toolCalling/agent.d.ts +70 -0
- package/dist/agents/toolCalling/agent.js +206 -0
- package/dist/agents/toolCalling/agent.js.map +1 -0
- package/dist/agents/toolCalling/prompts.cjs +64 -0
- package/dist/agents/toolCalling/prompts.cjs.map +1 -0
- package/dist/agents/toolCalling/prompts.d.cts +49 -0
- package/dist/agents/toolCalling/prompts.d.ts +49 -0
- package/dist/agents/toolCalling/prompts.js +61 -0
- package/dist/agents/toolCalling/prompts.js.map +1 -0
- package/dist/agents/toolCalling/types.cjs +4 -0
- package/dist/agents/toolCalling/types.cjs.map +1 -0
- package/dist/agents/toolCalling/types.d.cts +66 -0
- package/dist/agents/toolCalling/types.d.ts +66 -0
- package/dist/agents/toolCalling/types.js +3 -0
- package/dist/agents/toolCalling/types.js.map +1 -0
- package/dist/agents/types.d.cts +2 -2
- package/dist/agents/types.d.ts +2 -2
- package/dist/backend/backend.d.cts +1 -1
- package/dist/backend/backend.d.ts +1 -1
- package/dist/backend/chat.cjs +3 -0
- package/dist/backend/chat.cjs.map +1 -1
- package/dist/backend/chat.d.cts +4 -3
- package/dist/backend/chat.d.ts +4 -3
- package/dist/backend/chat.js +3 -0
- package/dist/backend/chat.js.map +1 -1
- package/dist/backend/core.d.cts +1 -1
- package/dist/backend/core.d.ts +1 -1
- package/dist/backend/embedding.d.cts +1 -1
- package/dist/backend/embedding.d.ts +1 -1
- package/dist/backend/message.cjs +9 -0
- package/dist/backend/message.cjs.map +1 -1
- package/dist/backend/message.d.cts +2 -0
- package/dist/backend/message.d.ts +2 -0
- package/dist/backend/message.js +9 -0
- package/dist/backend/message.js.map +1 -1
- package/dist/{base-daM6fHUP.d.cts → base-Csr9guq2.d.cts} +1 -1
- package/dist/{base-mmG-8Pk9.d.ts → base-DHhpWHQm.d.ts} +1 -1
- package/dist/context.d.cts +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/emitter/emitter.d.cts +1 -1
- package/dist/emitter/emitter.d.ts +1 -1
- package/dist/emitter/types.d.cts +1 -1
- package/dist/emitter/types.d.ts +1 -1
- package/dist/index.cjs +21 -0
- package/dist/index.d.cts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +3 -0
- package/dist/instrumentation/create-telemetry-middleware.cjs.map +1 -1
- package/dist/instrumentation/create-telemetry-middleware.d.cts +1 -1
- package/dist/instrumentation/create-telemetry-middleware.d.ts +1 -1
- package/dist/instrumentation/create-telemetry-middleware.js.map +1 -1
- package/dist/instrumentation/helpers/utils.d.cts +1 -1
- package/dist/instrumentation/helpers/utils.d.ts +1 -1
- package/dist/internals/fetcher.d.cts +1 -1
- package/dist/internals/fetcher.d.ts +1 -1
- package/dist/memory/summarizeMemory.d.cts +1 -1
- package/dist/memory/summarizeMemory.d.ts +1 -1
- package/dist/parsers/linePrefix.d.cts +1 -1
- package/dist/parsers/linePrefix.d.ts +1 -1
- package/dist/tools/arxiv.d.cts +1 -1
- package/dist/tools/arxiv.d.ts +1 -1
- package/dist/tools/base.d.cts +1 -1
- package/dist/tools/base.d.ts +1 -1
- package/dist/tools/calculator.d.cts +1 -1
- package/dist/tools/calculator.d.ts +1 -1
- package/dist/tools/custom.d.cts +1 -1
- package/dist/tools/custom.d.ts +1 -1
- package/dist/tools/database/elasticsearch.d.cts +1 -1
- package/dist/tools/database/elasticsearch.d.ts +1 -1
- package/dist/tools/database/milvus.d.cts +3 -3
- package/dist/tools/database/milvus.d.ts +3 -3
- package/dist/tools/database/sql.d.cts +1 -1
- package/dist/tools/database/sql.d.ts +1 -1
- package/dist/tools/llm.d.cts +1 -1
- package/dist/tools/llm.d.ts +1 -1
- package/dist/tools/mcp.d.cts +1 -1
- package/dist/tools/mcp.d.ts +1 -1
- package/dist/tools/openapi.d.cts +1 -1
- package/dist/tools/openapi.d.ts +1 -1
- package/dist/tools/python/output.d.cts +1 -1
- package/dist/tools/python/output.d.ts +1 -1
- package/dist/tools/python/python.d.cts +1 -1
- package/dist/tools/python/python.d.ts +1 -1
- package/dist/tools/search/base.d.cts +1 -1
- package/dist/tools/search/base.d.ts +1 -1
- package/dist/tools/search/duckDuckGoSearch.d.cts +1 -1
- package/dist/tools/search/duckDuckGoSearch.d.ts +1 -1
- package/dist/tools/search/googleSearch.d.cts +1 -1
- package/dist/tools/search/googleSearch.d.ts +1 -1
- package/dist/tools/search/searXNGSearch.d.cts +1 -1
- package/dist/tools/search/searXNGSearch.d.ts +1 -1
- package/dist/tools/search/wikipedia.d.cts +1 -1
- package/dist/tools/search/wikipedia.d.ts +1 -1
- package/dist/tools/similarity.d.cts +1 -1
- package/dist/tools/similarity.d.ts +1 -1
- package/dist/tools/weather/openMeteo.d.cts +1 -1
- package/dist/tools/weather/openMeteo.d.ts +1 -1
- package/dist/tools/web/webCrawler.d.cts +1 -1
- package/dist/tools/web/webCrawler.d.ts +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.js +1 -1
- package/dist/workflows/agent.cjs +28 -20
- package/dist/workflows/agent.cjs.map +1 -1
- package/dist/workflows/agent.d.cts +223 -43
- package/dist/workflows/agent.d.ts +223 -43
- package/dist/workflows/agent.js +29 -21
- package/dist/workflows/agent.js.map +1 -1
- package/dist/workflows/workflow.d.cts +1 -1
- package/dist/workflows/workflow.d.ts +1 -1
- package/package.json +7 -7
- package/dist/agent-BZ-_ATuJ.d.cts +0 -84
- package/dist/agent-BqoZ6FbM.d.ts +0 -84
- package/dist/agents/bee/agent.cjs.map +0 -1
- package/dist/agents/bee/agent.js.map +0 -1
- package/dist/agents/bee/prompts.cjs.map +0 -1
- package/dist/agents/bee/prompts.js.map +0 -1
- package/dist/agents/bee/runners/deep-think/prompts.cjs.map +0 -1
- package/dist/agents/bee/runners/deep-think/prompts.js.map +0 -1
- package/dist/agents/bee/runners/deep-think/runner.cjs.map +0 -1
- package/dist/agents/bee/runners/deep-think/runner.js.map +0 -1
- package/dist/agents/bee/runners/default/runner.cjs.map +0 -1
- package/dist/agents/bee/runners/default/runner.js.map +0 -1
- package/dist/agents/bee/runners/default/runner.spec.cjs.map +0 -1
- package/dist/agents/bee/runners/default/runner.spec.js.map +0 -1
- package/dist/agents/bee/runners/granite/prompts.cjs.map +0 -1
- package/dist/agents/bee/runners/granite/prompts.js.map +0 -1
- package/dist/agents/bee/runners/granite/runner.cjs.map +0 -1
- package/dist/agents/bee/runners/granite/runner.js.map +0 -1
- package/dist/agents/{bee → react}/runners/default/runner.spec.d.cts +0 -0
- package/dist/agents/{bee → react}/runners/default/runner.spec.d.ts +0 -0
- package/dist/agents/{bee → react}/types.cjs +0 -0
- package/dist/agents/{bee → react}/types.cjs.map +0 -0
- package/dist/agents/{bee → react}/types.js +0 -0
- package/dist/agents/{bee → react}/types.js.map +0 -0
- package/dist/{emitter-C9EN5B0j.d.cts → emitter-BWtGHYn0.d.cts} +1 -1
- package/dist/{emitter-BxVxGBbJ.d.ts → emitter-l0W9gC1A.d.ts} +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PromptTemplate } from '../../../../template.cjs';
|
|
2
|
-
import { B as BaseRunner,
|
|
3
|
-
import {
|
|
2
|
+
import { B as BaseRunner, b as ReActAgentRunnerLLMInput, c as ReActAgentRunnerToolInput } from '../../../../agent-COg8SPbf.cjs';
|
|
3
|
+
import { ReActAgentRunIteration, ReActAgentRunInput, ReActAgentParserInput } from '../../types.cjs';
|
|
4
4
|
import { AnyTool } from '../../../../tools/base.cjs';
|
|
5
5
|
import { LinePrefixParser } from '../../../../parsers/linePrefix.cjs';
|
|
6
6
|
import { z } from 'zod';
|
|
@@ -12,9 +12,9 @@ import '../../../../internals/helpers/guards.cjs';
|
|
|
12
12
|
import '../../../../internals/serializable.cjs';
|
|
13
13
|
import 'ajv';
|
|
14
14
|
import '../../../../context.cjs';
|
|
15
|
-
import '../../../../emitter-
|
|
15
|
+
import '../../../../emitter-BWtGHYn0.cjs';
|
|
16
16
|
import '../../../../internals/helpers/promise.cjs';
|
|
17
|
-
import '../../../../base-
|
|
17
|
+
import '../../../../base-Csr9guq2.cjs';
|
|
18
18
|
import '../../../../backend/chat.cjs';
|
|
19
19
|
import 'ai';
|
|
20
20
|
import 'promise-based-task';
|
|
@@ -157,14 +157,14 @@ declare class DefaultRunner extends BaseRunner {
|
|
|
157
157
|
userEmpty: PromptTemplate<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
|
158
158
|
toolNoResultError: PromptTemplate<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
159
159
|
};
|
|
160
|
-
llm({ signal, meta, emitter }:
|
|
161
|
-
tool({ state, signal, meta, emitter }:
|
|
160
|
+
llm({ signal, meta, emitter }: ReActAgentRunnerLLMInput): Promise<ReActAgentRunIteration>;
|
|
161
|
+
tool({ state, signal, meta, emitter }: ReActAgentRunnerToolInput): Promise<{
|
|
162
162
|
success: boolean;
|
|
163
163
|
output: string;
|
|
164
164
|
}>;
|
|
165
165
|
protected get renderers(): {
|
|
166
166
|
user: {
|
|
167
|
-
message: ({ prompt }:
|
|
167
|
+
message: ({ prompt }: ReActAgentRunInput) => UserMessage | undefined;
|
|
168
168
|
};
|
|
169
169
|
system: {
|
|
170
170
|
variables: {
|
|
@@ -177,9 +177,9 @@ declare class DefaultRunner extends BaseRunner {
|
|
|
177
177
|
message: () => Promise<SystemMessage>;
|
|
178
178
|
};
|
|
179
179
|
};
|
|
180
|
-
protected initMemory({ prompt }:
|
|
180
|
+
protected initMemory({ prompt }: ReActAgentRunInput): Promise<BaseMemory>;
|
|
181
181
|
protected createParser(tools: AnyTool[]): {
|
|
182
|
-
readonly parser: LinePrefixParser<
|
|
182
|
+
readonly parser: LinePrefixParser<ReActAgentParserInput>;
|
|
183
183
|
};
|
|
184
184
|
}
|
|
185
185
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { PromptTemplate } from '../../../../template.js';
|
|
2
|
-
import { B as BaseRunner,
|
|
3
|
-
import {
|
|
2
|
+
import { B as BaseRunner, b as ReActAgentRunnerLLMInput, c as ReActAgentRunnerToolInput } from '../../../../agent-Dv5YSk8H.js';
|
|
3
|
+
import { ReActAgentRunIteration, ReActAgentRunInput, ReActAgentParserInput } from '../../types.js';
|
|
4
4
|
import { AnyTool } from '../../../../tools/base.js';
|
|
5
5
|
import { LinePrefixParser } from '../../../../parsers/linePrefix.js';
|
|
6
6
|
import { z } from 'zod';
|
|
@@ -12,9 +12,9 @@ import '../../../../internals/helpers/guards.js';
|
|
|
12
12
|
import '../../../../internals/serializable.js';
|
|
13
13
|
import 'ajv';
|
|
14
14
|
import '../../../../context.js';
|
|
15
|
-
import '../../../../emitter-
|
|
15
|
+
import '../../../../emitter-l0W9gC1A.js';
|
|
16
16
|
import '../../../../internals/helpers/promise.js';
|
|
17
|
-
import '../../../../base-
|
|
17
|
+
import '../../../../base-DHhpWHQm.js';
|
|
18
18
|
import '../../../../backend/chat.js';
|
|
19
19
|
import 'ai';
|
|
20
20
|
import 'promise-based-task';
|
|
@@ -157,14 +157,14 @@ declare class DefaultRunner extends BaseRunner {
|
|
|
157
157
|
userEmpty: PromptTemplate<z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>>;
|
|
158
158
|
toolNoResultError: PromptTemplate<z.ZodRecord<z.ZodString, z.ZodAny>>;
|
|
159
159
|
};
|
|
160
|
-
llm({ signal, meta, emitter }:
|
|
161
|
-
tool({ state, signal, meta, emitter }:
|
|
160
|
+
llm({ signal, meta, emitter }: ReActAgentRunnerLLMInput): Promise<ReActAgentRunIteration>;
|
|
161
|
+
tool({ state, signal, meta, emitter }: ReActAgentRunnerToolInput): Promise<{
|
|
162
162
|
success: boolean;
|
|
163
163
|
output: string;
|
|
164
164
|
}>;
|
|
165
165
|
protected get renderers(): {
|
|
166
166
|
user: {
|
|
167
|
-
message: ({ prompt }:
|
|
167
|
+
message: ({ prompt }: ReActAgentRunInput) => UserMessage | undefined;
|
|
168
168
|
};
|
|
169
169
|
system: {
|
|
170
170
|
variables: {
|
|
@@ -177,9 +177,9 @@ declare class DefaultRunner extends BaseRunner {
|
|
|
177
177
|
message: () => Promise<SystemMessage>;
|
|
178
178
|
};
|
|
179
179
|
};
|
|
180
|
-
protected initMemory({ prompt }:
|
|
180
|
+
protected initMemory({ prompt }: ReActAgentRunInput): Promise<BaseMemory>;
|
|
181
181
|
protected createParser(tools: AnyTool[]): {
|
|
182
|
-
readonly parser: LinePrefixParser<
|
|
182
|
+
readonly parser: LinePrefixParser<ReActAgentParserInput>;
|
|
183
183
|
};
|
|
184
184
|
}
|
|
185
185
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BaseRunner } from '../base.js';
|
|
2
2
|
import { Retryable } from '../../../../internals/helpers/retryable.js';
|
|
3
3
|
import { AgentError } from '../../../base.js';
|
|
4
|
-
import {
|
|
4
|
+
import { ReActAgentToolNoResultsPrompt, ReActAgentUserEmptyPrompt, ReActAgentToolInputErrorPrompt, ReActAgentToolErrorPrompt, ReActAgentToolNotFoundPrompt, ReActAgentSchemaErrorPrompt, ReActAgentUserPrompt, ReActAgentAssistantPrompt, ReActAgentSystemPrompt } from '../../prompts.js';
|
|
5
5
|
import { Tool, ToolInputValidationError, ToolError } from '../../../../tools/base.js';
|
|
6
6
|
import { FrameworkError } from '../../../../errors.js';
|
|
7
7
|
import { isTruthy, last } from 'remeda';
|
|
@@ -34,15 +34,15 @@ class DefaultRunner extends BaseRunner {
|
|
|
34
34
|
useNativeToolCalling = false;
|
|
35
35
|
get defaultTemplates() {
|
|
36
36
|
return {
|
|
37
|
-
system:
|
|
38
|
-
assistant:
|
|
39
|
-
user:
|
|
40
|
-
schemaError:
|
|
41
|
-
toolNotFoundError:
|
|
42
|
-
toolError:
|
|
43
|
-
toolInputError:
|
|
44
|
-
userEmpty:
|
|
45
|
-
toolNoResultError:
|
|
37
|
+
system: ReActAgentSystemPrompt,
|
|
38
|
+
assistant: ReActAgentAssistantPrompt,
|
|
39
|
+
user: ReActAgentUserPrompt,
|
|
40
|
+
schemaError: ReActAgentSchemaErrorPrompt,
|
|
41
|
+
toolNotFoundError: ReActAgentToolNotFoundPrompt,
|
|
42
|
+
toolError: ReActAgentToolErrorPrompt,
|
|
43
|
+
toolInputError: ReActAgentToolInputErrorPrompt,
|
|
44
|
+
userEmpty: ReActAgentUserEmptyPrompt,
|
|
45
|
+
toolNoResultError: ReActAgentToolNoResultsPrompt
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
static {
|
|
@@ -290,7 +290,7 @@ class DefaultRunner extends BaseRunner {
|
|
|
290
290
|
].filter(isTruthy).map((message) => {
|
|
291
291
|
if (message.role === Role.USER) {
|
|
292
292
|
const isEmpty = !message.text.trim();
|
|
293
|
-
const text = isEmpty ? (this.templates?.userEmpty ??
|
|
293
|
+
const text = isEmpty ? (this.templates?.userEmpty ?? ReActAgentUserEmptyPrompt).render({}) : (this.templates?.user ?? ReActAgentUserPrompt).render({
|
|
294
294
|
input: message.text,
|
|
295
295
|
meta: {
|
|
296
296
|
...message?.meta,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["runner.ts"],"names":["DefaultRunner","BaseRunner","useNativeToolCalling","defaultTemplates","system","ReActAgentSystemPrompt","assistant","ReActAgentAssistantPrompt","user","ReActAgentUserPrompt","schemaError","ReActAgentSchemaErrorPrompt","toolNotFoundError","ReActAgentToolNotFoundPrompt","toolError","ReActAgentToolErrorPrompt","toolInputError","ReActAgentToolInputErrorPrompt","userEmpty","ReActAgentUserEmptyPrompt","toolNoResultError","ReActAgentToolNoResultsPrompt","register","llm","signal","meta","emitter","tempMessageKey","Retryable","onRetry","emit","onError","error","failedAttemptsCounter","use","LinePrefixParserError","reason","Reason","NoDataReceived","memory","add","AssistantMessage","UserMessage","templates","render","executor","tools","input","slice","parser","createParser","raw","create","messages","undefined","abortSignal","stream","observe","llmEmitter","on","value","key","field","isDone","data","finalState","update","parsedValue","success","delta","callbacks","abort","getTextContent","partialState","tool_output","end","deleteMany","filter","msg","getProp","state","config","maxRetries","options","execution","maxRetriesPerStep","get","tool","find","name","trim","toUpperCase","tool_name","AgentError","context","output","iteration","tool_input","FrameworkError","ensure","toolOptions","shallowCopy","toolOutput","run","Tool","contextKeys","Memory","result","isEmpty","ToolInputValidationError","toString","ToolError","explain","renderers","self","message","prompt","variables","Promise","all","map","description","replaceAll","replace","concat","schema","JSON","stringify","getInputJsonSchema","ignoredKeys","Set","has","SystemMessage","instructions","createdAt","Date","toISOString","initMemory","history","prevConversation","isTruthy","role","Role","USER","text","TokenMemory","capacityThreshold","syncThreshold","handlers","removalSelector","curMessages","prevConversationMessage","includes","last","lastMessage","length","ASSISTANT","addMany","LinePrefixParser","thought","prefix","next","isStart","ZodParserField","z","string","min","pipeline","enum","isEnd","JSONParserField","object","passthrough","base","matchPair","final_answer","waitForStartNode","endOnRepeat","fallback","stash","enumerable"],"mappings":";;;;;;;;;;;;;;;;;;AAcC,SAAA,YAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GAAA,EAAA,IAAA,EAAA;;;;;;AAAA,MAAA,CAAA,YAAA,EAAA,cAAA,CAAA;;;;;AAsCM,MAAMA,sBAAsBC,UAAAA,CAAAA;EApDnC;;;EAqDYC,oBAAuB,GAAA,KAAA;AAEjC,EAAA,IACWC,gBAAmB,GAAA;AAC5B,IAAO,OAAA;MACLC,MAAQC,EAAAA,sBAAAA;MACRC,SAAWC,EAAAA,yBAAAA;MACXC,IAAMC,EAAAA,oBAAAA;MACNC,WAAaC,EAAAA,2BAAAA;MACbC,iBAAmBC,EAAAA,4BAAAA;MACnBC,SAAWC,EAAAA,yBAAAA;MACXC,cAAgBC,EAAAA,8BAAAA;MAChBC,SAAWC,EAAAA,yBAAAA;MACXC,iBAAmBC,EAAAA;AACrB,KAAA;AACF;EAEA;AACE,IAAA,IAAA,CAAKC,QAAQ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;QACZf,MAAQ,EAAA,eAAA;AACRC,QAAAA,IAAAA,EAAM,EAAA;QACNC,OAAS,EAAA,IAAA;QACTO,KAAO,EAAA,IAAA;AACP3G,QAAAA,KAAAA,EAAO,IAAIqG,cAAeC,CAAAA,CAAAA,CAAEC,QAASC,CAAAA,GAAAA,CAAI,CAAA,CAAA;AAC3C;KAEF,EAAA;MACEU,gBAAkB,EAAA,IAAA;MAClBC,WAAa,EAAA,IAAA;MACbC,QAAU,kBAAA,MAAA,CAAA,CAACC,UACTA,KACI,GAAA;AACE,QAAA;UAAEtH,GAAK,EAAA,SAAA;UAAWD,KAAO,EAAA;AAA+B,SAAA;AACxD,QAAA;UAAEC,GAAK,EAAA,cAAA;UAAgBD,KAAOuH,EAAAA;AAAM;AAEtC,OAAA,GAAA,EANI,EAAA,UAAA;KAOZ,CAAA;AAGF,IAAO,OAAA;AACLlI,MAAAA;AACF,KAAA;AACF;AACF;;;IAvXWmI,UAAY,EAAA;;;;;;;IA2NZA,UAAY,EAAA","file":"runner.js","sourcesContent":["/**\n * Copyright 2025 IBM Corp.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n BaseRunner,\n ReActAgentRunnerLLMInput,\n ReActAgentRunnerToolInput,\n} from \"@/agents/react/runners/base.js\";\nimport type {\n ReActAgentRunIteration,\n ReActAgentParserInput,\n ReActAgentRunInput,\n} from \"@/agents/react/types.js\";\nimport { Retryable } from \"@/internals/helpers/retryable.js\";\nimport { AgentError } from \"@/agents/base.js\";\nimport {\n ReActAgentAssistantPrompt,\n ReActAgentSchemaErrorPrompt,\n ReActAgentSystemPrompt,\n ReActAgentToolErrorPrompt,\n ReActAgentToolInputErrorPrompt,\n ReActAgentToolNoResultsPrompt,\n ReActAgentToolNotFoundPrompt,\n ReActAgentUserEmptyPrompt,\n ReActAgentUserPrompt,\n} from \"@/agents/react/prompts.js\";\nimport { AnyTool, Tool, ToolError, ToolInputValidationError, ToolOutput } from \"@/tools/base.js\";\nimport { FrameworkError } from \"@/errors.js\";\nimport { isTruthy, last } from \"remeda\";\nimport { LinePrefixParser, LinePrefixParserError } from \"@/parsers/linePrefix.js\";\nimport { JSONParserField, ZodParserField } from \"@/parsers/field.js\";\nimport { z } from \"zod\";\nimport { AssistantMessage, Role, SystemMessage, UserMessage } from \"@/backend/message.js\";\nimport { TokenMemory } from \"@/memory/tokenMemory.js\";\nimport { getProp } from \"@/internals/helpers/object.js\";\nimport { BaseMemory } from \"@/memory/base.js\";\nimport { Cache } from \"@/cache/decoratorCache.js\";\nimport { shallowCopy } from \"@/serializer/utils.js\";\n\nexport class DefaultRunner extends BaseRunner {\n protected useNativeToolCalling = false;\n\n @Cache({ enumerable: false })\n public get defaultTemplates() {\n return {\n system: ReActAgentSystemPrompt,\n assistant: ReActAgentAssistantPrompt,\n user: ReActAgentUserPrompt,\n schemaError: ReActAgentSchemaErrorPrompt,\n toolNotFoundError: ReActAgentToolNotFoundPrompt,\n toolError: ReActAgentToolErrorPrompt,\n toolInputError: ReActAgentToolInputErrorPrompt,\n userEmpty: ReActAgentUserEmptyPrompt,\n toolNoResultError: ReActAgentToolNoResultsPrompt,\n };\n }\n\n static {\n this.register();\n }\n\n async llm({ signal, meta, emitter }: ReActAgentRunnerLLMInput): Promise<ReActAgentRunIteration> {\n const tempMessageKey = \"tempMessage\" as const;\n\n return new Retryable({\n onRetry: () => emitter.emit(\"retry\", { meta }),\n onError: async (error) => {\n await emitter.emit(\"error\", { error, meta });\n this.failedAttemptsCounter.use(error);\n\n if (error instanceof LinePrefixParserError) {\n // Prevent hanging on EOT\n if (error.reason === LinePrefixParserError.Reason.NoDataReceived) {\n await this.memory.add(\n new AssistantMessage(\"\\n\", {\n [tempMessageKey]: true,\n }),\n );\n } else {\n await this.memory.add(\n new UserMessage(this.templates.schemaError.render({}), {\n [tempMessageKey]: true,\n }),\n );\n }\n }\n },\n executor: async () => {\n const tools = this.input.tools.slice();\n await emitter.emit(\"start\", { meta, tools, memory: this.memory });\n\n const { parser } = this.createParser(tools);\n const raw = await this.input.llm\n .create({\n messages: this.memory.messages.slice(),\n tools: this.useNativeToolCalling ? tools : undefined,\n abortSignal: signal,\n stream: this.input.stream !== false,\n })\n .observe((llmEmitter) => {\n parser.emitter.on(\"update\", async ({ value, key, field }) => {\n if (key === \"tool_output\" && parser.isDone) {\n return;\n }\n await emitter.emit(\"update\", {\n data: parser.finalState,\n update: { key, value: field.raw, parsedValue: value },\n meta: { success: true, ...meta },\n memory: this.memory,\n });\n });\n parser.emitter.on(\"partialUpdate\", async ({ key, delta, value }) => {\n await emitter.emit(\"partialUpdate\", {\n data: parser.finalState,\n update: { key, value: delta, parsedValue: value },\n meta: { success: true, ...meta },\n });\n });\n\n llmEmitter.on(\"newToken\", async ({ value, callbacks }) => {\n if (parser.isDone) {\n callbacks.abort();\n return;\n }\n\n await parser.add(value.getTextContent());\n if (parser.partialState.tool_output !== undefined) {\n callbacks.abort();\n }\n });\n });\n\n await parser.end();\n await this.memory.deleteMany(\n this.memory.messages.filter((msg) => getProp(msg.meta, [tempMessageKey]) === true),\n );\n\n return {\n state: parser.finalState,\n raw,\n };\n },\n config: {\n maxRetries: this.options.execution?.maxRetriesPerStep,\n signal,\n },\n }).get();\n }\n\n async tool({ state, signal, meta, emitter }: ReActAgentRunnerToolInput) {\n const tool = this.input.tools.find(\n (tool) => tool.name.trim().toUpperCase() == state.tool_name?.trim()?.toUpperCase(),\n );\n if (!tool) {\n this.failedAttemptsCounter.use(\n new AgentError(`Agent was trying to use non-existing tool \"${state.tool_name}\"`, [], {\n context: { state, meta },\n }),\n );\n\n return {\n success: false,\n output: this.templates.toolNotFoundError.render({\n tools: this.input.tools,\n }),\n };\n }\n\n return new Retryable({\n config: {\n signal,\n maxRetries: this.options.execution?.maxRetriesPerStep,\n },\n onError: async (error) => {\n await emitter.emit(\"toolError\", {\n data: {\n iteration: state,\n tool,\n input: state.tool_input,\n options: this.options,\n error: FrameworkError.ensure(error),\n },\n meta,\n });\n this.failedAttemptsCounter.use(error);\n },\n executor: async () => {\n const toolOptions = shallowCopy(this.options);\n\n try {\n await emitter.emit(\"toolStart\", {\n data: {\n tool,\n input: state.tool_input,\n options: toolOptions,\n iteration: state,\n },\n meta,\n });\n const toolOutput: ToolOutput = await tool.run(state.tool_input, toolOptions).context({\n [Tool.contextKeys.Memory]: this.memory,\n });\n await emitter.emit(\"toolSuccess\", {\n data: {\n tool,\n input: state.tool_input,\n options: toolOptions,\n result: toolOutput,\n iteration: state,\n },\n meta,\n });\n\n if (toolOutput.isEmpty()) {\n return { output: this.templates.toolNoResultError.render({}), success: true };\n }\n\n return {\n success: true,\n output: toolOutput.getTextContent(),\n };\n } catch (error) {\n await emitter.emit(\"toolError\", {\n data: {\n tool,\n input: state.tool_input,\n options: toolOptions,\n error,\n iteration: state,\n },\n meta,\n });\n\n if (error instanceof ToolInputValidationError) {\n this.failedAttemptsCounter.use(error);\n\n return {\n success: false,\n output: this.templates.toolInputError.render({\n reason: error.toString(),\n }),\n };\n }\n\n if (error instanceof ToolError) {\n this.failedAttemptsCounter.use(error);\n\n return {\n success: false,\n output: this.templates.toolError.render({\n reason: error.explain(),\n }),\n };\n }\n\n throw error;\n }\n },\n }).get();\n }\n\n @Cache({ enumerable: false })\n protected get renderers() {\n const self = {\n user: {\n message: ({ prompt }: ReActAgentRunInput) =>\n prompt !== null || this.input.memory.isEmpty()\n ? new UserMessage(prompt || this.templates.userEmpty.render({}))\n : undefined,\n },\n system: {\n variables: {\n tools: async () => {\n return await Promise.all(\n this.input.tools.map(async (tool) => ({\n name: tool.name,\n description: tool.description.replaceAll(\"\\n\", \".\").replace(/\\.$/, \"\").concat(\".\"),\n schema: JSON.stringify(\n await tool.getInputJsonSchema(),\n (() => {\n const ignoredKeys = new Set([\"minLength\", \"maxLength\", \"$schema\"]);\n return (key, value) => (ignoredKeys.has(key) ? undefined : value);\n })(),\n ),\n })),\n );\n },\n },\n message: async () =>\n new SystemMessage(\n this.templates.system.render({\n tools: await self.system.variables.tools(),\n instructions: undefined,\n createdAt: new Date().toISOString(),\n }),\n {\n createdAt: new Date(),\n },\n ),\n },\n };\n return self;\n }\n\n protected async initMemory({ prompt }: ReActAgentRunInput): Promise<BaseMemory> {\n const { memory: history } = this.input;\n\n const prevConversation = [...history.messages, this.renderers.user.message({ prompt })]\n .filter(isTruthy)\n .map((message) => {\n if (message.role === Role.USER) {\n const isEmpty = !message.text.trim();\n const text = isEmpty\n ? (this.templates?.userEmpty ?? ReActAgentUserEmptyPrompt).render({})\n : (this.templates?.user ?? ReActAgentUserPrompt).render({\n input: message.text,\n meta: {\n ...message?.meta,\n createdAt: message?.meta?.createdAt?.toISOString?.(),\n },\n });\n\n return new UserMessage(text, message.meta);\n }\n return message;\n });\n\n const memory = new TokenMemory({\n capacityThreshold: 0.85,\n syncThreshold: 0.5,\n handlers: {\n removalSelector(curMessages) {\n // First we remove messages from the past conversations\n const prevConversationMessage = curMessages.find((msg) => prevConversation.includes(msg));\n if (prevConversationMessage && prevConversationMessage !== last(prevConversation)) {\n return prevConversationMessage;\n }\n\n const lastMessage =\n curMessages.length > 3\n ? (curMessages.find(\n (msg) =>\n msg.role === Role.ASSISTANT && getProp(msg, [\"ctx\", \"success\"]) === false,\n ) ?? curMessages.find((msg) => msg.role === Role.ASSISTANT))\n : null;\n\n if (!lastMessage) {\n throw new AgentError(\"Cannot fit the current conversation into the context window!\");\n }\n return lastMessage;\n },\n },\n });\n await memory.addMany([await this.renderers.system.message(), ...prevConversation]);\n return memory;\n }\n\n protected createParser(tools: AnyTool[]) {\n const parser = new LinePrefixParser<ReActAgentParserInput>(\n {\n thought: {\n prefix: \"Thought:\",\n next: [\"tool_name\", \"final_answer\"],\n isStart: true,\n field: new ZodParserField(z.string().min(1)),\n },\n tool_name: {\n prefix: \"Function Name:\",\n next: [\"tool_input\"],\n field: new ZodParserField(\n z.pipeline(\n z.string().trim(),\n z.enum(tools.map((tool) => tool.name) as [string, ...string[]]),\n ),\n ),\n },\n tool_input: {\n prefix: \"Function Input:\",\n next: [\"tool_output\"],\n isEnd: true,\n field: new JSONParserField({\n schema: z.object({}).passthrough(),\n base: {},\n matchPair: [\"{\", \"}\"],\n }),\n },\n tool_output: {\n prefix: \"Function Output:\",\n next: [\"final_answer\"],\n isEnd: true,\n field: new ZodParserField(z.string()),\n },\n final_answer: {\n prefix: \"Final Answer:\",\n next: [],\n isStart: true,\n isEnd: true,\n field: new ZodParserField(z.string().min(1)),\n },\n },\n {\n waitForStartNode: true,\n endOnRepeat: true,\n fallback: (stash) =>\n stash\n ? [\n { key: \"thought\", value: \"I now know the final answer.\" },\n { key: \"final_answer\", value: stash },\n ]\n : [],\n },\n );\n\n return {\n parser,\n } as const;\n }\n}\n"]}
|
|
@@ -21,7 +21,7 @@ vi.mock("@/memory/tokenMemory.js", async () => {
|
|
|
21
21
|
};
|
|
22
22
|
});
|
|
23
23
|
vi.mock("@/context.js");
|
|
24
|
-
describe("
|
|
24
|
+
describe("ReAct Agent Runner", () => {
|
|
25
25
|
beforeEach(() => {
|
|
26
26
|
vi.useRealTimers();
|
|
27
27
|
});
|
|
@@ -59,22 +59,22 @@ describe("Bee Agent Runner", () => {
|
|
|
59
59
|
expect(instance.memory.messages).toEqual(instance2.memory.messages);
|
|
60
60
|
});
|
|
61
61
|
it.each([
|
|
62
|
-
prompts_cjs.
|
|
62
|
+
prompts_cjs.ReActAgentUserPrompt.fork((old) => ({
|
|
63
63
|
...old,
|
|
64
64
|
functions: {
|
|
65
65
|
...old.functions,
|
|
66
66
|
formatMeta: /* @__PURE__ */ __name(() => "", "formatMeta")
|
|
67
67
|
}
|
|
68
68
|
})),
|
|
69
|
-
prompts_cjs.
|
|
69
|
+
prompts_cjs.ReActAgentUserPrompt.fork((old) => ({
|
|
70
70
|
...old,
|
|
71
71
|
template: `{{input}}`
|
|
72
72
|
})),
|
|
73
|
-
prompts_cjs.
|
|
73
|
+
prompts_cjs.ReActAgentUserPrompt.fork((old) => ({
|
|
74
74
|
...old,
|
|
75
75
|
template: `User: {{input}}`
|
|
76
76
|
})),
|
|
77
|
-
prompts_cjs.
|
|
77
|
+
prompts_cjs.ReActAgentUserPrompt.fork((old) => ({
|
|
78
78
|
...old,
|
|
79
79
|
template: ``
|
|
80
80
|
}))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["runner.spec.ts"],"names":["vi","mock","UnconstrainedMemory","TokenMemory","describe","beforeEach","useRealTimers","it","useFakeTimers","setSystemTime","Date","createMemory","memory","addMany","UserMessage","AssistantMessage","createInstance","prompt","instance","DefaultRunner","llm","expect","any","Function","tools","templates","RunContext","init","memory2","add","createdAt","instance2","messages","toEqual","each","ReActAgentUserPrompt","fork","old","functions","formatMeta","template","user","a","b","zip","filter","msg","role","Role","USER","render","input","text","meta","undefined","toStrictEqual"],"mappings":";;;;;;;;;;;AAyBAA,EAAGC,CAAAA,IAAAA,CAAK,2BAA2B,YAAA;AACjC,EAAA,MAAM,EAAEC,mBAAAA,EAAAA,oBAAAA,EAAwB,GAAA,MAAM,OAAO,2CAAA,CAAA;AAC7C,EAAMC,IAAAA,WAAAA,GAAN,MAAMA,WAAAA,SAAoBD,oBAAAA,CAAAA;IA3B5B;;;AA2BiD,GAAA;AAC/C,EAAO,OAAA;AAAEC,IAAAA;AAAY,GAAA;AACvB,CAAA,CAAA;AAEAH,EAAAA,CAAGC,KAAK,cAAA,CAAA;AAERG,QAAAA,CAAS,sBAAsB,MAAA;AAC7BC,EAAAA,UAAAA,CAAW,MAAA;AACTL,IAAAA,EAAAA,CAAGM,aAAa,EAAA;GAClB,CAAA;AAEAC,EAAAA,EAAAA,CAAG,yCAAyC,YAAA;AAC1CP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QAAAA,GAAW,IAAIC,wBACnB,CAAA;MACEC,GAAKC,EAAAA,MAAAA,CAAOC,IAAIC,QAAAA,CAAAA;AAChBX,MAAAA,MAAAA;AACAY,MAAAA,KAAAA,EAAO,EAAA;MACPC,SAAW,EAAA;QACTgB,IAAMD,EAAAA;AACR;KAEF,EAAA,IACA,IAAId,sBAAAA,CAA4B,EAAW,EAAA,EAAC,CAAA,CAAA;AAE9C,IAAA,MAAMR,SAASS,IAAK,CAAA;AAAEV,MAAAA;KAAO,CAAA;AAE7B,IAAA,KAAA,MAAW,CAACyB,CAAAA,EAAGC,CAAAA,CAAAA,IAAMC,UACnB,CAAA;AAAIhC,MAAAA,GAAAA,MAAAA,CAAOoB,SAASa,MAAO,CAAA,CAACC,QAAQA,GAAIC,CAAAA,IAAAA,KAASC,iBAAKC,IAAI,CAAA;AAAG,MAAA,IAAInC,wBAAYG,MAAAA;OAC7EC,QAASN,CAAAA,MAAAA,CAAOoB,QAASa,CAAAA,MAAAA,CAAO,CAACC,GAAAA,KAAQA,IAAIC,IAASC,KAAAA,gBAAAA,CAAKC,IAAI,CAAA,CAC9D,EAAA;AACD5B,MAAAA,MAAAA,CAAOmB,SAASU,MAAO,CAAA;AAAEC,QAAAA,KAAAA,EAAOT,CAAEU,CAAAA,IAAAA;QAAMC,IAAMC,EAAAA;AAAU,OAAA,CAAA,CAAA,CAAIC,aAAcZ,CAAAA,CAAAA,CAAES,IAAI,CAAA;AAClF;GACF,CAAA;AACF,CAAA,CAAA","file":"runner.spec.cjs","sourcesContent":["/**\n * Copyright 2025 IBM Corp.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DefaultRunner } from \"@/agents/react/runners/default/runner.js\";\nimport { UnconstrainedMemory } from \"@/memory/unconstrainedMemory.js\";\nimport { AssistantMessage, Role, UserMessage } from \"@/backend/message.js\";\nimport { BaseMemory } from \"@/memory/base.js\";\nimport { ReActAgentUserPrompt } from \"@/agents/react/prompts.js\";\nimport { zip } from \"remeda\";\nimport { RunContext } from \"@/context.js\";\nimport { ReActAgent } from \"@/agents/react/agent.js\";\n\nvi.mock(\"@/memory/tokenMemory.js\", async () => {\n const { UnconstrainedMemory } = await import(\"@/memory/unconstrainedMemory.js\");\n class TokenMemory extends UnconstrainedMemory {}\n return { TokenMemory };\n});\n\nvi.mock(\"@/context.js\");\n\ndescribe(\"ReAct Agent Runner\", () => {\n beforeEach(() => {\n vi.useRealTimers();\n });\n\n it(\"Handles different prompt input source\", async () => {\n vi.useFakeTimers();\n vi.setSystemTime(new Date(\"2024-09-10T19:51:46.954Z\"));\n\n const createMemory = async () => {\n const memory = new UnconstrainedMemory();\n await memory.addMany([\n new UserMessage(\"What is your name?\"),\n new AssistantMessage(\"I am Bee\"),\n ]);\n return memory;\n };\n\n const createInstance = async (memory: BaseMemory, prompt: string | null) => {\n const instance = new DefaultRunner(\n {\n llm: expect.any(Function),\n memory,\n tools: [],\n templates: {},\n },\n {},\n new RunContext<ReActAgent, any>({} as any, {} as any),\n );\n await instance.init({ prompt });\n return instance;\n };\n\n const memory = await createMemory();\n const prompt = \"What can you do for me?\";\n const instance = await createInstance(memory, prompt);\n\n const memory2 = await createMemory();\n await memory2.add(new UserMessage(prompt, { createdAt: new Date() }));\n const instance2 = await createInstance(memory2, null);\n expect(instance.memory.messages).toEqual(instance2.memory.messages);\n });\n\n it.each([\n ReActAgentUserPrompt.fork((old) => ({\n ...old,\n functions: { ...old.functions, formatMeta: () => \"\" },\n })),\n ReActAgentUserPrompt.fork((old) => ({ ...old, template: `{{input}}` })),\n ReActAgentUserPrompt.fork((old) => ({ ...old, template: `User: {{input}}` })),\n ReActAgentUserPrompt.fork((old) => ({ ...old, template: `` })),\n ])(\"Correctly formats user input\", async (template: typeof ReActAgentUserPrompt) => {\n const memory = new UnconstrainedMemory();\n await memory.addMany([\n new UserMessage(\"What is your name?\"),\n new AssistantMessage(\"Bee\"),\n new UserMessage(\"Who are you?\"),\n new AssistantMessage(\"I am a helpful assistant.\"),\n ]);\n\n const prompt = \"What can you do for me?\";\n const instance = new DefaultRunner(\n {\n llm: expect.any(Function),\n memory,\n tools: [],\n templates: {\n user: template,\n },\n },\n {},\n new RunContext<ReActAgent, any>({} as any, {} as any),\n );\n await instance.init({ prompt });\n\n for (const [a, b] of zip(\n [...memory.messages.filter((msg) => msg.role === Role.USER), new UserMessage(prompt)],\n instance.memory.messages.filter((msg) => msg.role === Role.USER),\n )) {\n expect(template.render({ input: a.text, meta: undefined })).toStrictEqual(b.text);\n }\n });\n});\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DefaultRunner } from './runner.js';
|
|
2
2
|
import { UnconstrainedMemory } from '../../../../memory/unconstrainedMemory.js';
|
|
3
3
|
import { UserMessage, AssistantMessage, Role } from '../../../../backend/message.js';
|
|
4
|
-
import {
|
|
4
|
+
import { ReActAgentUserPrompt } from '../../prompts.js';
|
|
5
5
|
import { zip } from 'remeda';
|
|
6
6
|
import { RunContext } from '../../../../context.js';
|
|
7
7
|
|
|
@@ -19,7 +19,7 @@ vi.mock("@/memory/tokenMemory.js", async () => {
|
|
|
19
19
|
};
|
|
20
20
|
});
|
|
21
21
|
vi.mock("@/context.js");
|
|
22
|
-
describe("
|
|
22
|
+
describe("ReAct Agent Runner", () => {
|
|
23
23
|
beforeEach(() => {
|
|
24
24
|
vi.useRealTimers();
|
|
25
25
|
});
|
|
@@ -57,22 +57,22 @@ describe("Bee Agent Runner", () => {
|
|
|
57
57
|
expect(instance.memory.messages).toEqual(instance2.memory.messages);
|
|
58
58
|
});
|
|
59
59
|
it.each([
|
|
60
|
-
|
|
60
|
+
ReActAgentUserPrompt.fork((old) => ({
|
|
61
61
|
...old,
|
|
62
62
|
functions: {
|
|
63
63
|
...old.functions,
|
|
64
64
|
formatMeta: /* @__PURE__ */ __name(() => "", "formatMeta")
|
|
65
65
|
}
|
|
66
66
|
})),
|
|
67
|
-
|
|
67
|
+
ReActAgentUserPrompt.fork((old) => ({
|
|
68
68
|
...old,
|
|
69
69
|
template: `{{input}}`
|
|
70
70
|
})),
|
|
71
|
-
|
|
71
|
+
ReActAgentUserPrompt.fork((old) => ({
|
|
72
72
|
...old,
|
|
73
73
|
template: `User: {{input}}`
|
|
74
74
|
})),
|
|
75
|
-
|
|
75
|
+
ReActAgentUserPrompt.fork((old) => ({
|
|
76
76
|
...old,
|
|
77
77
|
template: ``
|
|
78
78
|
}))
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["runner.spec.ts"],"names":["vi","mock","UnconstrainedMemory","TokenMemory","describe","beforeEach","useRealTimers","it","useFakeTimers","setSystemTime","Date","createMemory","memory","addMany","UserMessage","AssistantMessage","createInstance","prompt","instance","DefaultRunner","llm","expect","any","Function","tools","templates","RunContext","init","memory2","add","createdAt","instance2","messages","toEqual","each","ReActAgentUserPrompt","fork","old","functions","formatMeta","template","user","a","b","zip","filter","msg","role","Role","USER","render","input","text","meta","undefined","toStrictEqual"],"mappings":";;;;;;;;;AAyBAA,EAAGC,CAAAA,IAAAA,CAAK,2BAA2B,YAAA;AACjC,EAAA,MAAM,EAAEC,mBAAAA,EAAAA,oBAAAA,EAAwB,GAAA,MAAM,OAAO,2CAAA,CAAA;AAC7C,EAAMC,IAAAA,WAAAA,GAAN,MAAMA,WAAAA,SAAoBD,oBAAAA,CAAAA;IA3B5B;;;AA2BiD,GAAA;AAC/C,EAAO,OAAA;AAAEC,IAAAA;AAAY,GAAA;AACvB,CAAA,CAAA;AAEAH,EAAAA,CAAGC,KAAK,cAAA,CAAA;AAERG,QAAAA,CAAS,sBAAsB,MAAA;AAC7BC,EAAAA,UAAAA,CAAW,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AA,IAAIC,iBAAiB,2BAAA;AACtB,KAAA,CAAA;AAED,IAAA,MAAME,MAAS,GAAA,yBAAA;AACf,IAAMC,MAAAA,QAAAA,GAAW,IAAIC,aACnB,CAAA;MACEC,GAAKC,EAAAA,MAAAA,CAAOC,IAAIC,QAAAA,CAAAA;AAChBX,MAAAA,MAAAA;AACAY,MAAAA,KAAAA,EAAO,EAAA;MACPC,SAAW,EAAA;QACTgB,IAAMD,EAAAA;AACR;KAEF,EAAA,IACA,IAAId,UAAAA,CAA4B,EAAW,EAAA,EAAC,CAAA,CAAA;AAE9C,IAAA,MAAMR,SAASS,IAAK,CAAA;AAAEV,MAAAA;KAAO,CAAA;AAE7B,IAAA,KAAA,MAAW,CAACyB,CAAAA,EAAGC,CAAAA,CAAAA,IAAMC,GACnB,CAAA;AAAIhC,MAAAA,GAAAA,MAAAA,CAAOoB,SAASa,MAAO,CAAA,CAACC,QAAQA,GAAIC,CAAAA,IAAAA,KAASC,KAAKC,IAAI,CAAA;AAAG,MAAA,IAAInC,YAAYG,MAAAA;OAC7EC,QAASN,CAAAA,MAAAA,CAAOoB,QAASa,CAAAA,MAAAA,CAAO,CAACC,GAAAA,KAAQA,IAAIC,IAASC,KAAAA,IAAAA,CAAKC,IAAI,CAAA,CAC9D,EAAA;AACD5B,MAAAA,MAAAA,CAAOmB,SAASU,MAAO,CAAA;AAAEC,QAAAA,KAAAA,EAAOT,CAAEU,CAAAA,IAAAA;QAAMC,IAAMC,EAAAA;AAAU,OAAA,CAAA,CAAA,CAAIC,aAAcZ,CAAAA,CAAAA,CAAES,IAAI,CAAA;AAClF;GACF,CAAA;AACF,CAAA,CAAA","file":"runner.spec.js","sourcesContent":["/**\n * Copyright 2025 IBM Corp.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { DefaultRunner } from \"@/agents/react/runners/default/runner.js\";\nimport { UnconstrainedMemory } from \"@/memory/unconstrainedMemory.js\";\nimport { AssistantMessage, Role, UserMessage } from \"@/backend/message.js\";\nimport { BaseMemory } from \"@/memory/base.js\";\nimport { ReActAgentUserPrompt } from \"@/agents/react/prompts.js\";\nimport { zip } from \"remeda\";\nimport { RunContext } from \"@/context.js\";\nimport { ReActAgent } from \"@/agents/react/agent.js\";\n\nvi.mock(\"@/memory/tokenMemory.js\", async () => {\n const { UnconstrainedMemory } = await import(\"@/memory/unconstrainedMemory.js\");\n class TokenMemory extends UnconstrainedMemory {}\n return { TokenMemory };\n});\n\nvi.mock(\"@/context.js\");\n\ndescribe(\"ReAct Agent Runner\", () => {\n beforeEach(() => {\n vi.useRealTimers();\n });\n\n it(\"Handles different prompt input source\", async () => {\n vi.useFakeTimers();\n vi.setSystemTime(new Date(\"2024-09-10T19:51:46.954Z\"));\n\n const createMemory = async () => {\n const memory = new UnconstrainedMemory();\n await memory.addMany([\n new UserMessage(\"What is your name?\"),\n new AssistantMessage(\"I am Bee\"),\n ]);\n return memory;\n };\n\n const createInstance = async (memory: BaseMemory, prompt: string | null) => {\n const instance = new DefaultRunner(\n {\n llm: expect.any(Function),\n memory,\n tools: [],\n templates: {},\n },\n {},\n new RunContext<ReActAgent, any>({} as any, {} as any),\n );\n await instance.init({ prompt });\n return instance;\n };\n\n const memory = await createMemory();\n const prompt = \"What can you do for me?\";\n const instance = await createInstance(memory, prompt);\n\n const memory2 = await createMemory();\n await memory2.add(new UserMessage(prompt, { createdAt: new Date() }));\n const instance2 = await createInstance(memory2, null);\n expect(instance.memory.messages).toEqual(instance2.memory.messages);\n });\n\n it.each([\n ReActAgentUserPrompt.fork((old) => ({\n ...old,\n functions: { ...old.functions, formatMeta: () => \"\" },\n })),\n ReActAgentUserPrompt.fork((old) => ({ ...old, template: `{{input}}` })),\n ReActAgentUserPrompt.fork((old) => ({ ...old, template: `User: {{input}}` })),\n ReActAgentUserPrompt.fork((old) => ({ ...old, template: `` })),\n ])(\"Correctly formats user input\", async (template: typeof ReActAgentUserPrompt) => {\n const memory = new UnconstrainedMemory();\n await memory.addMany([\n new UserMessage(\"What is your name?\"),\n new AssistantMessage(\"Bee\"),\n new UserMessage(\"Who are you?\"),\n new AssistantMessage(\"I am a helpful assistant.\"),\n ]);\n\n const prompt = \"What can you do for me?\";\n const instance = new DefaultRunner(\n {\n llm: expect.any(Function),\n memory,\n tools: [],\n templates: {\n user: template,\n },\n },\n {},\n new RunContext<ReActAgent, any>({} as any, {} as any),\n );\n await instance.init({ prompt });\n\n for (const [a, b] of zip(\n [...memory.messages.filter((msg) => msg.role === Role.USER), new UserMessage(prompt)],\n instance.memory.messages.filter((msg) => msg.role === Role.USER),\n )) {\n expect(template.render({ input: a.text, meta: undefined })).toStrictEqual(b.text);\n }\n });\n});\n"]}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
var prompts_cjs = require('../../prompts.cjs');
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const GraniteReActAgentAssistantPrompt = prompts_cjs.ReActAgentAssistantPrompt.fork((config) => {
|
|
6
6
|
config.template = `{{#thought}}Thought: {{.}}
|
|
7
7
|
{{/thought}}{{#toolName}}Tool Name: {{.}}
|
|
8
8
|
{{/toolName}}{{#toolInput}}Tool Input: {{.}}
|
|
9
9
|
{{/toolInput}}{{#finalAnswer}}Final Answer: {{.}}{{/finalAnswer}}`;
|
|
10
10
|
});
|
|
11
|
-
const
|
|
11
|
+
const GraniteReActAgentSystemPrompt = prompts_cjs.ReActAgentSystemPrompt.fork((config) => {
|
|
12
12
|
config.defaults.instructions = "";
|
|
13
13
|
config.functions.formatDate = function() {
|
|
14
14
|
const date = this.createdAt ? new Date(this.createdAt) : /* @__PURE__ */ new Date();
|
|
@@ -59,36 +59,36 @@ You do not need a tool to get the current Date and Time. Use the information ava
|
|
|
59
59
|
{{/instructions}}
|
|
60
60
|
`;
|
|
61
61
|
});
|
|
62
|
-
const
|
|
62
|
+
const GraniteReActAgentSchemaErrorPrompt = prompts_cjs.ReActAgentSchemaErrorPrompt.fork((config) => {
|
|
63
63
|
config.template = `Error: The generated response does not adhere to the communication structure mentioned in the system prompt.
|
|
64
64
|
You communicate only in instruction lines. Valid instruction lines are 'Thought' followed by 'Tool Name' and then 'Tool Input' or 'Thought' followed by 'Final Answer'.`;
|
|
65
65
|
});
|
|
66
|
-
const
|
|
66
|
+
const GraniteReActAgentUserPrompt = prompts_cjs.ReActAgentUserPrompt.fork((config) => {
|
|
67
67
|
config.template = `{{input}}`;
|
|
68
68
|
});
|
|
69
|
-
const
|
|
69
|
+
const GraniteReActAgentToolNotFoundPrompt = prompts_cjs.ReActAgentToolNotFoundPrompt.fork((config) => {
|
|
70
70
|
config.template = `Tool does not exist!
|
|
71
71
|
{{#tools.length}}
|
|
72
72
|
Use one of the following tools: {{#trim}}{{#tools}}{{name}},{{/tools}}{{/trim}}
|
|
73
73
|
{{/tools.length}}`;
|
|
74
74
|
});
|
|
75
|
-
const
|
|
75
|
+
const GraniteReActAgentToolErrorPrompt = prompts_cjs.ReActAgentToolErrorPrompt.fork((config) => {
|
|
76
76
|
config.template = `The tool has failed; the error log is shown below. If the tool cannot accomplish what you want, use a different tool or explain why you can't use it.
|
|
77
77
|
|
|
78
78
|
{{reason}}`;
|
|
79
79
|
});
|
|
80
|
-
const
|
|
80
|
+
const GraniteReActAgentToolInputErrorPrompt = prompts_cjs.ReActAgentToolInputErrorPrompt.fork((config) => {
|
|
81
81
|
config.template = `{{reason}}
|
|
82
82
|
|
|
83
83
|
HINT: If you're convinced that the input was correct but the tool cannot process it then use a different tool or say I don't know.`;
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
exports.
|
|
87
|
-
exports.
|
|
88
|
-
exports.
|
|
89
|
-
exports.
|
|
90
|
-
exports.
|
|
91
|
-
exports.
|
|
92
|
-
exports.
|
|
86
|
+
exports.GraniteReActAgentAssistantPrompt = GraniteReActAgentAssistantPrompt;
|
|
87
|
+
exports.GraniteReActAgentSchemaErrorPrompt = GraniteReActAgentSchemaErrorPrompt;
|
|
88
|
+
exports.GraniteReActAgentSystemPrompt = GraniteReActAgentSystemPrompt;
|
|
89
|
+
exports.GraniteReActAgentToolErrorPrompt = GraniteReActAgentToolErrorPrompt;
|
|
90
|
+
exports.GraniteReActAgentToolInputErrorPrompt = GraniteReActAgentToolInputErrorPrompt;
|
|
91
|
+
exports.GraniteReActAgentToolNotFoundPrompt = GraniteReActAgentToolNotFoundPrompt;
|
|
92
|
+
exports.GraniteReActAgentUserPrompt = GraniteReActAgentUserPrompt;
|
|
93
93
|
//# sourceMappingURL=prompts.cjs.map
|
|
94
94
|
//# sourceMappingURL=prompts.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["prompts.ts"],"names":["GraniteReActAgentAssistantPrompt","ReActAgentAssistantPrompt","fork","config","template","GraniteReActAgentSystemPrompt","ReActAgentSystemPrompt","defaults","instructions","functions","formatDate","date","createdAt","Date","Intl","DateTimeFormat","dateStyle","timeStyle","format","GraniteReActAgentSchemaErrorPrompt","ReActAgentSchemaErrorPrompt","GraniteReActAgentUserPrompt","ReActAgentUserPrompt","GraniteReActAgentToolNotFoundPrompt","ReActAgentToolNotFoundPrompt","GraniteReActAgentToolErrorPrompt","ReActAgentToolErrorPrompt","GraniteReActAgentToolInputErrorPrompt","ReActAgentToolInputErrorPrompt"],"mappings":";;;;AA0BO,MAAMA,gCAAmCC,GAAAA,qCAAAA,CAA0BC,IAAK,CAAA,CAACC,MAAAA,KAAAA;AAC9EA,EAAAA,MAAAA,CAAOC,QAAW,GAAA,CAAA;;;;AACpB,CAAA;AAEO,MAAMC,6BAAgCC,GAAAA,kCAAAA,CAAuBJ,IAAK,CAAA,CAACC,MAAAA,KAAAA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file":"prompts.cjs","sourcesContent":["/**\n * Copyright 2025 IBM Corp.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ReActAgentAssistantPrompt,\n ReActAgentSchemaErrorPrompt,\n ReActAgentSystemPrompt,\n ReActAgentToolErrorPrompt,\n ReActAgentToolInputErrorPrompt,\n ReActAgentToolNotFoundPrompt,\n ReActAgentUserPrompt,\n} from \"@/agents/react/prompts.js\";\n\nexport const GraniteReActAgentAssistantPrompt = ReActAgentAssistantPrompt.fork((config) => {\n config.template = `{{#thought}}Thought: {{.}}\\n{{/thought}}{{#toolName}}Tool Name: {{.}}\\n{{/toolName}}{{#toolInput}}Tool Input: {{.}}\\n{{/toolInput}}{{#finalAnswer}}Final Answer: {{.}}{{/finalAnswer}}`;\n});\n\nexport const GraniteReActAgentSystemPrompt = ReActAgentSystemPrompt.fork((config) => {\n config.defaults.instructions = \"\";\n config.functions.formatDate = function () {\n const date = this.createdAt ? new Date(this.createdAt) : new Date();\n return new Intl.DateTimeFormat(\"en-US\", {\n dateStyle: \"full\",\n timeStyle: \"medium\",\n }).format(date);\n };\n config.template = `You are an AI assistant.\nWhen the user sends a message figure out a solution and provide a final answer.\n{{#tools.length}}\nYou have access to a set of tools that can be used to retrieve information and perform actions.\nPay close attention to the tool description to determine if a tool is useful in a particular context.\n{{/tools.length}}\n\n# Communication structure\nYou communicate only in instruction lines. Valid instruction lines are 'Thought' followed by 'Tool Name' and then 'Tool Input', or 'Thought' followed by 'Final Answer'\n\nLine starting 'Thought: ' The assistant's response always starts with a thought, this is a single line where the assistant thinks about the user's message and describes in detail what it should do next.\n{{#tools.length}}\nIn a 'Thought: ', the assistant should determine if a Tool Call is necessary to get more information or perform an action, or if the available information is sufficient to provide the Final Answer.\nIf a tool needs to be called and is available, the assistant will produce a tool call:\nLine starting 'Tool Name: ' name of the tool that you want to use.\nLine starting 'Tool Input: ' JSON formatted tool arguments adhering to the selected tool parameters schema i.e. {\"arg1\":\"value1\", \"arg2\":\"value2\"}.\nAfter a 'Tool Input: ' the next message will contain a tool response. The next output should be a 'Thought: ' where the assistant thinks about the all the information it has available, and what it should do next (e.g. try the same tool with a different input, try a different tool, or proceed with answering the original user question).\n{{/tools.length}}\nOnce enough information is available to provide the Final Answer, the last line in the message needs to be:\nLine starting 'Final Answer: ' followed by a concise and clear answer to the original message.\n\n# Best practices\n- Use markdown syntax for formatting code snippets, links, JSON, tables, images, files.\n{{#tools.length}}\n- Do not attempt to use a tool that is not listed in available tools. This will cause an error.\n- Make sure that tool input is in the correct format and contains the correct arguments.\n{{/tools.length}}\n- When the message is unclear, respond with a line starting with 'Final Answer:' followed by a request for additional information needed to solve the problem.\n- When the user wants to chitchat instead, always respond politely.\n\n# Date and Time\nThe current date and time is: {{formatDate}}\n{{#tools.length}}\nYou do not need a tool to get the current Date and Time. Use the information available here.\n{{/tools.length}}\n\n{{#instructions}} \n# Additional instructions\n{{.}} \n{{/instructions}}\n`;\n});\n\nexport const GraniteReActAgentSchemaErrorPrompt = ReActAgentSchemaErrorPrompt.fork((config) => {\n config.template = `Error: The generated response does not adhere to the communication structure mentioned in the system prompt.\nYou communicate only in instruction lines. Valid instruction lines are 'Thought' followed by 'Tool Name' and then 'Tool Input' or 'Thought' followed by 'Final Answer'.`;\n});\n\nexport const GraniteReActAgentUserPrompt = ReActAgentUserPrompt.fork((config) => {\n config.template = `{{input}}`;\n});\n\nexport const GraniteReActAgentToolNotFoundPrompt = ReActAgentToolNotFoundPrompt.fork((config) => {\n config.template = `Tool does not exist!\n{{#tools.length}}\nUse one of the following tools: {{#trim}}{{#tools}}{{name}},{{/tools}}{{/trim}}\n{{/tools.length}}`;\n});\n\nexport const GraniteReActAgentToolErrorPrompt = ReActAgentToolErrorPrompt.fork((config) => {\n config.template = `The tool has failed; the error log is shown below. If the tool cannot accomplish what you want, use a different tool or explain why you can't use it.\n\n{{reason}}`;\n});\n\nexport const GraniteReActAgentToolInputErrorPrompt = ReActAgentToolInputErrorPrompt.fork(\n (config) => {\n config.template = `{{reason}}\n\nHINT: If you're convinced that the input was correct but the tool cannot process it then use a different tool or say I don't know.`;\n },\n);\n"]}
|
|
@@ -21,7 +21,7 @@ import 'ajv';
|
|
|
21
21
|
* See the License for the specific language governing permissions and
|
|
22
22
|
* limitations under the License.
|
|
23
23
|
*/
|
|
24
|
-
declare const
|
|
24
|
+
declare const GraniteReActAgentAssistantPrompt: PromptTemplate<zod.ZodObject<{
|
|
25
25
|
thought: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
26
26
|
toolName: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
27
27
|
toolInput: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
@@ -40,7 +40,7 @@ declare const DeepThinkBeeAssistantPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
40
40
|
toolOutput?: string[] | undefined;
|
|
41
41
|
finalAnswer?: string[] | undefined;
|
|
42
42
|
}>>;
|
|
43
|
-
declare const
|
|
43
|
+
declare const GraniteReActAgentSystemPrompt: PromptTemplate<zod.ZodObject<{
|
|
44
44
|
instructions: zod.ZodDefault<zod.ZodString>;
|
|
45
45
|
tools: zod.ZodArray<zod.ZodObject<{
|
|
46
46
|
name: zod.ZodString;
|
|
@@ -73,8 +73,8 @@ declare const DeepThinkBeeSystemPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
73
73
|
createdAt?: string | null | undefined;
|
|
74
74
|
instructions?: string | undefined;
|
|
75
75
|
}>>;
|
|
76
|
-
declare const
|
|
77
|
-
declare const
|
|
76
|
+
declare const GraniteReActAgentSchemaErrorPrompt: PromptTemplate<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
77
|
+
declare const GraniteReActAgentUserPrompt: PromptTemplate<zod.ZodObject<{
|
|
78
78
|
input: zod.ZodString;
|
|
79
79
|
meta: zod.ZodOptional<zod.ZodObject<{
|
|
80
80
|
createdAt: zod.ZodOptional<zod.ZodString>;
|
|
@@ -102,7 +102,7 @@ declare const DeepThinkBeeUserPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
102
102
|
createdAt: zod.ZodOptional<zod.ZodString>;
|
|
103
103
|
}, zod.ZodTypeAny, "passthrough">>>;
|
|
104
104
|
}, zod.ZodTypeAny, "passthrough">>>;
|
|
105
|
-
declare const
|
|
105
|
+
declare const GraniteReActAgentToolNotFoundPrompt: PromptTemplate<zod.ZodObject<{
|
|
106
106
|
tools: zod.ZodArray<zod.ZodObject<{
|
|
107
107
|
name: zod.ZodString;
|
|
108
108
|
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
@@ -127,14 +127,14 @@ declare const DeepThinkBeeToolNotFoundPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
127
127
|
name: zod.ZodString;
|
|
128
128
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
129
129
|
}, zod.ZodTypeAny, "passthrough">>>;
|
|
130
|
-
declare const
|
|
130
|
+
declare const GraniteReActAgentToolErrorPrompt: PromptTemplate<zod.ZodObject<{
|
|
131
131
|
reason: zod.ZodString;
|
|
132
132
|
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
133
133
|
reason: zod.ZodString;
|
|
134
134
|
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
135
135
|
reason: zod.ZodString;
|
|
136
136
|
}, zod.ZodTypeAny, "passthrough">>>;
|
|
137
|
-
declare const
|
|
137
|
+
declare const GraniteReActAgentToolInputErrorPrompt: PromptTemplate<zod.ZodObject<{
|
|
138
138
|
reason: zod.ZodString;
|
|
139
139
|
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
140
140
|
reason: zod.ZodString;
|
|
@@ -142,4 +142,4 @@ declare const DeepThinkBeeToolInputErrorPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
142
142
|
reason: zod.ZodString;
|
|
143
143
|
}, zod.ZodTypeAny, "passthrough">>>;
|
|
144
144
|
|
|
145
|
-
export {
|
|
145
|
+
export { GraniteReActAgentAssistantPrompt, GraniteReActAgentSchemaErrorPrompt, GraniteReActAgentSystemPrompt, GraniteReActAgentToolErrorPrompt, GraniteReActAgentToolInputErrorPrompt, GraniteReActAgentToolNotFoundPrompt, GraniteReActAgentUserPrompt };
|
|
@@ -21,7 +21,7 @@ import 'ajv';
|
|
|
21
21
|
* See the License for the specific language governing permissions and
|
|
22
22
|
* limitations under the License.
|
|
23
23
|
*/
|
|
24
|
-
declare const
|
|
24
|
+
declare const GraniteReActAgentAssistantPrompt: PromptTemplate<zod.ZodObject<{
|
|
25
25
|
thought: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
26
26
|
toolName: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
27
27
|
toolInput: zod.ZodOptional<zod.ZodArray<zod.ZodString, "many">>;
|
|
@@ -40,7 +40,7 @@ declare const DeepThinkBeeAssistantPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
40
40
|
toolOutput?: string[] | undefined;
|
|
41
41
|
finalAnswer?: string[] | undefined;
|
|
42
42
|
}>>;
|
|
43
|
-
declare const
|
|
43
|
+
declare const GraniteReActAgentSystemPrompt: PromptTemplate<zod.ZodObject<{
|
|
44
44
|
instructions: zod.ZodDefault<zod.ZodString>;
|
|
45
45
|
tools: zod.ZodArray<zod.ZodObject<{
|
|
46
46
|
name: zod.ZodString;
|
|
@@ -73,8 +73,8 @@ declare const DeepThinkBeeSystemPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
73
73
|
createdAt?: string | null | undefined;
|
|
74
74
|
instructions?: string | undefined;
|
|
75
75
|
}>>;
|
|
76
|
-
declare const
|
|
77
|
-
declare const
|
|
76
|
+
declare const GraniteReActAgentSchemaErrorPrompt: PromptTemplate<zod.ZodObject<{}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{}, zod.ZodTypeAny, "passthrough">>>;
|
|
77
|
+
declare const GraniteReActAgentUserPrompt: PromptTemplate<zod.ZodObject<{
|
|
78
78
|
input: zod.ZodString;
|
|
79
79
|
meta: zod.ZodOptional<zod.ZodObject<{
|
|
80
80
|
createdAt: zod.ZodOptional<zod.ZodString>;
|
|
@@ -102,7 +102,7 @@ declare const DeepThinkBeeUserPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
102
102
|
createdAt: zod.ZodOptional<zod.ZodString>;
|
|
103
103
|
}, zod.ZodTypeAny, "passthrough">>>;
|
|
104
104
|
}, zod.ZodTypeAny, "passthrough">>>;
|
|
105
|
-
declare const
|
|
105
|
+
declare const GraniteReActAgentToolNotFoundPrompt: PromptTemplate<zod.ZodObject<{
|
|
106
106
|
tools: zod.ZodArray<zod.ZodObject<{
|
|
107
107
|
name: zod.ZodString;
|
|
108
108
|
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
@@ -127,14 +127,14 @@ declare const DeepThinkBeeToolNotFoundPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
127
127
|
name: zod.ZodString;
|
|
128
128
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
129
129
|
}, zod.ZodTypeAny, "passthrough">>>;
|
|
130
|
-
declare const
|
|
130
|
+
declare const GraniteReActAgentToolErrorPrompt: PromptTemplate<zod.ZodObject<{
|
|
131
131
|
reason: zod.ZodString;
|
|
132
132
|
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
133
133
|
reason: zod.ZodString;
|
|
134
134
|
}, zod.ZodTypeAny, "passthrough">, zod.objectInputType<{
|
|
135
135
|
reason: zod.ZodString;
|
|
136
136
|
}, zod.ZodTypeAny, "passthrough">>>;
|
|
137
|
-
declare const
|
|
137
|
+
declare const GraniteReActAgentToolInputErrorPrompt: PromptTemplate<zod.ZodObject<{
|
|
138
138
|
reason: zod.ZodString;
|
|
139
139
|
}, "passthrough", zod.ZodTypeAny, zod.objectOutputType<{
|
|
140
140
|
reason: zod.ZodString;
|
|
@@ -142,4 +142,4 @@ declare const DeepThinkBeeToolInputErrorPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
142
142
|
reason: zod.ZodString;
|
|
143
143
|
}, zod.ZodTypeAny, "passthrough">>>;
|
|
144
144
|
|
|
145
|
-
export {
|
|
145
|
+
export { GraniteReActAgentAssistantPrompt, GraniteReActAgentSchemaErrorPrompt, GraniteReActAgentSystemPrompt, GraniteReActAgentToolErrorPrompt, GraniteReActAgentToolInputErrorPrompt, GraniteReActAgentToolNotFoundPrompt, GraniteReActAgentUserPrompt };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ReActAgentAssistantPrompt, ReActAgentSystemPrompt, ReActAgentSchemaErrorPrompt, ReActAgentUserPrompt, ReActAgentToolNotFoundPrompt, ReActAgentToolErrorPrompt, ReActAgentToolInputErrorPrompt } from '../../prompts.js';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const GraniteReActAgentAssistantPrompt = ReActAgentAssistantPrompt.fork((config) => {
|
|
4
4
|
config.template = `{{#thought}}Thought: {{.}}
|
|
5
5
|
{{/thought}}{{#toolName}}Tool Name: {{.}}
|
|
6
6
|
{{/toolName}}{{#toolInput}}Tool Input: {{.}}
|
|
7
7
|
{{/toolInput}}{{#finalAnswer}}Final Answer: {{.}}{{/finalAnswer}}`;
|
|
8
8
|
});
|
|
9
|
-
const
|
|
9
|
+
const GraniteReActAgentSystemPrompt = ReActAgentSystemPrompt.fork((config) => {
|
|
10
10
|
config.defaults.instructions = "";
|
|
11
11
|
config.functions.formatDate = function() {
|
|
12
12
|
const date = this.createdAt ? new Date(this.createdAt) : /* @__PURE__ */ new Date();
|
|
@@ -57,30 +57,30 @@ You do not need a tool to get the current Date and Time. Use the information ava
|
|
|
57
57
|
{{/instructions}}
|
|
58
58
|
`;
|
|
59
59
|
});
|
|
60
|
-
const
|
|
60
|
+
const GraniteReActAgentSchemaErrorPrompt = ReActAgentSchemaErrorPrompt.fork((config) => {
|
|
61
61
|
config.template = `Error: The generated response does not adhere to the communication structure mentioned in the system prompt.
|
|
62
62
|
You communicate only in instruction lines. Valid instruction lines are 'Thought' followed by 'Tool Name' and then 'Tool Input' or 'Thought' followed by 'Final Answer'.`;
|
|
63
63
|
});
|
|
64
|
-
const
|
|
64
|
+
const GraniteReActAgentUserPrompt = ReActAgentUserPrompt.fork((config) => {
|
|
65
65
|
config.template = `{{input}}`;
|
|
66
66
|
});
|
|
67
|
-
const
|
|
67
|
+
const GraniteReActAgentToolNotFoundPrompt = ReActAgentToolNotFoundPrompt.fork((config) => {
|
|
68
68
|
config.template = `Tool does not exist!
|
|
69
69
|
{{#tools.length}}
|
|
70
70
|
Use one of the following tools: {{#trim}}{{#tools}}{{name}},{{/tools}}{{/trim}}
|
|
71
71
|
{{/tools.length}}`;
|
|
72
72
|
});
|
|
73
|
-
const
|
|
73
|
+
const GraniteReActAgentToolErrorPrompt = ReActAgentToolErrorPrompt.fork((config) => {
|
|
74
74
|
config.template = `The tool has failed; the error log is shown below. If the tool cannot accomplish what you want, use a different tool or explain why you can't use it.
|
|
75
75
|
|
|
76
76
|
{{reason}}`;
|
|
77
77
|
});
|
|
78
|
-
const
|
|
78
|
+
const GraniteReActAgentToolInputErrorPrompt = ReActAgentToolInputErrorPrompt.fork((config) => {
|
|
79
79
|
config.template = `{{reason}}
|
|
80
80
|
|
|
81
81
|
HINT: If you're convinced that the input was correct but the tool cannot process it then use a different tool or say I don't know.`;
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
-
export {
|
|
84
|
+
export { GraniteReActAgentAssistantPrompt, GraniteReActAgentSchemaErrorPrompt, GraniteReActAgentSystemPrompt, GraniteReActAgentToolErrorPrompt, GraniteReActAgentToolInputErrorPrompt, GraniteReActAgentToolNotFoundPrompt, GraniteReActAgentUserPrompt };
|
|
85
85
|
//# sourceMappingURL=prompts.js.map
|
|
86
86
|
//# sourceMappingURL=prompts.js.map
|