beeai-framework 0.1.22 → 0.1.23
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/adapters/a2a/agents/agent.d.cts +2 -2
- package/dist/adapters/a2a/agents/agent.d.ts +2 -2
- package/dist/adapters/a2a/agents/events.d.cts +1 -1
- package/dist/adapters/a2a/agents/events.d.ts +1 -1
- package/dist/adapters/a2a/agents/types.d.cts +2 -2
- package/dist/adapters/a2a/agents/types.d.ts +2 -2
- package/dist/adapters/a2a/serve/agent_executor.d.cts +3 -3
- package/dist/adapters/a2a/serve/agent_executor.d.ts +3 -3
- package/dist/adapters/a2a/serve/server.d.cts +2 -2
- package/dist/adapters/a2a/serve/server.d.ts +2 -2
- package/dist/adapters/acp/agents/agent.d.cts +2 -2
- package/dist/adapters/acp/agents/agent.d.ts +2 -2
- package/dist/adapters/acp/agents/events.d.cts +1 -1
- package/dist/adapters/acp/agents/events.d.ts +1 -1
- package/dist/adapters/agentstack/agents/agent.d.cts +2 -2
- package/dist/adapters/agentstack/agents/agent.d.ts +2 -2
- package/dist/adapters/agentstack/agents/events.d.cts +1 -1
- package/dist/adapters/agentstack/agents/events.d.ts +1 -1
- package/dist/adapters/amazon-bedrock/backend/chat.d.cts +2 -2
- package/dist/adapters/amazon-bedrock/backend/chat.d.ts +2 -2
- package/dist/adapters/amazon-bedrock/backend/embedding.d.cts +2 -2
- package/dist/adapters/amazon-bedrock/backend/embedding.d.ts +2 -2
- package/dist/adapters/anthropic/backend/chat.d.cts +2 -2
- package/dist/adapters/anthropic/backend/chat.d.ts +2 -2
- package/dist/adapters/anthropic/backend/embedding.d.cts +2 -2
- package/dist/adapters/anthropic/backend/embedding.d.ts +2 -2
- package/dist/adapters/azure-openai/backend/chat.d.cts +2 -2
- package/dist/adapters/azure-openai/backend/chat.d.ts +2 -2
- package/dist/adapters/azure-openai/backend/embedding.d.cts +2 -2
- package/dist/adapters/azure-openai/backend/embedding.d.ts +2 -2
- package/dist/adapters/dummy/backend/chat.d.cts +2 -2
- package/dist/adapters/dummy/backend/chat.d.ts +2 -2
- package/dist/adapters/dummy/backend/embedding.d.cts +2 -2
- package/dist/adapters/dummy/backend/embedding.d.ts +2 -2
- package/dist/adapters/google-vertex/backend/chat.d.cts +2 -2
- package/dist/adapters/google-vertex/backend/chat.d.ts +2 -2
- package/dist/adapters/google-vertex/backend/embedding.d.cts +2 -2
- package/dist/adapters/google-vertex/backend/embedding.d.ts +2 -2
- package/dist/adapters/groq/backend/chat.d.cts +2 -2
- package/dist/adapters/groq/backend/chat.d.ts +2 -2
- package/dist/adapters/groq/backend/embedding.d.cts +2 -2
- package/dist/adapters/groq/backend/embedding.d.ts +2 -2
- package/dist/adapters/langchain/backend/chat.d.cts +2 -2
- package/dist/adapters/langchain/backend/chat.d.ts +2 -2
- package/dist/adapters/langchain/backend/embedding.d.cts +2 -2
- package/dist/adapters/langchain/backend/embedding.d.ts +2 -2
- package/dist/adapters/langchain/tools.d.cts +1 -1
- package/dist/adapters/langchain/tools.d.ts +1 -1
- package/dist/adapters/ollama/backend/chat.cjs +1 -2
- package/dist/adapters/ollama/backend/chat.cjs.map +1 -1
- package/dist/adapters/ollama/backend/chat.d.cts +2 -3
- package/dist/adapters/ollama/backend/chat.d.ts +2 -3
- package/dist/adapters/ollama/backend/chat.js +1 -2
- package/dist/adapters/ollama/backend/chat.js.map +1 -1
- package/dist/adapters/ollama/backend/embedding.d.cts +2 -2
- package/dist/adapters/ollama/backend/embedding.d.ts +2 -2
- package/dist/adapters/openai/backend/chat.d.cts +2 -2
- package/dist/adapters/openai/backend/chat.d.ts +2 -2
- package/dist/adapters/openai/backend/embedding.d.cts +2 -2
- package/dist/adapters/openai/backend/embedding.d.ts +2 -2
- package/dist/adapters/vercel/backend/chat.cjs +77 -17
- package/dist/adapters/vercel/backend/chat.cjs.map +1 -1
- package/dist/adapters/vercel/backend/chat.d.cts +2 -2
- package/dist/adapters/vercel/backend/chat.d.ts +2 -2
- package/dist/adapters/vercel/backend/chat.js +77 -17
- package/dist/adapters/vercel/backend/chat.js.map +1 -1
- package/dist/adapters/vercel/backend/embedding.d.cts +2 -2
- package/dist/adapters/vercel/backend/embedding.d.ts +2 -2
- package/dist/adapters/vercel/backend/utils.cjs +17 -0
- package/dist/adapters/vercel/backend/utils.cjs.map +1 -1
- package/dist/adapters/vercel/backend/utils.d.cts +5 -4
- package/dist/adapters/vercel/backend/utils.d.ts +5 -4
- package/dist/adapters/vercel/backend/utils.js +17 -1
- package/dist/adapters/vercel/backend/utils.js.map +1 -1
- package/dist/adapters/watsonx/backend/chat.cjs +7 -8
- package/dist/adapters/watsonx/backend/chat.cjs.map +1 -1
- package/dist/adapters/watsonx/backend/chat.d.cts +4 -4
- package/dist/adapters/watsonx/backend/chat.d.ts +4 -4
- package/dist/adapters/watsonx/backend/chat.js +7 -8
- package/dist/adapters/watsonx/backend/chat.js.map +1 -1
- package/dist/adapters/watsonx/backend/embedding.d.cts +2 -2
- package/dist/adapters/watsonx/backend/embedding.d.ts +2 -2
- package/dist/adapters/xai/backend/chat.d.cts +2 -2
- package/dist/adapters/xai/backend/chat.d.ts +2 -2
- package/dist/{agent-BMfyig7X.d.cts → agent-BVuc9Nfn.d.cts} +3 -3
- package/dist/{agent-Dxw8AGWb.d.ts → agent-Cuy8Q4gw.d.ts} +3 -3
- package/dist/agents/base.d.cts +2 -2
- package/dist/agents/base.d.ts +2 -2
- package/dist/agents/experimental/replan/agent.d.cts +3 -3
- package/dist/agents/experimental/replan/agent.d.ts +3 -3
- 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 +3 -3
- package/dist/agents/experimental/streamlit/agent.d.ts +3 -3
- package/dist/agents/react/agent.d.cts +4 -4
- package/dist/agents/react/agent.d.ts +4 -4
- package/dist/agents/react/prompts.d.cts +1 -1
- package/dist/agents/react/prompts.d.ts +1 -1
- package/dist/agents/react/runners/base.d.cts +4 -4
- package/dist/agents/react/runners/base.d.ts +4 -4
- package/dist/agents/react/runners/deep-think/prompts.d.cts +1 -1
- package/dist/agents/react/runners/deep-think/prompts.d.ts +1 -1
- package/dist/agents/react/runners/deep-think/runner.d.cts +5 -5
- package/dist/agents/react/runners/deep-think/runner.d.ts +5 -5
- package/dist/agents/react/runners/default/runner.d.cts +6 -6
- package/dist/agents/react/runners/default/runner.d.ts +6 -6
- package/dist/agents/react/runners/granite/prompts.d.cts +1 -1
- package/dist/agents/react/runners/granite/prompts.d.ts +1 -1
- package/dist/agents/react/runners/granite/runner.d.cts +5 -5
- package/dist/agents/react/runners/granite/runner.d.ts +5 -5
- package/dist/agents/react/types.d.cts +2 -2
- package/dist/agents/react/types.d.ts +2 -2
- package/dist/agents/requirement/agent.cjs +1 -1
- package/dist/agents/requirement/agent.cjs.map +1 -1
- package/dist/agents/requirement/agent.d.cts +4 -4
- package/dist/agents/requirement/agent.d.ts +4 -4
- package/dist/agents/requirement/agent.js +1 -1
- package/dist/agents/requirement/agent.js.map +1 -1
- package/dist/agents/requirement/prompts.d.cts +2 -2
- package/dist/agents/requirement/prompts.d.ts +2 -2
- package/dist/agents/requirement/requirements/conditional.d.cts +4 -4
- package/dist/agents/requirement/requirements/conditional.d.ts +4 -4
- package/dist/agents/requirement/requirements/requirement.d.cts +4 -4
- package/dist/agents/requirement/requirements/requirement.d.ts +4 -4
- package/dist/agents/requirement/requirements/utils.d.cts +1 -1
- package/dist/agents/requirement/requirements/utils.d.ts +1 -1
- package/dist/agents/requirement/runner.cjs +31 -15
- package/dist/agents/requirement/runner.cjs.map +1 -1
- package/dist/agents/requirement/runner.d.cts +13 -15
- package/dist/agents/requirement/runner.d.ts +13 -15
- package/dist/agents/requirement/runner.js +31 -15
- package/dist/agents/requirement/runner.js.map +1 -1
- package/dist/agents/requirement/types.d.cts +4 -4
- package/dist/agents/requirement/types.d.ts +4 -4
- package/dist/agents/requirement/utils/llm.d.cts +4 -4
- package/dist/agents/requirement/utils/llm.d.ts +4 -4
- package/dist/agents/requirement/utils/tool.cjs +2 -1
- package/dist/agents/requirement/utils/tool.cjs.map +1 -1
- package/dist/agents/requirement/utils/tool.d.cts +4 -4
- package/dist/agents/requirement/utils/tool.d.ts +4 -4
- package/dist/agents/requirement/utils/tool.js +2 -1
- package/dist/agents/requirement/utils/tool.js.map +1 -1
- package/dist/agents/toolCalling/agent.cjs +4 -1
- package/dist/agents/toolCalling/agent.cjs.map +1 -1
- package/dist/agents/toolCalling/agent.d.cts +6 -3
- package/dist/agents/toolCalling/agent.d.ts +6 -3
- package/dist/agents/toolCalling/agent.js +5 -2
- package/dist/agents/toolCalling/agent.js.map +1 -1
- package/dist/agents/toolCalling/types.d.cts +1 -1
- package/dist/agents/toolCalling/types.d.ts +1 -1
- package/dist/agents/types.d.cts +2 -2
- package/dist/agents/types.d.ts +2 -2
- package/dist/backend/backend.d.cts +2 -2
- package/dist/backend/backend.d.ts +2 -2
- package/dist/backend/chat.cjs +122 -4
- package/dist/backend/chat.cjs.map +1 -1
- package/dist/backend/chat.d.cts +3 -3
- package/dist/backend/chat.d.ts +3 -3
- package/dist/backend/chat.js +123 -5
- package/dist/backend/chat.js.map +1 -1
- package/dist/backend/core.d.cts +3 -3
- package/dist/backend/core.d.ts +3 -3
- package/dist/backend/embedding.d.cts +2 -2
- package/dist/backend/embedding.d.ts +2 -2
- package/dist/backend/message.cjs +20 -13
- package/dist/backend/message.cjs.map +1 -1
- package/dist/backend/message.d.cts +7 -3
- package/dist/backend/message.d.ts +7 -3
- package/dist/backend/message.js +20 -13
- package/dist/backend/message.js.map +1 -1
- package/dist/backend/utils.d.cts +2 -2
- package/dist/backend/utils.d.ts +2 -2
- package/dist/{base-BurRTBA7.d.ts → base-CyFx7BRL.d.ts} +2 -2
- package/dist/{base-v-PYIq5G.d.cts → base-XfWeXQ-S.d.cts} +2 -2
- package/dist/{chat-DB_cf15S.d.cts → chat-BOb9n7AJ.d.cts} +7 -8
- package/dist/{chat-BbCYMAdE.d.ts → chat-DrqwUgD8.d.ts} +7 -8
- package/dist/context.d.cts +1 -1
- package/dist/context.d.ts +1 -1
- package/dist/emitter/emitter.cjs +2 -1
- package/dist/emitter/emitter.cjs.map +1 -1
- package/dist/emitter/emitter.d.cts +1 -1
- package/dist/emitter/emitter.d.ts +1 -1
- package/dist/emitter/emitter.js +2 -1
- package/dist/emitter/emitter.js.map +1 -1
- package/dist/emitter/types.d.cts +1 -1
- package/dist/emitter/types.d.ts +1 -1
- package/dist/{emitter-CN7I4uSV.d.ts → emitter-36-9MnvA.d.ts} +2 -2
- package/dist/{emitter-CGKd_-kK.d.cts → emitter-jN55XZZq.d.cts} +2 -2
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/internals/fetcher.d.cts +1 -1
- package/dist/internals/fetcher.d.ts +1 -1
- package/dist/memory/summarizeMemory.d.cts +2 -2
- package/dist/memory/summarizeMemory.d.ts +2 -2
- package/dist/middleware/streamToolCall.cjs +132 -0
- package/dist/middleware/streamToolCall.cjs.map +1 -0
- package/dist/middleware/streamToolCall.d.cts +94 -0
- package/dist/middleware/streamToolCall.d.ts +94 -0
- package/dist/middleware/streamToolCall.js +130 -0
- package/dist/middleware/streamToolCall.js.map +1 -0
- package/dist/middleware/trajectory.cjs +14 -5
- package/dist/middleware/trajectory.cjs.map +1 -1
- package/dist/middleware/trajectory.d.cts +1 -1
- package/dist/middleware/trajectory.d.ts +1 -1
- package/dist/middleware/trajectory.js +13 -4
- package/dist/middleware/trajectory.js.map +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 +2 -2
- package/dist/tools/custom.d.ts +2 -2
- 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/qdrant.d.cts +1 -1
- package/dist/tools/database/qdrant.d.ts +1 -1
- package/dist/tools/database/sql.d.cts +1 -1
- package/dist/tools/database/sql.d.ts +1 -1
- package/dist/tools/handoff.cjs +68 -0
- package/dist/tools/handoff.cjs.map +1 -0
- package/dist/tools/handoff.d.cts +47 -0
- package/dist/tools/handoff.d.ts +47 -0
- package/dist/tools/handoff.js +66 -0
- package/dist/tools/handoff.js.map +1 -0
- package/dist/tools/llm.d.cts +2 -2
- package/dist/tools/llm.d.ts +2 -2
- 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 +2 -2
- package/dist/tools/python/python.d.ts +2 -2
- 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/think.d.cts +1 -1
- package/dist/tools/think.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/{types-BXkkbABd.d.ts → types-CJwiMH3u.d.ts} +11 -11
- package/dist/{types-Cx6f43du.d.cts → types-W0QttuP_.d.cts} +11 -11
- package/dist/version.cjs +1 -1
- package/dist/version.js +1 -1
- package/dist/workflows/agent.d.cts +3 -3
- package/dist/workflows/agent.d.ts +3 -3
- package/dist/workflows/workflow.d.cts +1 -1
- package/dist/workflows/workflow.d.ts +1 -1
- package/package.json +8 -8
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import '../../../parsers/linePrefix.cjs';
|
|
2
2
|
import '../types.cjs';
|
|
3
3
|
import '../../../internals/serializable.cjs';
|
|
4
|
-
export { B as BaseRunner, R as ReActAgentRunnerLLMInput, a as ReActAgentRunnerToolInput } from '../../../agent-
|
|
4
|
+
export { B as BaseRunner, R as ReActAgentRunnerLLMInput, a as ReActAgentRunnerToolInput } from '../../../agent-BVuc9Nfn.cjs';
|
|
5
5
|
import '../../../internals/helpers/counter.cjs';
|
|
6
6
|
import '../../../memory/base.cjs';
|
|
7
7
|
import '../../../context.cjs';
|
|
8
|
-
import '../../../emitter-
|
|
8
|
+
import '../../../emitter-jN55XZZq.cjs';
|
|
9
9
|
import 'node_modules/remeda/dist/ToString-DKW-jYvM.js';
|
|
10
10
|
import '../../../parsers/field.cjs';
|
|
11
11
|
import 'zod';
|
|
@@ -26,8 +26,8 @@ import 'zod-to-json-schema';
|
|
|
26
26
|
import '../../../internals/helpers/promise.cjs';
|
|
27
27
|
import '../prompts.cjs';
|
|
28
28
|
import '../../../template.cjs';
|
|
29
|
-
import '../../../chat-
|
|
29
|
+
import '../../../chat-BOb9n7AJ.cjs';
|
|
30
30
|
import '../../../backend/constants.cjs';
|
|
31
31
|
import '../../../logger/logger.cjs';
|
|
32
32
|
import 'pino';
|
|
33
|
-
import '../../../base-
|
|
33
|
+
import '../../../base-XfWeXQ-S.cjs';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import '../../../parsers/linePrefix.js';
|
|
2
2
|
import '../types.js';
|
|
3
3
|
import '../../../internals/serializable.js';
|
|
4
|
-
export { B as BaseRunner, R as ReActAgentRunnerLLMInput, a as ReActAgentRunnerToolInput } from '../../../agent-
|
|
4
|
+
export { B as BaseRunner, R as ReActAgentRunnerLLMInput, a as ReActAgentRunnerToolInput } from '../../../agent-Cuy8Q4gw.js';
|
|
5
5
|
import '../../../internals/helpers/counter.js';
|
|
6
6
|
import '../../../memory/base.js';
|
|
7
7
|
import '../../../context.js';
|
|
8
|
-
import '../../../emitter-
|
|
8
|
+
import '../../../emitter-36-9MnvA.js';
|
|
9
9
|
import 'node_modules/remeda/dist/ToString-DKW-jYvM.js';
|
|
10
10
|
import '../../../parsers/field.js';
|
|
11
11
|
import 'zod';
|
|
@@ -26,8 +26,8 @@ import 'zod-to-json-schema';
|
|
|
26
26
|
import '../../../internals/helpers/promise.js';
|
|
27
27
|
import '../prompts.js';
|
|
28
28
|
import '../../../template.js';
|
|
29
|
-
import '../../../chat-
|
|
29
|
+
import '../../../chat-DrqwUgD8.js';
|
|
30
30
|
import '../../../backend/constants.js';
|
|
31
31
|
import '../../../logger/logger.js';
|
|
32
32
|
import 'pino';
|
|
33
|
-
import '../../../base-
|
|
33
|
+
import '../../../base-CyFx7BRL.js';
|
|
@@ -46,12 +46,12 @@ declare const DeepThinkReActAgentSystemPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
46
46
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
47
47
|
createdAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
48
48
|
}, "strip", zod.ZodTypeAny, {
|
|
49
|
+
instructions: string;
|
|
49
50
|
tools: zod.objectOutputType<{
|
|
50
51
|
name: zod.ZodString;
|
|
51
52
|
description: zod.ZodString;
|
|
52
53
|
schema: zod.ZodString;
|
|
53
54
|
}, zod.ZodTypeAny, "passthrough">[];
|
|
54
|
-
instructions: string;
|
|
55
55
|
createdAt?: string | null | undefined;
|
|
56
56
|
}, {
|
|
57
57
|
tools: zod.objectInputType<{
|
|
@@ -46,12 +46,12 @@ declare const DeepThinkReActAgentSystemPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
46
46
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
47
47
|
createdAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
48
48
|
}, "strip", zod.ZodTypeAny, {
|
|
49
|
+
instructions: string;
|
|
49
50
|
tools: zod.objectOutputType<{
|
|
50
51
|
name: zod.ZodString;
|
|
51
52
|
description: zod.ZodString;
|
|
52
53
|
schema: zod.ZodString;
|
|
53
54
|
}, zod.ZodTypeAny, "passthrough">[];
|
|
54
|
-
instructions: string;
|
|
55
55
|
createdAt?: string | null | undefined;
|
|
56
56
|
}, {
|
|
57
57
|
tools: zod.objectInputType<{
|
|
@@ -4,10 +4,10 @@ import { PromptTemplate } from '../../../../template.cjs';
|
|
|
4
4
|
import { AnyTool } from '../../../../tools/base.cjs';
|
|
5
5
|
import { DefaultRunner } from '../default/runner.cjs';
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
-
import { b as ReActAgentInput, c as ReActAgent } from '../../../../agent-
|
|
7
|
+
import { b as ReActAgentInput, c as ReActAgent } from '../../../../agent-BVuc9Nfn.cjs';
|
|
8
8
|
import { GetRunContext } from '../../../../context.cjs';
|
|
9
9
|
import 'node_modules/remeda/dist/ToString-DKW-jYvM.js';
|
|
10
|
-
import '../../../../emitter-
|
|
10
|
+
import '../../../../emitter-jN55XZZq.cjs';
|
|
11
11
|
import '../../../../internals/types.cjs';
|
|
12
12
|
import '../../../../internals/helpers/guards.cjs';
|
|
13
13
|
import '../../../../internals/serializable.cjs';
|
|
@@ -21,7 +21,7 @@ import '../../../../backend/message.cjs';
|
|
|
21
21
|
import 'ai';
|
|
22
22
|
import '../../prompts.cjs';
|
|
23
23
|
import 'ajv';
|
|
24
|
-
import '../../../../chat-
|
|
24
|
+
import '../../../../chat-BOb9n7AJ.cjs';
|
|
25
25
|
import 'promise-based-task';
|
|
26
26
|
import '../../../../cache/base.cjs';
|
|
27
27
|
import '../../../../backend/constants.cjs';
|
|
@@ -30,7 +30,7 @@ import 'pino';
|
|
|
30
30
|
import '../../../../internals/helpers/promise.cjs';
|
|
31
31
|
import '../../../../internals/helpers/schema.cjs';
|
|
32
32
|
import 'zod-to-json-schema';
|
|
33
|
-
import '../../../../base-
|
|
33
|
+
import '../../../../base-XfWeXQ-S.cjs';
|
|
34
34
|
import '../../../../internals/helpers/counter.cjs';
|
|
35
35
|
|
|
36
36
|
declare class DeepThinkRunner extends DefaultRunner {
|
|
@@ -52,12 +52,12 @@ declare class DeepThinkRunner extends DefaultRunner {
|
|
|
52
52
|
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
53
53
|
createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
54
54
|
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
instructions: string;
|
|
55
56
|
tools: z.objectOutputType<{
|
|
56
57
|
name: z.ZodString;
|
|
57
58
|
description: z.ZodString;
|
|
58
59
|
schema: z.ZodString;
|
|
59
60
|
}, z.ZodTypeAny, "passthrough">[];
|
|
60
|
-
instructions: string;
|
|
61
61
|
createdAt?: string | null | undefined;
|
|
62
62
|
}, {
|
|
63
63
|
tools: z.objectInputType<{
|
|
@@ -4,10 +4,10 @@ import { PromptTemplate } from '../../../../template.js';
|
|
|
4
4
|
import { AnyTool } from '../../../../tools/base.js';
|
|
5
5
|
import { DefaultRunner } from '../default/runner.js';
|
|
6
6
|
import { z } from 'zod';
|
|
7
|
-
import { b as ReActAgentInput, c as ReActAgent } from '../../../../agent-
|
|
7
|
+
import { b as ReActAgentInput, c as ReActAgent } from '../../../../agent-Cuy8Q4gw.js';
|
|
8
8
|
import { GetRunContext } from '../../../../context.js';
|
|
9
9
|
import 'node_modules/remeda/dist/ToString-DKW-jYvM.js';
|
|
10
|
-
import '../../../../emitter-
|
|
10
|
+
import '../../../../emitter-36-9MnvA.js';
|
|
11
11
|
import '../../../../internals/types.js';
|
|
12
12
|
import '../../../../internals/helpers/guards.js';
|
|
13
13
|
import '../../../../internals/serializable.js';
|
|
@@ -21,7 +21,7 @@ import '../../../../backend/message.js';
|
|
|
21
21
|
import 'ai';
|
|
22
22
|
import '../../prompts.js';
|
|
23
23
|
import 'ajv';
|
|
24
|
-
import '../../../../chat-
|
|
24
|
+
import '../../../../chat-DrqwUgD8.js';
|
|
25
25
|
import 'promise-based-task';
|
|
26
26
|
import '../../../../cache/base.js';
|
|
27
27
|
import '../../../../backend/constants.js';
|
|
@@ -30,7 +30,7 @@ import 'pino';
|
|
|
30
30
|
import '../../../../internals/helpers/promise.js';
|
|
31
31
|
import '../../../../internals/helpers/schema.js';
|
|
32
32
|
import 'zod-to-json-schema';
|
|
33
|
-
import '../../../../base-
|
|
33
|
+
import '../../../../base-CyFx7BRL.js';
|
|
34
34
|
import '../../../../internals/helpers/counter.js';
|
|
35
35
|
|
|
36
36
|
declare class DeepThinkRunner extends DefaultRunner {
|
|
@@ -52,12 +52,12 @@ declare class DeepThinkRunner extends DefaultRunner {
|
|
|
52
52
|
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
53
53
|
createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
54
54
|
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
instructions: string;
|
|
55
56
|
tools: z.objectOutputType<{
|
|
56
57
|
name: z.ZodString;
|
|
57
58
|
description: z.ZodString;
|
|
58
59
|
schema: z.ZodString;
|
|
59
60
|
}, z.ZodTypeAny, "passthrough">[];
|
|
60
|
-
instructions: string;
|
|
61
61
|
createdAt?: string | null | undefined;
|
|
62
62
|
}, {
|
|
63
63
|
tools: z.objectInputType<{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PromptTemplate } from '../../../../template.cjs';
|
|
2
|
-
import { B as BaseRunner, R as ReActAgentRunnerLLMInput, a as ReActAgentRunnerToolInput } from '../../../../agent-
|
|
2
|
+
import { B as BaseRunner, R as ReActAgentRunnerLLMInput, a as ReActAgentRunnerToolInput } from '../../../../agent-BVuc9Nfn.cjs';
|
|
3
3
|
import { ReActAgentRunIteration, ReActAgentRunInput, ReActAgentParserInput } from '../../types.cjs';
|
|
4
4
|
import { AnyTool } from '../../../../tools/base.cjs';
|
|
5
5
|
import { LinePrefixParser } from '../../../../parsers/linePrefix.cjs';
|
|
@@ -12,16 +12,16 @@ 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-jN55XZZq.cjs';
|
|
16
16
|
import '../../../../internals/helpers/promise.cjs';
|
|
17
|
-
import '../../../../base-
|
|
18
|
-
import '../../../../chat-
|
|
19
|
-
import 'ai';
|
|
17
|
+
import '../../../../base-XfWeXQ-S.cjs';
|
|
18
|
+
import '../../../../chat-BOb9n7AJ.cjs';
|
|
20
19
|
import 'promise-based-task';
|
|
21
20
|
import '../../../../cache/base.cjs';
|
|
22
21
|
import '../../../../backend/constants.cjs';
|
|
23
22
|
import '../../../../logger/logger.cjs';
|
|
24
23
|
import 'pino';
|
|
24
|
+
import 'ai';
|
|
25
25
|
import '../../../../internals/helpers/counter.cjs';
|
|
26
26
|
import '../../prompts.cjs';
|
|
27
27
|
import '../../../../parsers/field.cjs';
|
|
@@ -52,12 +52,12 @@ declare class DefaultRunner extends BaseRunner {
|
|
|
52
52
|
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
53
53
|
createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
54
54
|
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
instructions: string;
|
|
55
56
|
tools: z.objectOutputType<{
|
|
56
57
|
name: z.ZodString;
|
|
57
58
|
description: z.ZodString;
|
|
58
59
|
schema: z.ZodString;
|
|
59
60
|
}, z.ZodTypeAny, "passthrough">[];
|
|
60
|
-
instructions: string;
|
|
61
61
|
createdAt?: string | null | undefined;
|
|
62
62
|
}, {
|
|
63
63
|
tools: z.objectInputType<{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PromptTemplate } from '../../../../template.js';
|
|
2
|
-
import { B as BaseRunner, R as ReActAgentRunnerLLMInput, a as ReActAgentRunnerToolInput } from '../../../../agent-
|
|
2
|
+
import { B as BaseRunner, R as ReActAgentRunnerLLMInput, a as ReActAgentRunnerToolInput } from '../../../../agent-Cuy8Q4gw.js';
|
|
3
3
|
import { ReActAgentRunIteration, ReActAgentRunInput, ReActAgentParserInput } from '../../types.js';
|
|
4
4
|
import { AnyTool } from '../../../../tools/base.js';
|
|
5
5
|
import { LinePrefixParser } from '../../../../parsers/linePrefix.js';
|
|
@@ -12,16 +12,16 @@ 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-36-9MnvA.js';
|
|
16
16
|
import '../../../../internals/helpers/promise.js';
|
|
17
|
-
import '../../../../base-
|
|
18
|
-
import '../../../../chat-
|
|
19
|
-
import 'ai';
|
|
17
|
+
import '../../../../base-CyFx7BRL.js';
|
|
18
|
+
import '../../../../chat-DrqwUgD8.js';
|
|
20
19
|
import 'promise-based-task';
|
|
21
20
|
import '../../../../cache/base.js';
|
|
22
21
|
import '../../../../backend/constants.js';
|
|
23
22
|
import '../../../../logger/logger.js';
|
|
24
23
|
import 'pino';
|
|
24
|
+
import 'ai';
|
|
25
25
|
import '../../../../internals/helpers/counter.js';
|
|
26
26
|
import '../../prompts.js';
|
|
27
27
|
import '../../../../parsers/field.js';
|
|
@@ -52,12 +52,12 @@ declare class DefaultRunner extends BaseRunner {
|
|
|
52
52
|
}, z.ZodTypeAny, "passthrough">>, "many">;
|
|
53
53
|
createdAt: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
54
54
|
}, "strip", z.ZodTypeAny, {
|
|
55
|
+
instructions: string;
|
|
55
56
|
tools: z.objectOutputType<{
|
|
56
57
|
name: z.ZodString;
|
|
57
58
|
description: z.ZodString;
|
|
58
59
|
schema: z.ZodString;
|
|
59
60
|
}, z.ZodTypeAny, "passthrough">[];
|
|
60
|
-
instructions: string;
|
|
61
61
|
createdAt?: string | null | undefined;
|
|
62
62
|
}, {
|
|
63
63
|
tools: z.objectInputType<{
|
|
@@ -46,12 +46,12 @@ declare const GraniteReActAgentSystemPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
46
46
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
47
47
|
createdAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
48
48
|
}, "strip", zod.ZodTypeAny, {
|
|
49
|
+
instructions: string;
|
|
49
50
|
tools: zod.objectOutputType<{
|
|
50
51
|
name: zod.ZodString;
|
|
51
52
|
description: zod.ZodString;
|
|
52
53
|
schema: zod.ZodString;
|
|
53
54
|
}, zod.ZodTypeAny, "passthrough">[];
|
|
54
|
-
instructions: string;
|
|
55
55
|
createdAt?: string | null | undefined;
|
|
56
56
|
}, {
|
|
57
57
|
tools: zod.objectInputType<{
|
|
@@ -46,12 +46,12 @@ declare const GraniteReActAgentSystemPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
46
46
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
47
47
|
createdAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
48
48
|
}, "strip", zod.ZodTypeAny, {
|
|
49
|
+
instructions: string;
|
|
49
50
|
tools: zod.objectOutputType<{
|
|
50
51
|
name: zod.ZodString;
|
|
51
52
|
description: zod.ZodString;
|
|
52
53
|
schema: zod.ZodString;
|
|
53
54
|
}, zod.ZodTypeAny, "passthrough">[];
|
|
54
|
-
instructions: string;
|
|
55
55
|
createdAt?: string | null | undefined;
|
|
56
56
|
}, {
|
|
57
57
|
tools: zod.objectInputType<{
|
|
@@ -4,10 +4,10 @@ import * as zod from 'zod';
|
|
|
4
4
|
import { AnyTool } from '../../../../tools/base.cjs';
|
|
5
5
|
import { DefaultRunner } from '../default/runner.cjs';
|
|
6
6
|
import { ReActAgentRunOptions, ReActAgentParserInput } from '../../types.cjs';
|
|
7
|
-
import { b as ReActAgentInput, c as ReActAgent } from '../../../../agent-
|
|
7
|
+
import { b as ReActAgentInput, c as ReActAgent } from '../../../../agent-BVuc9Nfn.cjs';
|
|
8
8
|
import { GetRunContext } from '../../../../context.cjs';
|
|
9
9
|
import 'node_modules/remeda/dist/ToString-DKW-jYvM.js';
|
|
10
|
-
import '../../../../emitter-
|
|
10
|
+
import '../../../../emitter-jN55XZZq.cjs';
|
|
11
11
|
import '../../../../internals/types.cjs';
|
|
12
12
|
import '../../../../internals/helpers/guards.cjs';
|
|
13
13
|
import '../../../../internals/serializable.cjs';
|
|
@@ -25,8 +25,8 @@ import '../../../../internals/helpers/promise.cjs';
|
|
|
25
25
|
import '../../../../backend/message.cjs';
|
|
26
26
|
import 'ai';
|
|
27
27
|
import '../../../../memory/base.cjs';
|
|
28
|
-
import '../../../../base-
|
|
29
|
-
import '../../../../chat-
|
|
28
|
+
import '../../../../base-XfWeXQ-S.cjs';
|
|
29
|
+
import '../../../../chat-BOb9n7AJ.cjs';
|
|
30
30
|
import '../../../../backend/constants.cjs';
|
|
31
31
|
import '../../../../logger/logger.cjs';
|
|
32
32
|
import 'pino';
|
|
@@ -53,12 +53,12 @@ declare class GraniteRunner extends DefaultRunner {
|
|
|
53
53
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
54
54
|
createdAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
55
55
|
}, "strip", zod.ZodTypeAny, {
|
|
56
|
+
instructions: string;
|
|
56
57
|
tools: zod.objectOutputType<{
|
|
57
58
|
name: zod.ZodString;
|
|
58
59
|
description: zod.ZodString;
|
|
59
60
|
schema: zod.ZodString;
|
|
60
61
|
}, zod.ZodTypeAny, "passthrough">[];
|
|
61
|
-
instructions: string;
|
|
62
62
|
createdAt?: string | null | undefined;
|
|
63
63
|
}, {
|
|
64
64
|
tools: zod.objectInputType<{
|
|
@@ -4,10 +4,10 @@ import * as zod from 'zod';
|
|
|
4
4
|
import { AnyTool } from '../../../../tools/base.js';
|
|
5
5
|
import { DefaultRunner } from '../default/runner.js';
|
|
6
6
|
import { ReActAgentRunOptions, ReActAgentParserInput } from '../../types.js';
|
|
7
|
-
import { b as ReActAgentInput, c as ReActAgent } from '../../../../agent-
|
|
7
|
+
import { b as ReActAgentInput, c as ReActAgent } from '../../../../agent-Cuy8Q4gw.js';
|
|
8
8
|
import { GetRunContext } from '../../../../context.js';
|
|
9
9
|
import 'node_modules/remeda/dist/ToString-DKW-jYvM.js';
|
|
10
|
-
import '../../../../emitter-
|
|
10
|
+
import '../../../../emitter-36-9MnvA.js';
|
|
11
11
|
import '../../../../internals/types.js';
|
|
12
12
|
import '../../../../internals/helpers/guards.js';
|
|
13
13
|
import '../../../../internals/serializable.js';
|
|
@@ -25,8 +25,8 @@ import '../../../../internals/helpers/promise.js';
|
|
|
25
25
|
import '../../../../backend/message.js';
|
|
26
26
|
import 'ai';
|
|
27
27
|
import '../../../../memory/base.js';
|
|
28
|
-
import '../../../../base-
|
|
29
|
-
import '../../../../chat-
|
|
28
|
+
import '../../../../base-CyFx7BRL.js';
|
|
29
|
+
import '../../../../chat-DrqwUgD8.js';
|
|
30
30
|
import '../../../../backend/constants.js';
|
|
31
31
|
import '../../../../logger/logger.js';
|
|
32
32
|
import 'pino';
|
|
@@ -53,12 +53,12 @@ declare class GraniteRunner extends DefaultRunner {
|
|
|
53
53
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
54
54
|
createdAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
55
55
|
}, "strip", zod.ZodTypeAny, {
|
|
56
|
+
instructions: string;
|
|
56
57
|
tools: zod.objectOutputType<{
|
|
57
58
|
name: zod.ZodString;
|
|
58
59
|
description: zod.ZodString;
|
|
59
60
|
schema: zod.ZodString;
|
|
60
61
|
}, zod.ZodTypeAny, "passthrough">[];
|
|
61
|
-
instructions: string;
|
|
62
62
|
createdAt?: string | null | undefined;
|
|
63
63
|
}, {
|
|
64
64
|
tools: zod.objectInputType<{
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { BaseMemory } from '../../memory/base.cjs';
|
|
2
2
|
import { Message } from '../../backend/message.cjs';
|
|
3
|
-
import { C as Callback } from '../../emitter-
|
|
3
|
+
import { C as Callback } from '../../emitter-jN55XZZq.cjs';
|
|
4
4
|
import { AnyTool, BaseToolRunOptions, ToolOutput, ToolError } from '../../tools/base.cjs';
|
|
5
5
|
import { ReActAgentSystemPrompt, ReActAgentAssistantPrompt, ReActAgentUserPrompt, ReActAgentUserEmptyPrompt, ReActAgentToolErrorPrompt, ReActAgentToolInputErrorPrompt, ReActAgentToolNoResultsPrompt, ReActAgentToolNotFoundPrompt, ReActAgentSchemaErrorPrompt } from './prompts.cjs';
|
|
6
6
|
import { LinePrefixParser } from '../../parsers/linePrefix.cjs';
|
|
7
7
|
import { ZodParserField, JSONParserField } from '../../parsers/field.cjs';
|
|
8
8
|
import { NonUndefined } from '../../internals/types.cjs';
|
|
9
|
-
import { n as ChatModelOutput } from '../../chat-
|
|
9
|
+
import { n as ChatModelOutput } from '../../chat-BOb9n7AJ.cjs';
|
|
10
10
|
import '../../errors.cjs';
|
|
11
11
|
import '../../internals/helpers/guards.cjs';
|
|
12
12
|
import '../../internals/serializable.cjs';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { BaseMemory } from '../../memory/base.js';
|
|
2
2
|
import { Message } from '../../backend/message.js';
|
|
3
|
-
import { C as Callback } from '../../emitter-
|
|
3
|
+
import { C as Callback } from '../../emitter-36-9MnvA.js';
|
|
4
4
|
import { AnyTool, BaseToolRunOptions, ToolOutput, ToolError } from '../../tools/base.js';
|
|
5
5
|
import { ReActAgentSystemPrompt, ReActAgentAssistantPrompt, ReActAgentUserPrompt, ReActAgentUserEmptyPrompt, ReActAgentToolErrorPrompt, ReActAgentToolInputErrorPrompt, ReActAgentToolNoResultsPrompt, ReActAgentToolNotFoundPrompt, ReActAgentSchemaErrorPrompt } from './prompts.js';
|
|
6
6
|
import { LinePrefixParser } from '../../parsers/linePrefix.js';
|
|
7
7
|
import { ZodParserField, JSONParserField } from '../../parsers/field.js';
|
|
8
8
|
import { NonUndefined } from '../../internals/types.js';
|
|
9
|
-
import { n as ChatModelOutput } from '../../chat-
|
|
9
|
+
import { n as ChatModelOutput } from '../../chat-DrqwUgD8.js';
|
|
10
10
|
import '../../errors.js';
|
|
11
11
|
import '../../internals/helpers/guards.js';
|
|
12
12
|
import '../../internals/serializable.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/agents/requirement/agent.ts"],"names":["RequirementAgent","BaseAgent","emitter","Emitter","root","child","namespace","creator","input","runner","RequirementAgentRunner","memory","UnconstrainedMemory","tools","requirements","saveIntermediateSteps","finalAnswerAsTool","toolCallChecker","middlewares","push","register","_run","options","run","execution","maxRetriesPerStep","totalMaxRetries","maxIterations","createToolCallChecker","llm","expectedOutput","templates","newMessages","processInput","addMessages","messages","finalState","reset","addMany","lastPair","slice","answer","Error","result","state","prompt","userMessage","UserMessage","task","render","context","undefined","config","Object","assign","checker","ToolCallChecker","enabled","meta","name","description","length","extraDescription","map","tool","join","overrides","finalized","mapObj","system","RequirementAgentSystemPrompt","RequirementAgentTaskPrompt","toolError","RequirementAgentToolErrorPrompt","toolNoResult","RequirementAgentToolNoResultPrompt","key","defaultTemplate","override","PromptTemplate","role","instructions","notes","update","defaults","pickBy","isEmptyish","castArray","v","isDefined","createSnapshot","shallowCopy","runnerClass"],"mappings":";;;;;;;;;;;;;;;;;AAqFO,MAAMA,yBAAyBC,kBAAAA,CAAAA;EArFtC;;;EA0FkBC,OAAAA,GAAUC,mBAAAA,CAAQC,KAA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AAA,EAAM,KAAKxE,KAAAA,CAAMwE,IAAAA;AACjBC,UAAAA,YAAAA,EAAcK,kBAAW,IAAA,CAAK9E,KAAAA,CAAMyE,YAAY,CAAA,GAC5C9B,MAAAA,GACAoC,oBAAU,IAAA,CAAK/E,KAAAA,CAAMyE,YAAY,CAAA,CAC9BlB,GAAAA,CAAI,CAACyB,CAAAA,KAAM,CAAA,EAAA,EAAKA,CAAAA,CAAAA,CAAG,CAAA,CACnBvB,KAAK,IAAA,CAAA;AACZiB,UAAAA,KAAAA,EAAOI,kBAAW,IAAA,CAAK9E,KAAAA,CAAM0E,KAAK,CAAA,GAC9B/B,MAAAA,GACAoC,oBAAU,IAAA,CAAK/E,KAAAA,CAAM0E,KAAK,CAAA,CACvBnB,GAAAA,CAAI,CAACyB,CAAAA,KAAM,CAAA,EAAA,EAAKA,CAAAA,CAAAA,CAAG,CAAA,CACnBvB,KAAK,IAAA;AACd,SAAA,EACAwB,gBAAAA;OAEJ,CAAA;AACF;AAEA,IAAA,OAAOtB,SAAAA;AACT;EAEAuB,cAAAA,GAAiB;AACf,IAAA,OAAO;AACL,MAAA,GAAG,MAAMA,cAAAA,EAAAA;MACTlF,KAAAA,EAAOmF,qBAAAA,CAAY,KAAKnF,KAAK,CAAA;AAC7BN,MAAAA,OAAAA,EAAS,IAAA,CAAKA,OAAAA;AACd0F,MAAAA,WAAAA,EAAa,IAAA,CAAKnF;AACpB,KAAA;AACF;AAEA,EAAA,IAAIE,OAAOA,MAAAA,EAAoB;AAC7B,IAAA,IAAA,CAAKH,MAAMG,MAAAA,GAASA,MAAAA;AACtB;AAEA,EAAA,IAAIA,MAAAA,GAAqB;AACvB,IAAA,OAAO,KAAKH,KAAAA,CAAMG,MAAAA;AACpB;AACF","file":"agent.cjs","sourcesContent":["/**\n * Copyright 2025 © BeeAI a Series of LF Projects, LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { BaseAgent } from \"@/agents/base.js\";\nimport { AnyTool } from \"@/tools/base.js\";\nimport { BaseMemory } from \"@/memory/base.js\";\nimport { AgentMeta } from \"@/agents/types.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport { ChatModel } from \"@/backend/chat.js\";\nimport type { GetRunContext, MiddlewareType } from \"@/context.js\";\nimport { UnconstrainedMemory } from \"@/memory/unconstrainedMemory.js\";\nimport { Message, UserMessage } from \"@/backend/message.js\";\nimport { shallowCopy } from \"@/serializer/utils.js\";\nimport { mapObj } from \"@/internals/helpers/object.js\";\nimport { PromptTemplate } from \"@/template.js\";\nimport {\n RequirementAgentCallbacks,\n RequirementAgentExecutionConfig,\n RequirementAgentOutput,\n RequirementAgentRunInput,\n RequirementAgentRunOptions,\n RequirementAgentTemplates,\n} from \"./types.js\";\nimport {\n RequirementAgentSystemPrompt,\n RequirementAgentTaskPrompt,\n RequirementAgentToolErrorPrompt,\n RequirementAgentToolNoResultPrompt,\n} from \"./prompts.js\";\nimport { Requirement } from \"./requirements/requirement.js\";\nimport { RequirementAgentRunner } from \"./runner.js\";\nimport { ToolCallChecker, ToolCallCheckerConfig } from \"./utils/toolCallChecker.js\";\nimport { isDefined, isEmptyish, pickBy } from \"remeda\";\nimport { castArray } from \"@/internals/helpers/array.js\";\nimport type { RequiredExcept } from \"@/internals/types.js\";\n\nexport type RequirementAgentTemplateFactory<K extends keyof RequirementAgentTemplates> = (\n template: RequirementAgentTemplates[K],\n) => RequirementAgentTemplates[K];\n\nexport interface RequirementAgentInput {\n llm: ChatModel;\n memory?: BaseMemory;\n tools?: AnyTool[];\n requirements?: Requirement[];\n name?: string;\n description?: string;\n role?: string;\n instructions?: string | string[];\n notes?: string | string[];\n toolCallChecker?: boolean | ToolCallCheckerConfig;\n finalAnswerAsTool?: boolean;\n saveIntermediateSteps?: boolean;\n execution?: RequirementAgentExecutionConfig;\n templates?: Partial<{\n [K in keyof RequirementAgentTemplates]:\n | RequirementAgentTemplates[K]\n | RequirementAgentTemplateFactory<K>;\n }>;\n middlewares?: MiddlewareType<RequirementAgent>[];\n}\n\ntype InternalRequirementAgentInput = RequiredExcept<\n RequirementAgentInput,\n | \"role\"\n | \"instructions\"\n | \"name\"\n | \"description\"\n | \"templates\"\n | \"notes\"\n | \"execution\"\n | \"middlewares\"\n>;\n\n/**\n * RequirementAgent - A declarative AI agent with rule-based constraints\n *\n * The RequirementAgent provides predictable, controlled execution behavior across\n * different language models through rule-based constraints (Requirements).\n * Requirements can be configured as strict or flexible as necessary, adapting to\n * task requirements while ensuring consistent execution regardless of the underlying\n * model's reasoning or tool-calling capabilities.\n */\nexport class RequirementAgent extends BaseAgent<\n RequirementAgentRunInput,\n RequirementAgentOutput,\n RequirementAgentRunOptions\n> {\n public readonly emitter = Emitter.root.child<RequirementAgentCallbacks>({\n namespace: [\"agent\", \"requirement\"],\n creator: this,\n });\n\n protected readonly input: InternalRequirementAgentInput;\n\n protected runner: new (\n ...args: ConstructorParameters<typeof RequirementAgentRunner>\n ) => RequirementAgentRunner = RequirementAgentRunner;\n\n constructor(input: RequirementAgentInput) {\n super();\n this.input = {\n ...input,\n memory: input.memory || new UnconstrainedMemory(),\n tools: input.tools || [],\n requirements: input.requirements || [],\n saveIntermediateSteps: input.saveIntermediateSteps ?? true,\n finalAnswerAsTool: input.finalAnswerAsTool ?? true,\n toolCallChecker: input.toolCallChecker ?? true,\n };\n if (input.middlewares) {\n this.middlewares.push(...input.middlewares);\n }\n }\n\n static {\n this.register();\n }\n\n protected async _run(\n input: RequirementAgentRunInput,\n options: RequirementAgentRunOptions = {},\n run: GetRunContext<typeof this>,\n ): Promise<RequirementAgentOutput> {\n const execution: RequirementAgentExecutionConfig = {\n maxRetriesPerStep: 3,\n totalMaxRetries: 20,\n maxIterations: 20,\n ...this.input.execution,\n ...options.execution,\n };\n\n const toolCallChecker = this.createToolCallChecker();\n\n const runner = new this.runner(\n this.input.llm,\n execution,\n this.input.tools || [],\n this.input.requirements || [],\n input.expectedOutput || null,\n toolCallChecker,\n run,\n this.input.finalAnswerAsTool,\n this.templates,\n );\n\n // Process input messages\n const newMessages = this.processInput(input);\n await runner.addMessages([...this.memory.messages]);\n await runner.addMessages(newMessages);\n\n // Run the agent\n const finalState = await runner.run();\n\n // Update memory\n if (this.input.saveIntermediateSteps) {\n this.memory.reset();\n await this.memory.addMany(finalState.memory.messages);\n } else {\n await this.memory.addMany(newMessages);\n // Add last tool call pair\n const messages = finalState.memory.messages;\n const lastPair = messages.slice(-2);\n await this.memory.addMany(lastPair);\n }\n\n if (!finalState.answer) {\n throw new Error(\"Agent did not produce a final answer\");\n }\n\n return {\n result: finalState.answer,\n memory: finalState.memory,\n state: finalState,\n };\n }\n\n protected processInput(input: RequirementAgentRunInput): Message[] {\n if (!input.prompt) {\n return [];\n }\n\n const userMessage = new UserMessage(\n this.templates.task.render({\n prompt: input.prompt,\n context: input.context,\n expectedOutput: typeof input.expectedOutput === \"string\" ? input.expectedOutput : undefined,\n }),\n );\n\n return [userMessage];\n }\n\n protected createToolCallChecker(): ToolCallChecker {\n const config: ToolCallCheckerConfig = {};\n\n if (typeof this.input.toolCallChecker === \"object\") {\n Object.assign(config, this.input.toolCallChecker);\n }\n\n const checker = new ToolCallChecker(config);\n checker.enabled = this.input.toolCallChecker !== false;\n return checker;\n }\n\n get meta(): AgentMeta {\n const tools = this.input.tools || [];\n\n return {\n name: this.input.name ?? \"Requirement\",\n tools,\n description:\n this.input.description ??\n \"The RequirementAgent is a declarative AI agent implementation that provides predictable, \" +\n \"controlled execution behavior across different language models through rule-based constraints.\",\n ...(tools.length > 0 && {\n extraDescription: [\n `Tools that I can use to accomplish given task.`,\n ...tools.map((tool) => `Tool '${tool.name}': ${tool.description}.`),\n ].join(\"\\n\"),\n }),\n };\n }\n\n protected get templates(): RequirementAgentTemplates {\n const overrides = this.input.templates || {};\n const finalized = mapObj({\n system: RequirementAgentSystemPrompt,\n task: RequirementAgentTaskPrompt,\n toolError: RequirementAgentToolErrorPrompt,\n toolNoResult: RequirementAgentToolNoResultPrompt,\n } as RequirementAgentTemplates)((\n key,\n defaultTemplate: RequirementAgentTemplates[typeof key],\n ) => {\n const override = overrides[key] ?? defaultTemplate;\n if (override instanceof PromptTemplate) {\n return override;\n }\n return override(defaultTemplate) ?? defaultTemplate;\n });\n\n if (this.input.role || this.input.instructions || this.input.notes) {\n finalized.system.update({\n defaults: pickBy(\n {\n role: this.input.role,\n instructions: isEmptyish(this.input.instructions)\n ? undefined\n : castArray(this.input.instructions)\n .map((v) => `- ${v}`)\n .join(\"\\n\"),\n notes: isEmptyish(this.input.notes)\n ? undefined\n : castArray(this.input.notes)\n .map((v) => `- ${v}`)\n .join(\"\\n\"),\n },\n isDefined,\n ),\n });\n }\n\n return finalized;\n }\n\n createSnapshot() {\n return {\n ...super.createSnapshot(),\n input: shallowCopy(this.input),\n emitter: this.emitter,\n runnerClass: this.runner,\n };\n }\n\n set memory(memory: BaseMemory) {\n this.input.memory = memory;\n }\n\n get memory(): BaseMemory {\n return this.input.memory!;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/agents/requirement/agent.ts"],"names":["RequirementAgent","BaseAgent","emitter","Emitter","root","child","namespace","creator","input","runner","RequirementAgentRunner","memory","UnconstrainedMemory","tools","requirements","saveIntermediateSteps","finalAnswerAsTool","toolCallChecker","middlewares","push","register","_run","options","run","execution","maxRetriesPerStep","totalMaxRetries","maxIterations","createToolCallChecker","llm","expectedOutput","templates","newMessages","processInput","addMessages","messages","finalState","reset","addMany","lastPair","slice","answer","Error","result","state","prompt","userMessage","UserMessage","task","render","context","undefined","config","Object","assign","checker","ToolCallChecker","enabled","meta","name","description","length","extraDescription","map","tool","join","overrides","finalized","mapObj","system","RequirementAgentSystemPrompt","RequirementAgentTaskPrompt","toolError","RequirementAgentToolErrorPrompt","toolNoResult","RequirementAgentToolNoResultPrompt","key","defaultTemplate","override","PromptTemplate","role","instructions","notes","update","defaults","pickBy","isEmptyish","castArray","v","isDefined","createSnapshot","shallowCopy"],"mappings":";;;;;;;;;;;;;;;;;AAqFO,MAAMA,yBAAy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apache-2.0\n */\n\nimport { BaseAgent } from \"@/agents/base.js\";\nimport { AnyTool } from \"@/tools/base.js\";\nimport { BaseMemory } from \"@/memory/base.js\";\nimport { AgentMeta } from \"@/agents/types.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport { ChatModel } from \"@/backend/chat.js\";\nimport type { GetRunContext, MiddlewareType } from \"@/context.js\";\nimport { UnconstrainedMemory } from \"@/memory/unconstrainedMemory.js\";\nimport { Message, UserMessage } from \"@/backend/message.js\";\nimport { shallowCopy } from \"@/serializer/utils.js\";\nimport { mapObj } from \"@/internals/helpers/object.js\";\nimport { PromptTemplate } from \"@/template.js\";\nimport {\n RequirementAgentCallbacks,\n RequirementAgentExecutionConfig,\n RequirementAgentOutput,\n RequirementAgentRunInput,\n RequirementAgentRunOptions,\n RequirementAgentTemplates,\n} from \"./types.js\";\nimport {\n RequirementAgentSystemPrompt,\n RequirementAgentTaskPrompt,\n RequirementAgentToolErrorPrompt,\n RequirementAgentToolNoResultPrompt,\n} from \"./prompts.js\";\nimport { Requirement } from \"./requirements/requirement.js\";\nimport { RequirementAgentRunner } from \"./runner.js\";\nimport { ToolCallChecker, ToolCallCheckerConfig } from \"./utils/toolCallChecker.js\";\nimport { isDefined, isEmptyish, pickBy } from \"remeda\";\nimport { castArray } from \"@/internals/helpers/array.js\";\nimport type { RequiredExcept } from \"@/internals/types.js\";\n\nexport type RequirementAgentTemplateFactory<K extends keyof RequirementAgentTemplates> = (\n template: RequirementAgentTemplates[K],\n) => RequirementAgentTemplates[K];\n\nexport interface RequirementAgentInput {\n llm: ChatModel;\n memory?: BaseMemory;\n tools?: AnyTool[];\n requirements?: Requirement[];\n name?: string;\n description?: string;\n role?: string;\n instructions?: string | string[];\n notes?: string | string[];\n toolCallChecker?: boolean | ToolCallCheckerConfig;\n finalAnswerAsTool?: boolean;\n saveIntermediateSteps?: boolean;\n execution?: RequirementAgentExecutionConfig;\n templates?: Partial<{\n [K in keyof RequirementAgentTemplates]:\n | RequirementAgentTemplates[K]\n | RequirementAgentTemplateFactory<K>;\n }>;\n middlewares?: MiddlewareType<RequirementAgent>[];\n}\n\ntype InternalRequirementAgentInput = RequiredExcept<\n RequirementAgentInput,\n | \"role\"\n | \"instructions\"\n | \"name\"\n | \"description\"\n | \"templates\"\n | \"notes\"\n | \"execution\"\n | \"middlewares\"\n>;\n\n/**\n * RequirementAgent - A declarative AI agent with rule-based constraints\n *\n * The RequirementAgent provides predictable, controlled execution behavior across\n * different language models through rule-based constraints (Requirements).\n * Requirements can be configured as strict or flexible as necessary, adapting to\n * task requirements while ensuring consistent execution regardless of the underlying\n * model's reasoning or tool-calling capabilities.\n */\nexport class RequirementAgent extends BaseAgent<\n RequirementAgentRunInput,\n RequirementAgentOutput,\n RequirementAgentRunOptions\n> {\n public readonly emitter = Emitter.root.child<RequirementAgentCallbacks>({\n namespace: [\"agent\", \"requirement\"],\n creator: this,\n });\n\n protected readonly input: InternalRequirementAgentInput;\n\n protected runner: new (\n ...args: ConstructorParameters<typeof RequirementAgentRunner>\n ) => RequirementAgentRunner = RequirementAgentRunner;\n\n constructor(input: RequirementAgentInput) {\n super();\n this.input = {\n ...input,\n memory: input.memory || new UnconstrainedMemory(),\n tools: input.tools || [],\n requirements: input.requirements || [],\n saveIntermediateSteps: input.saveIntermediateSteps ?? true,\n finalAnswerAsTool: input.finalAnswerAsTool ?? true,\n toolCallChecker: input.toolCallChecker ?? true,\n };\n if (input.middlewares) {\n this.middlewares.push(...input.middlewares);\n }\n }\n\n static {\n this.register();\n }\n\n protected async _run(\n input: RequirementAgentRunInput,\n options: RequirementAgentRunOptions = {},\n run: GetRunContext<typeof this>,\n ): Promise<RequirementAgentOutput> {\n const execution: RequirementAgentExecutionConfig = {\n maxRetriesPerStep: 3,\n totalMaxRetries: 20,\n maxIterations: 20,\n ...this.input.execution,\n ...options.execution,\n };\n\n const toolCallChecker = this.createToolCallChecker();\n\n const runner = new this.runner(\n this.input.llm,\n execution,\n this.input.tools || [],\n this.input.requirements || [],\n input.expectedOutput || null,\n toolCallChecker,\n run,\n this.input.finalAnswerAsTool,\n this.templates,\n );\n\n // Process input messages\n const newMessages = this.processInput(input);\n await runner.addMessages([...this.memory.messages]);\n await runner.addMessages(newMessages);\n\n // Run the agent\n const finalState = await runner.run();\n\n // Update memory\n if (this.input.saveIntermediateSteps) {\n this.memory.reset();\n await this.memory.addMany(finalState.memory.messages);\n } else {\n await this.memory.addMany(newMessages);\n // Add last tool call pair\n const messages = finalState.memory.messages;\n const lastPair = messages.slice(-2);\n await this.memory.addMany(lastPair);\n }\n\n if (!finalState.answer) {\n throw new Error(\"Agent did not produce a final answer\");\n }\n\n return {\n result: finalState.answer,\n memory: finalState.memory,\n state: finalState,\n };\n }\n\n protected processInput(input: RequirementAgentRunInput): Message[] {\n if (!input.prompt) {\n return [];\n }\n\n const userMessage = new UserMessage(\n this.templates.task.render({\n prompt: input.prompt,\n context: input.context,\n expectedOutput: typeof input.expectedOutput === \"string\" ? input.expectedOutput : undefined,\n }),\n );\n\n return [userMessage];\n }\n\n protected createToolCallChecker(): ToolCallChecker {\n const config: ToolCallCheckerConfig = {};\n\n if (typeof this.input.toolCallChecker === \"object\") {\n Object.assign(config, this.input.toolCallChecker);\n }\n\n const checker = new ToolCallChecker(config);\n checker.enabled = this.input.toolCallChecker !== false;\n return checker;\n }\n\n get meta(): AgentMeta {\n const tools = this.input.tools || [];\n\n return {\n name: this.input.name ?? \"Requirement\",\n tools,\n description:\n this.input.description ??\n \"The RequirementAgent is a declarative AI agent implementation that provides predictable, \" +\n \"controlled execution behavior across different language models through rule-based constraints.\",\n ...(tools.length > 0 && {\n extraDescription: [\n `Tools that I can use to accomplish given task.`,\n ...tools.map((tool) => `Tool '${tool.name}': ${tool.description}.`),\n ].join(\"\\n\"),\n }),\n };\n }\n\n protected get templates(): RequirementAgentTemplates {\n const overrides = this.input.templates || {};\n const finalized = mapObj({\n system: RequirementAgentSystemPrompt,\n task: RequirementAgentTaskPrompt,\n toolError: RequirementAgentToolErrorPrompt,\n toolNoResult: RequirementAgentToolNoResultPrompt,\n } as RequirementAgentTemplates)((\n key,\n defaultTemplate: RequirementAgentTemplates[typeof key],\n ) => {\n const override = overrides[key] ?? defaultTemplate;\n if (override instanceof PromptTemplate) {\n return override;\n }\n return override(defaultTemplate) ?? defaultTemplate;\n });\n\n if (this.input.role || this.input.instructions || this.input.notes) {\n finalized.system.update({\n defaults: pickBy(\n {\n role: this.input.role,\n instructions: isEmptyish(this.input.instructions)\n ? undefined\n : castArray(this.input.instructions)\n .map((v) => `- ${v}`)\n .join(\"\\n\"),\n notes: isEmptyish(this.input.notes)\n ? undefined\n : castArray(this.input.notes)\n .map((v) => `- ${v}`)\n .join(\"\\n\"),\n },\n isDefined,\n ),\n });\n }\n\n return finalized;\n }\n\n createSnapshot() {\n return {\n ...super.createSnapshot(),\n input: shallowCopy(this.input),\n emitter: this.emitter,\n runner: this.runner,\n };\n }\n\n set memory(memory: BaseMemory) {\n this.input.memory = memory;\n }\n\n get memory(): BaseMemory {\n return this.input.memory!;\n }\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import '../../context.cjs';
|
|
2
2
|
import 'zod';
|
|
3
|
-
import '../../base-
|
|
3
|
+
import '../../base-XfWeXQ-S.cjs';
|
|
4
4
|
import '../../tools/base.cjs';
|
|
5
5
|
import '../../memory/base.cjs';
|
|
6
|
-
import '../../emitter-
|
|
7
|
-
import '../../chat-
|
|
6
|
+
import '../../emitter-jN55XZZq.cjs';
|
|
7
|
+
import '../../chat-BOb9n7AJ.cjs';
|
|
8
8
|
import '../../backend/message.cjs';
|
|
9
|
-
import '../../types-
|
|
9
|
+
import '../../types-W0QttuP_.cjs';
|
|
10
10
|
import './requirements/requirement.cjs';
|
|
11
11
|
export { b as RequirementAgent, a as RequirementAgentInput, R as RequirementAgentTemplateFactory } from './runner.cjs';
|
|
12
12
|
import './utils/toolCallChecker.cjs';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import '../../context.js';
|
|
2
2
|
import 'zod';
|
|
3
|
-
import '../../base-
|
|
3
|
+
import '../../base-CyFx7BRL.js';
|
|
4
4
|
import '../../tools/base.js';
|
|
5
5
|
import '../../memory/base.js';
|
|
6
|
-
import '../../emitter-
|
|
7
|
-
import '../../chat-
|
|
6
|
+
import '../../emitter-36-9MnvA.js';
|
|
7
|
+
import '../../chat-DrqwUgD8.js';
|
|
8
8
|
import '../../backend/message.js';
|
|
9
|
-
import '../../types-
|
|
9
|
+
import '../../types-CJwiMH3u.js';
|
|
10
10
|
import './requirements/requirement.js';
|
|
11
11
|
export { b as RequirementAgent, a as RequirementAgentInput, R as RequirementAgentTemplateFactory } from './runner.js';
|
|
12
12
|
import './utils/toolCallChecker.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/agents/requirement/agent.ts"],"names":["RequirementAgent","BaseAgent","emitter","Emitter","root","child","namespace","creator","input","runner","RequirementAgentRunner","memory","UnconstrainedMemory","tools","requirements","saveIntermediateSteps","finalAnswerAsTool","toolCallChecker","middlewares","push","register","_run","options","run","execution","maxRetriesPerStep","totalMaxRetries","maxIterations","createToolCallChecker","llm","expectedOutput","templates","newMessages","processInput","addMessages","messages","finalState","reset","addMany","lastPair","slice","answer","Error","result","state","prompt","userMessage","UserMessage","task","render","context","undefined","config","Object","assign","checker","ToolCallChecker","enabled","meta","name","description","length","extraDescription","map","tool","join","overrides","finalized","mapObj","system","RequirementAgentSystemPrompt","RequirementAgentTaskPrompt","toolError","RequirementAgentToolErrorPrompt","toolNoResult","RequirementAgentToolNoResultPrompt","key","defaultTemplate","override","PromptTemplate","role","instructions","notes","update","defaults","pickBy","isEmptyish","castArray","v","isDefined","createSnapshot","shallowCopy","runnerClass"],"mappings":";;;;;;;;;;;;;;;AAqFO,MAAMA,yBAAyBC,SAAAA,CAAAA;EArFtC;;;EA0FkBC,OAAAA,GAAUC,OAAAA,CAAQC,KAAKC,KAAAA,CAAiC;IACtEC,SAAAA,EAAW;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ACjBC,UAAAA,YAAAA,EAAcK,WAAW,IAAA,CAAK9E,KAAAA,CAAMyE,YAAY,CAAA,GAC5C9B,MAAAA,GACAoC,UAAU,IAAA,CAAK/E,KAAAA,CAAMyE,YAAY,CAAA,CAC9BlB,GAAAA,CAAI,CAACyB,CAAAA,KAAM,CAAA,EAAA,EAAKA,CAAAA,CAAAA,CAAG,CAAA,CACnBvB,KAAK,IAAA,CAAA;AACZiB,UAAAA,KAAAA,EAAOI,WAAW,IAAA,CAAK9E,KAAAA,CAAM0E,KAAK,CAAA,GAC9B/B,MAAAA,GACAoC,UAAU,IAAA,CAAK/E,KAAAA,CAAM0E,KAAK,CAAA,CACvBnB,GAAAA,CAAI,CAACyB,CAAAA,KAAM,CAAA,EAAA,EAAKA,CAAAA,CAAAA,CAAG,CAAA,CACnBvB,KAAK,IAAA;AACd,SAAA,EACAwB,SAAAA;OAEJ,CAAA;AACF;AAEA,IAAA,OAAOtB,SAAAA;AACT;EAEAuB,cAAAA,GAAiB;AACf,IAAA,OAAO;AACL,MAAA,GAAG,MAAMA,cAAAA,EAAAA;MACTlF,KAAAA,EAAOmF,WAAAA,CAAY,KAAKnF,KAAK,CAAA;AAC7BN,MAAAA,OAAAA,EAAS,IAAA,CAAKA,OAAAA;AACd0F,MAAAA,WAAAA,EAAa,IAAA,CAAKnF;AACpB,KAAA;AACF;AAEA,EAAA,IAAIE,OAAOA,MAAAA,EAAoB;AAC7B,IAAA,IAAA,CAAKH,MAAMG,MAAAA,GAASA,MAAAA;AACtB;AAEA,EAAA,IAAIA,MAAAA,GAAqB;AACvB,IAAA,OAAO,KAAKH,KAAAA,CAAMG,MAAAA;AACpB;AACF","file":"agent.js","sourcesContent":["/**\n * Copyright 2025 © BeeAI a Series of LF Projects, LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { BaseAgent } from \"@/agents/base.js\";\nimport { AnyTool } from \"@/tools/base.js\";\nimport { BaseMemory } from \"@/memory/base.js\";\nimport { AgentMeta } from \"@/agents/types.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport { ChatModel } from \"@/backend/chat.js\";\nimport type { GetRunContext, MiddlewareType } from \"@/context.js\";\nimport { UnconstrainedMemory } from \"@/memory/unconstrainedMemory.js\";\nimport { Message, UserMessage } from \"@/backend/message.js\";\nimport { shallowCopy } from \"@/serializer/utils.js\";\nimport { mapObj } from \"@/internals/helpers/object.js\";\nimport { PromptTemplate } from \"@/template.js\";\nimport {\n RequirementAgentCallbacks,\n RequirementAgentExecutionConfig,\n RequirementAgentOutput,\n RequirementAgentRunInput,\n RequirementAgentRunOptions,\n RequirementAgentTemplates,\n} from \"./types.js\";\nimport {\n RequirementAgentSystemPrompt,\n RequirementAgentTaskPrompt,\n RequirementAgentToolErrorPrompt,\n RequirementAgentToolNoResultPrompt,\n} from \"./prompts.js\";\nimport { Requirement } from \"./requirements/requirement.js\";\nimport { RequirementAgentRunner } from \"./runner.js\";\nimport { ToolCallChecker, ToolCallCheckerConfig } from \"./utils/toolCallChecker.js\";\nimport { isDefined, isEmptyish, pickBy } from \"remeda\";\nimport { castArray } from \"@/internals/helpers/array.js\";\nimport type { RequiredExcept } from \"@/internals/types.js\";\n\nexport type RequirementAgentTemplateFactory<K extends keyof RequirementAgentTemplates> = (\n template: RequirementAgentTemplates[K],\n) => RequirementAgentTemplates[K];\n\nexport interface RequirementAgentInput {\n llm: ChatModel;\n memory?: BaseMemory;\n tools?: AnyTool[];\n requirements?: Requirement[];\n name?: string;\n description?: string;\n role?: string;\n instructions?: string | string[];\n notes?: string | string[];\n toolCallChecker?: boolean | ToolCallCheckerConfig;\n finalAnswerAsTool?: boolean;\n saveIntermediateSteps?: boolean;\n execution?: RequirementAgentExecutionConfig;\n templates?: Partial<{\n [K in keyof RequirementAgentTemplates]:\n | RequirementAgentTemplates[K]\n | RequirementAgentTemplateFactory<K>;\n }>;\n middlewares?: MiddlewareType<RequirementAgent>[];\n}\n\ntype InternalRequirementAgentInput = RequiredExcept<\n RequirementAgentInput,\n | \"role\"\n | \"instructions\"\n | \"name\"\n | \"description\"\n | \"templates\"\n | \"notes\"\n | \"execution\"\n | \"middlewares\"\n>;\n\n/**\n * RequirementAgent - A declarative AI agent with rule-based constraints\n *\n * The RequirementAgent provides predictable, controlled execution behavior across\n * different language models through rule-based constraints (Requirements).\n * Requirements can be configured as strict or flexible as necessary, adapting to\n * task requirements while ensuring consistent execution regardless of the underlying\n * model's reasoning or tool-calling capabilities.\n */\nexport class RequirementAgent extends BaseAgent<\n RequirementAgentRunInput,\n RequirementAgentOutput,\n RequirementAgentRunOptions\n> {\n public readonly emitter = Emitter.root.child<RequirementAgentCallbacks>({\n namespace: [\"agent\", \"requirement\"],\n creator: this,\n });\n\n protected readonly input: InternalRequirementAgentInput;\n\n protected runner: new (\n ...args: ConstructorParameters<typeof RequirementAgentRunner>\n ) => RequirementAgentRunner = RequirementAgentRunner;\n\n constructor(input: RequirementAgentInput) {\n super();\n this.input = {\n ...input,\n memory: input.memory || new UnconstrainedMemory(),\n tools: input.tools || [],\n requirements: input.requirements || [],\n saveIntermediateSteps: input.saveIntermediateSteps ?? true,\n finalAnswerAsTool: input.finalAnswerAsTool ?? true,\n toolCallChecker: input.toolCallChecker ?? true,\n };\n if (input.middlewares) {\n this.middlewares.push(...input.middlewares);\n }\n }\n\n static {\n this.register();\n }\n\n protected async _run(\n input: RequirementAgentRunInput,\n options: RequirementAgentRunOptions = {},\n run: GetRunContext<typeof this>,\n ): Promise<RequirementAgentOutput> {\n const execution: RequirementAgentExecutionConfig = {\n maxRetriesPerStep: 3,\n totalMaxRetries: 20,\n maxIterations: 20,\n ...this.input.execution,\n ...options.execution,\n };\n\n const toolCallChecker = this.createToolCallChecker();\n\n const runner = new this.runner(\n this.input.llm,\n execution,\n this.input.tools || [],\n this.input.requirements || [],\n input.expectedOutput || null,\n toolCallChecker,\n run,\n this.input.finalAnswerAsTool,\n this.templates,\n );\n\n // Process input messages\n const newMessages = this.processInput(input);\n await runner.addMessages([...this.memory.messages]);\n await runner.addMessages(newMessages);\n\n // Run the agent\n const finalState = await runner.run();\n\n // Update memory\n if (this.input.saveIntermediateSteps) {\n this.memory.reset();\n await this.memory.addMany(finalState.memory.messages);\n } else {\n await this.memory.addMany(newMessages);\n // Add last tool call pair\n const messages = finalState.memory.messages;\n const lastPair = messages.slice(-2);\n await this.memory.addMany(lastPair);\n }\n\n if (!finalState.answer) {\n throw new Error(\"Agent did not produce a final answer\");\n }\n\n return {\n result: finalState.answer,\n memory: finalState.memory,\n state: finalState,\n };\n }\n\n protected processInput(input: RequirementAgentRunInput): Message[] {\n if (!input.prompt) {\n return [];\n }\n\n const userMessage = new UserMessage(\n this.templates.task.render({\n prompt: input.prompt,\n context: input.context,\n expectedOutput: typeof input.expectedOutput === \"string\" ? input.expectedOutput : undefined,\n }),\n );\n\n return [userMessage];\n }\n\n protected createToolCallChecker(): ToolCallChecker {\n const config: ToolCallCheckerConfig = {};\n\n if (typeof this.input.toolCallChecker === \"object\") {\n Object.assign(config, this.input.toolCallChecker);\n }\n\n const checker = new ToolCallChecker(config);\n checker.enabled = this.input.toolCallChecker !== false;\n return checker;\n }\n\n get meta(): AgentMeta {\n const tools = this.input.tools || [];\n\n return {\n name: this.input.name ?? \"Requirement\",\n tools,\n description:\n this.input.description ??\n \"The RequirementAgent is a declarative AI agent implementation that provides predictable, \" +\n \"controlled execution behavior across different language models through rule-based constraints.\",\n ...(tools.length > 0 && {\n extraDescription: [\n `Tools that I can use to accomplish given task.`,\n ...tools.map((tool) => `Tool '${tool.name}': ${tool.description}.`),\n ].join(\"\\n\"),\n }),\n };\n }\n\n protected get templates(): RequirementAgentTemplates {\n const overrides = this.input.templates || {};\n const finalized = mapObj({\n system: RequirementAgentSystemPrompt,\n task: RequirementAgentTaskPrompt,\n toolError: RequirementAgentToolErrorPrompt,\n toolNoResult: RequirementAgentToolNoResultPrompt,\n } as RequirementAgentTemplates)((\n key,\n defaultTemplate: RequirementAgentTemplates[typeof key],\n ) => {\n const override = overrides[key] ?? defaultTemplate;\n if (override instanceof PromptTemplate) {\n return override;\n }\n return override(defaultTemplate) ?? defaultTemplate;\n });\n\n if (this.input.role || this.input.instructions || this.input.notes) {\n finalized.system.update({\n defaults: pickBy(\n {\n role: this.input.role,\n instructions: isEmptyish(this.input.instructions)\n ? undefined\n : castArray(this.input.instructions)\n .map((v) => `- ${v}`)\n .join(\"\\n\"),\n notes: isEmptyish(this.input.notes)\n ? undefined\n : castArray(this.input.notes)\n .map((v) => `- ${v}`)\n .join(\"\\n\"),\n },\n isDefined,\n ),\n });\n }\n\n return finalized;\n }\n\n createSnapshot() {\n return {\n ...super.createSnapshot(),\n input: shallowCopy(this.input),\n emitter: this.emitter,\n runnerClass: this.runner,\n };\n }\n\n set memory(memory: BaseMemory) {\n this.input.memory = memory;\n }\n\n get memory(): BaseMemory {\n return this.input.memory!;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../../src/agents/requirement/agent.ts"],"names":["RequirementAgent","BaseAgent","emitter","Emitter","root","child","namespace","creator","input","runner","RequirementAgentRunner","memory","UnconstrainedMemory","tools","requirements","saveIntermediateSteps","finalAnswerAsTool","toolCallChecker","middlewares","push","register","_run","options","run","execution","maxRetriesPerStep","totalMaxRetries","maxIterations","createToolCallChecker","llm","expectedOutput","templates","newMessages","processInput","addMessages","messages","finalState","reset","addMany","lastPair","slice","answer","Error","result","state","prompt","userMessage","UserMessage","task","render","context","undefined","config","Object","assign","checker","ToolCallChecker","enabled","meta","name","description","length","extraDescription","map","tool","join","overrides","finalized","mapObj","system","RequirementAgentSystemPrompt","RequirementAgentTaskPrompt","toolError","RequirementAgentToolErrorPrompt","toolNoResult","RequirementAgentToolNoResultPrompt","key","defaultTemplate","override","PromptTemplate","role","instructions","notes","update","defaults","pickBy","isEmptyish","castArray","v","isDefined","createSnapshot","shallowCopy"],"mappings":";;;;;;;;;;;;;;;AAqFO,MAAMA,yBAAyBC,SAAAA,CAAAA;EArFtC;;;EA0FkBC,OAAAA,GAAUC,OAA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UAAAA,IAAAA,EAAM,KAAKxE,KAAAA,CAAMwE,IAAAA;AACjBC,UAAAA,YAAAA,EAAcK,WAAW,IAAA,CAAK9E,KAAAA,CAAMyE,YAAY,CAAA,GAC5C9B,MAAAA,GACAoC,UAAU,IAAA,CAAK/E,KAAAA,CAAMyE,YAAY,CAAA,CAC9BlB,GAAAA,CAAI,CAACyB,CAAAA,KAAM,CAAA,EAAA,EAAKA,CAAAA,CAAAA,CAAG,CAAA,CACnBvB,KAAK,IAAA,CAAA;AACZiB,UAAAA,KAAAA,EAAOI,WAAW,IAAA,CAAK9E,KAAAA,CAAM0E,KAAK,CAAA,GAC9B/B,MAAAA,GACAoC,UAAU,IAAA,CAAK/E,KAAAA,CAAM0E,KAAK,CAAA,CACvBnB,GAAAA,CAAI,CAACyB,CAAAA,KAAM,CAAA,EAAA,EAAKA,CAAAA,CAAAA,CAAG,CAAA,CACnBvB,KAAK,IAAA;AACd,SAAA,EACAwB,SAAAA;OAEJ,CAAA;AACF;AAEA,IAAA,OAAOtB,SAAAA;AACT;EAEAuB,cAAAA,GAAiB;AACf,IAAA,OAAO;AACL,MAAA,GAAG,MAAMA,cAAAA,EAAAA;MACTlF,KAAAA,EAAOmF,WAAAA,CAAY,KAAKnF,KAAK,CAAA;AAC7BN,MAAAA,OAAAA,EAAS,IAAA,CAAKA,OAAAA;AACdO,MAAAA,MAAAA,EAAQ,IAAA,CAAKA;AACf,KAAA;AACF;AAEA,EAAA,IAAIE,OAAOA,MAAAA,EAAoB;AAC7B,IAAA,IAAA,CAAKH,MAAMG,MAAAA,GAASA,MAAAA;AACtB;AAEA,EAAA,IAAIA,MAAAA,GAAqB;AACvB,IAAA,OAAO,KAAKH,KAAAA,CAAMG,MAAAA;AACpB;AACF","file":"agent.js","sourcesContent":["/**\n * Copyright 2025 © BeeAI a Series of LF Projects, LLC\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { BaseAgent } from \"@/agents/base.js\";\nimport { AnyTool } from \"@/tools/base.js\";\nimport { BaseMemory } from \"@/memory/base.js\";\nimport { AgentMeta } from \"@/agents/types.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport { ChatModel } from \"@/backend/chat.js\";\nimport type { GetRunContext, MiddlewareType } from \"@/context.js\";\nimport { UnconstrainedMemory } from \"@/memory/unconstrainedMemory.js\";\nimport { Message, UserMessage } from \"@/backend/message.js\";\nimport { shallowCopy } from \"@/serializer/utils.js\";\nimport { mapObj } from \"@/internals/helpers/object.js\";\nimport { PromptTemplate } from \"@/template.js\";\nimport {\n RequirementAgentCallbacks,\n RequirementAgentExecutionConfig,\n RequirementAgentOutput,\n RequirementAgentRunInput,\n RequirementAgentRunOptions,\n RequirementAgentTemplates,\n} from \"./types.js\";\nimport {\n RequirementAgentSystemPrompt,\n RequirementAgentTaskPrompt,\n RequirementAgentToolErrorPrompt,\n RequirementAgentToolNoResultPrompt,\n} from \"./prompts.js\";\nimport { Requirement } from \"./requirements/requirement.js\";\nimport { RequirementAgentRunner } from \"./runner.js\";\nimport { ToolCallChecker, ToolCallCheckerConfig } from \"./utils/toolCallChecker.js\";\nimport { isDefined, isEmptyish, pickBy } from \"remeda\";\nimport { castArray } from \"@/internals/helpers/array.js\";\nimport type { RequiredExcept } from \"@/internals/types.js\";\n\nexport type RequirementAgentTemplateFactory<K extends keyof RequirementAgentTemplates> = (\n template: RequirementAgentTemplates[K],\n) => RequirementAgentTemplates[K];\n\nexport interface RequirementAgentInput {\n llm: ChatModel;\n memory?: BaseMemory;\n tools?: AnyTool[];\n requirements?: Requirement[];\n name?: string;\n description?: string;\n role?: string;\n instructions?: string | string[];\n notes?: string | string[];\n toolCallChecker?: boolean | ToolCallCheckerConfig;\n finalAnswerAsTool?: boolean;\n saveIntermediateSteps?: boolean;\n execution?: RequirementAgentExecutionConfig;\n templates?: Partial<{\n [K in keyof RequirementAgentTemplates]:\n | RequirementAgentTemplates[K]\n | RequirementAgentTemplateFactory<K>;\n }>;\n middlewares?: MiddlewareType<RequirementAgent>[];\n}\n\ntype InternalRequirementAgentInput = RequiredExcept<\n RequirementAgentInput,\n | \"role\"\n | \"instructions\"\n | \"name\"\n | \"description\"\n | \"templates\"\n | \"notes\"\n | \"execution\"\n | \"middlewares\"\n>;\n\n/**\n * RequirementAgent - A declarative AI agent with rule-based constraints\n *\n * The RequirementAgent provides predictable, controlled execution behavior across\n * different language models through rule-based constraints (Requirements).\n * Requirements can be configured as strict or flexible as necessary, adapting to\n * task requirements while ensuring consistent execution regardless of the underlying\n * model's reasoning or tool-calling capabilities.\n */\nexport class RequirementAgent extends BaseAgent<\n RequirementAgentRunInput,\n RequirementAgentOutput,\n RequirementAgentRunOptions\n> {\n public readonly emitter = Emitter.root.child<RequirementAgentCallbacks>({\n namespace: [\"agent\", \"requirement\"],\n creator: this,\n });\n\n protected readonly input: InternalRequirementAgentInput;\n\n protected runner: new (\n ...args: ConstructorParameters<typeof RequirementAgentRunner>\n ) => RequirementAgentRunner = RequirementAgentRunner;\n\n constructor(input: RequirementAgentInput) {\n super();\n this.input = {\n ...input,\n memory: input.memory || new UnconstrainedMemory(),\n tools: input.tools || [],\n requirements: input.requirements || [],\n saveIntermediateSteps: input.saveIntermediateSteps ?? true,\n finalAnswerAsTool: input.finalAnswerAsTool ?? true,\n toolCallChecker: input.toolCallChecker ?? true,\n };\n if (input.middlewares) {\n this.middlewares.push(...input.middlewares);\n }\n }\n\n static {\n this.register();\n }\n\n protected async _run(\n input: RequirementAgentRunInput,\n options: RequirementAgentRunOptions = {},\n run: GetRunContext<typeof this>,\n ): Promise<RequirementAgentOutput> {\n const execution: RequirementAgentExecutionConfig = {\n maxRetriesPerStep: 3,\n totalMaxRetries: 20,\n maxIterations: 20,\n ...this.input.execution,\n ...options.execution,\n };\n\n const toolCallChecker = this.createToolCallChecker();\n\n const runner = new this.runner(\n this.input.llm,\n execution,\n this.input.tools || [],\n this.input.requirements || [],\n input.expectedOutput || null,\n toolCallChecker,\n run,\n this.input.finalAnswerAsTool,\n this.templates,\n );\n\n // Process input messages\n const newMessages = this.processInput(input);\n await runner.addMessages([...this.memory.messages]);\n await runner.addMessages(newMessages);\n\n // Run the agent\n const finalState = await runner.run();\n\n // Update memory\n if (this.input.saveIntermediateSteps) {\n this.memory.reset();\n await this.memory.addMany(finalState.memory.messages);\n } else {\n await this.memory.addMany(newMessages);\n // Add last tool call pair\n const messages = finalState.memory.messages;\n const lastPair = messages.slice(-2);\n await this.memory.addMany(lastPair);\n }\n\n if (!finalState.answer) {\n throw new Error(\"Agent did not produce a final answer\");\n }\n\n return {\n result: finalState.answer,\n memory: finalState.memory,\n state: finalState,\n };\n }\n\n protected processInput(input: RequirementAgentRunInput): Message[] {\n if (!input.prompt) {\n return [];\n }\n\n const userMessage = new UserMessage(\n this.templates.task.render({\n prompt: input.prompt,\n context: input.context,\n expectedOutput: typeof input.expectedOutput === \"string\" ? input.expectedOutput : undefined,\n }),\n );\n\n return [userMessage];\n }\n\n protected createToolCallChecker(): ToolCallChecker {\n const config: ToolCallCheckerConfig = {};\n\n if (typeof this.input.toolCallChecker === \"object\") {\n Object.assign(config, this.input.toolCallChecker);\n }\n\n const checker = new ToolCallChecker(config);\n checker.enabled = this.input.toolCallChecker !== false;\n return checker;\n }\n\n get meta(): AgentMeta {\n const tools = this.input.tools || [];\n\n return {\n name: this.input.name ?? \"Requirement\",\n tools,\n description:\n this.input.description ??\n \"The RequirementAgent is a declarative AI agent implementation that provides predictable, \" +\n \"controlled execution behavior across different language models through rule-based constraints.\",\n ...(tools.length > 0 && {\n extraDescription: [\n `Tools that I can use to accomplish given task.`,\n ...tools.map((tool) => `Tool '${tool.name}': ${tool.description}.`),\n ].join(\"\\n\"),\n }),\n };\n }\n\n protected get templates(): RequirementAgentTemplates {\n const overrides = this.input.templates || {};\n const finalized = mapObj({\n system: RequirementAgentSystemPrompt,\n task: RequirementAgentTaskPrompt,\n toolError: RequirementAgentToolErrorPrompt,\n toolNoResult: RequirementAgentToolNoResultPrompt,\n } as RequirementAgentTemplates)((\n key,\n defaultTemplate: RequirementAgentTemplates[typeof key],\n ) => {\n const override = overrides[key] ?? defaultTemplate;\n if (override instanceof PromptTemplate) {\n return override;\n }\n return override(defaultTemplate) ?? defaultTemplate;\n });\n\n if (this.input.role || this.input.instructions || this.input.notes) {\n finalized.system.update({\n defaults: pickBy(\n {\n role: this.input.role,\n instructions: isEmptyish(this.input.instructions)\n ? undefined\n : castArray(this.input.instructions)\n .map((v) => `- ${v}`)\n .join(\"\\n\"),\n notes: isEmptyish(this.input.notes)\n ? undefined\n : castArray(this.input.notes)\n .map((v) => `- ${v}`)\n .join(\"\\n\"),\n },\n isDefined,\n ),\n });\n }\n\n return finalized;\n }\n\n createSnapshot() {\n return {\n ...super.createSnapshot(),\n input: shallowCopy(this.input),\n emitter: this.emitter,\n runner: this.runner,\n };\n }\n\n set memory(memory: BaseMemory) {\n this.input.memory = memory;\n }\n\n get memory(): BaseMemory {\n return this.input.memory!;\n }\n}\n"]}
|