beeai-framework 0.1.14 → 0.1.16
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/{agents/experimental/remote → adapters/acp/agents}/agent.cjs +9 -6
- package/dist/adapters/acp/agents/agent.cjs.map +1 -0
- package/dist/{agents/experimental/remote → adapters/acp/agents}/agent.d.cts +12 -31
- package/dist/{agents/experimental/remote → adapters/acp/agents}/agent.d.ts +12 -31
- package/dist/{agents/experimental/remote → adapters/acp/agents}/agent.js +9 -6
- package/dist/adapters/acp/agents/agent.js.map +1 -0
- package/dist/adapters/acp/agents/events.cjs +4 -0
- package/dist/adapters/acp/agents/events.cjs.map +1 -0
- package/dist/adapters/acp/agents/events.d.cts +34 -0
- package/dist/adapters/acp/agents/events.d.ts +34 -0
- package/dist/adapters/acp/agents/events.js +3 -0
- package/dist/adapters/acp/agents/events.js.map +1 -0
- package/dist/adapters/acp/agents/types.cjs +4 -0
- package/dist/adapters/acp/agents/types.cjs.map +1 -0
- package/dist/adapters/acp/agents/types.d.cts +38 -0
- package/dist/adapters/acp/agents/types.d.ts +38 -0
- package/dist/adapters/acp/agents/types.js +3 -0
- package/dist/adapters/acp/agents/types.js.map +1 -0
- 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/beeai_platform/agents/agent.cjs +61 -0
- package/dist/adapters/beeai_platform/agents/agent.cjs.map +1 -0
- package/dist/adapters/beeai_platform/agents/agent.d.cts +49 -0
- package/dist/adapters/beeai_platform/agents/agent.d.ts +49 -0
- package/dist/adapters/beeai_platform/agents/agent.js +59 -0
- package/dist/adapters/beeai_platform/agents/agent.js.map +1 -0
- package/dist/adapters/beeai_platform/agents/events.cjs +4 -0
- package/dist/adapters/beeai_platform/agents/events.cjs.map +1 -0
- package/dist/adapters/beeai_platform/agents/events.d.cts +34 -0
- package/dist/adapters/beeai_platform/agents/events.d.ts +34 -0
- package/dist/adapters/beeai_platform/agents/events.js +3 -0
- package/dist/adapters/beeai_platform/agents/events.js.map +1 -0
- package/dist/adapters/beeai_platform/agents/types.cjs +4 -0
- package/dist/adapters/beeai_platform/agents/types.cjs.map +1 -0
- package/dist/adapters/beeai_platform/agents/types.d.cts +38 -0
- package/dist/adapters/beeai_platform/agents/types.d.ts +38 -0
- package/dist/adapters/beeai_platform/agents/types.js +3 -0
- package/dist/adapters/beeai_platform/agents/types.js.map +1 -0
- 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/mcp/serve/http_server.cjs +163 -0
- package/dist/adapters/mcp/serve/http_server.cjs.map +1 -0
- package/dist/adapters/mcp/serve/http_server.d.cts +21 -0
- package/dist/adapters/mcp/serve/http_server.d.ts +21 -0
- package/dist/adapters/mcp/serve/http_server.js +157 -0
- package/dist/adapters/mcp/serve/http_server.js.map +1 -0
- package/dist/adapters/mcp/serve/in_memory_store.cjs +69 -0
- package/dist/adapters/mcp/serve/in_memory_store.cjs.map +1 -0
- package/dist/adapters/mcp/serve/in_memory_store.d.cts +49 -0
- package/dist/adapters/mcp/serve/in_memory_store.d.ts +49 -0
- package/dist/adapters/mcp/serve/in_memory_store.js +67 -0
- package/dist/adapters/mcp/serve/in_memory_store.js.map +1 -0
- package/dist/adapters/mcp/serve/server.cjs +109 -0
- package/dist/adapters/mcp/serve/server.cjs.map +1 -0
- package/dist/adapters/mcp/serve/server.d.cts +70 -0
- package/dist/adapters/mcp/serve/server.d.ts +70 -0
- package/dist/adapters/mcp/serve/server.js +106 -0
- package/dist/adapters/mcp/serve/server.js.map +1 -0
- package/dist/adapters/ollama/backend/chat.d.cts +2 -2
- package/dist/adapters/ollama/backend/chat.d.ts +2 -2
- 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.d.cts +2 -2
- package/dist/adapters/vercel/backend/chat.d.ts +2 -2
- package/dist/adapters/vercel/backend/embedding.d.cts +2 -2
- package/dist/adapters/vercel/backend/embedding.d.ts +2 -2
- 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/embedding.d.cts +2 -2
- package/dist/adapters/watsonx/backend/embedding.d.ts +2 -2
- package/dist/{agent-B60_2RXt.d.cts → agent-Ca5UE2P1.d.cts} +3 -3
- package/dist/{agent-BgLMNZbc.d.ts → agent-CgsoqVL5.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 +5 -5
- package/dist/agents/react/runners/default/runner.d.ts +5 -5
- 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/toolCalling/agent.cjs +1 -1
- package/dist/agents/toolCalling/agent.cjs.map +1 -1
- package/dist/agents/toolCalling/agent.d.cts +3 -3
- package/dist/agents/toolCalling/agent.d.ts +3 -3
- package/dist/agents/toolCalling/agent.js +1 -1
- 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.d.cts +2 -2
- package/dist/backend/chat.d.ts +2 -2
- package/dist/backend/core.d.cts +2 -2
- package/dist/backend/core.d.ts +2 -2
- package/dist/backend/embedding.d.cts +2 -2
- package/dist/backend/embedding.d.ts +2 -2
- package/dist/backend/utils.d.cts +2 -2
- package/dist/backend/utils.d.ts +2 -2
- package/dist/{base-ZnwDK6ZB.d.ts → base-BOCDDBvG.d.ts} +1 -1
- package/dist/{base-BPsHNV2O.d.cts → base-szR2Izbt.d.cts} +1 -1
- package/dist/{chat-diSK3Sui.d.ts → chat-BdN8hGWn.d.ts} +1 -1
- package/dist/{chat-BvyMdWFo.d.cts → chat-DvMzAHj6.d.cts} +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.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/parsers/linePrefix.d.cts +1 -1
- package/dist/parsers/linePrefix.d.ts +1 -1
- package/dist/serve/server.cjs +52 -0
- package/dist/serve/server.cjs.map +1 -0
- package/dist/serve/server.d.cts +31 -0
- package/dist/serve/server.d.ts +31 -0
- package/dist/serve/server.js +50 -0
- package/dist/serve/server.js.map +1 -0
- 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/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/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.d.cts +40 -40
- package/dist/workflows/agent.d.ts +40 -40
- package/dist/workflows/workflow.d.cts +1 -1
- package/dist/workflows/workflow.d.ts +1 -1
- package/package.json +11 -14
- package/dist/agents/experimental/remote/agent.cjs.map +0 -1
- package/dist/agents/experimental/remote/agent.js.map +0 -1
- package/dist/{emitter-DiGmS_5O.d.ts → emitter-C3dO-s2P.d.ts} +1 -1
- package/dist/{emitter-BTr99H7I.d.cts → emitter-D5Mu0EEH.d.cts} +1 -1
|
@@ -57,12 +57,12 @@ declare const GraniteReActAgentSystemPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
57
57
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
58
58
|
createdAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
59
59
|
}, "strip", zod.ZodTypeAny, {
|
|
60
|
-
instructions: string;
|
|
61
60
|
tools: zod.objectOutputType<{
|
|
62
61
|
name: zod.ZodString;
|
|
63
62
|
description: zod.ZodString;
|
|
64
63
|
schema: zod.ZodString;
|
|
65
64
|
}, zod.ZodTypeAny, "passthrough">[];
|
|
65
|
+
instructions: string;
|
|
66
66
|
createdAt?: string | null | undefined;
|
|
67
67
|
}, {
|
|
68
68
|
tools: zod.objectInputType<{
|
|
@@ -57,12 +57,12 @@ declare const GraniteReActAgentSystemPrompt: PromptTemplate<zod.ZodObject<{
|
|
|
57
57
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
58
58
|
createdAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
59
59
|
}, "strip", zod.ZodTypeAny, {
|
|
60
|
-
instructions: string;
|
|
61
60
|
tools: zod.objectOutputType<{
|
|
62
61
|
name: zod.ZodString;
|
|
63
62
|
description: zod.ZodString;
|
|
64
63
|
schema: zod.ZodString;
|
|
65
64
|
}, zod.ZodTypeAny, "passthrough">[];
|
|
65
|
+
instructions: string;
|
|
66
66
|
createdAt?: string | null | undefined;
|
|
67
67
|
}, {
|
|
68
68
|
tools: zod.objectInputType<{
|
|
@@ -4,9 +4,9 @@ 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 { R as ReActAgentInput, a as ReActAgent } from '../../../../agent-
|
|
7
|
+
import { R as ReActAgentInput, a as ReActAgent } from '../../../../agent-Ca5UE2P1.cjs';
|
|
8
8
|
import { GetRunContext } from '../../../../context.cjs';
|
|
9
|
-
import '../../../../emitter-
|
|
9
|
+
import '../../../../emitter-D5Mu0EEH.cjs';
|
|
10
10
|
import '../../../../internals/types.cjs';
|
|
11
11
|
import '../../../../internals/helpers/guards.cjs';
|
|
12
12
|
import '../../../../internals/serializable.cjs';
|
|
@@ -24,8 +24,8 @@ import '../../../../internals/helpers/promise.cjs';
|
|
|
24
24
|
import '../../../../backend/message.cjs';
|
|
25
25
|
import 'ai';
|
|
26
26
|
import '../../../../memory/base.cjs';
|
|
27
|
-
import '../../../../base-
|
|
28
|
-
import '../../../../chat-
|
|
27
|
+
import '../../../../base-szR2Izbt.cjs';
|
|
28
|
+
import '../../../../chat-DvMzAHj6.cjs';
|
|
29
29
|
import '../../../../backend/constants.cjs';
|
|
30
30
|
import '../../../../logger/logger.cjs';
|
|
31
31
|
import 'pino';
|
|
@@ -52,12 +52,12 @@ declare class GraniteRunner extends DefaultRunner {
|
|
|
52
52
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
53
53
|
createdAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
54
54
|
}, "strip", zod.ZodTypeAny, {
|
|
55
|
-
instructions: string;
|
|
56
55
|
tools: zod.objectOutputType<{
|
|
57
56
|
name: zod.ZodString;
|
|
58
57
|
description: zod.ZodString;
|
|
59
58
|
schema: zod.ZodString;
|
|
60
59
|
}, zod.ZodTypeAny, "passthrough">[];
|
|
60
|
+
instructions: string;
|
|
61
61
|
createdAt?: string | null | undefined;
|
|
62
62
|
}, {
|
|
63
63
|
tools: zod.objectInputType<{
|
|
@@ -4,9 +4,9 @@ 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 { R as ReActAgentInput, a as ReActAgent } from '../../../../agent-
|
|
7
|
+
import { R as ReActAgentInput, a as ReActAgent } from '../../../../agent-CgsoqVL5.js';
|
|
8
8
|
import { GetRunContext } from '../../../../context.js';
|
|
9
|
-
import '../../../../emitter-
|
|
9
|
+
import '../../../../emitter-C3dO-s2P.js';
|
|
10
10
|
import '../../../../internals/types.js';
|
|
11
11
|
import '../../../../internals/helpers/guards.js';
|
|
12
12
|
import '../../../../internals/serializable.js';
|
|
@@ -24,8 +24,8 @@ import '../../../../internals/helpers/promise.js';
|
|
|
24
24
|
import '../../../../backend/message.js';
|
|
25
25
|
import 'ai';
|
|
26
26
|
import '../../../../memory/base.js';
|
|
27
|
-
import '../../../../base-
|
|
28
|
-
import '../../../../chat-
|
|
27
|
+
import '../../../../base-BOCDDBvG.js';
|
|
28
|
+
import '../../../../chat-BdN8hGWn.js';
|
|
29
29
|
import '../../../../backend/constants.js';
|
|
30
30
|
import '../../../../logger/logger.js';
|
|
31
31
|
import 'pino';
|
|
@@ -52,12 +52,12 @@ declare class GraniteRunner extends DefaultRunner {
|
|
|
52
52
|
}, zod.ZodTypeAny, "passthrough">>, "many">;
|
|
53
53
|
createdAt: zod.ZodOptional<zod.ZodNullable<zod.ZodString>>;
|
|
54
54
|
}, "strip", zod.ZodTypeAny, {
|
|
55
|
-
instructions: string;
|
|
56
55
|
tools: zod.objectOutputType<{
|
|
57
56
|
name: zod.ZodString;
|
|
58
57
|
description: zod.ZodString;
|
|
59
58
|
schema: zod.ZodString;
|
|
60
59
|
}, zod.ZodTypeAny, "passthrough">[];
|
|
60
|
+
instructions: string;
|
|
61
61
|
createdAt?: string | null | undefined;
|
|
62
62
|
}, {
|
|
63
63
|
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-D5Mu0EEH.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-DvMzAHj6.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-C3dO-s2P.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-BdN8hGWn.js';
|
|
10
10
|
import '../../errors.js';
|
|
11
11
|
import '../../internals/helpers/guards.js';
|
|
12
12
|
import '../../internals/serializable.js';
|
|
@@ -81,7 +81,7 @@ class ToolCallingAgent extends base_cjs.BaseAgent {
|
|
|
81
81
|
description: "Sends the final answer to the user",
|
|
82
82
|
inputSchema: finalAnswerToolSchema,
|
|
83
83
|
handler: /* @__PURE__ */ __name(async (input2) => {
|
|
84
|
-
const result = usePlainResponse ? input2.response : JSON.stringify(input2
|
|
84
|
+
const result = usePlainResponse ? input2.response : JSON.stringify(input2);
|
|
85
85
|
state.result = new message_cjs.AssistantMessage(result);
|
|
86
86
|
return new base_cjs$1.StringToolOutput("Message has been sent");
|
|
87
87
|
}, "handler")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["agent.ts"],"names":["ToolCallingAgent","BaseAgent","emitter","constructor","input","Emitter","root","child","namespace","creator","saveIntermediateSteps","register","_run","options","run","tempMessageKey","execution","totalMaxRetries","omitUndefined","state","memory","UnconstrainedMemory","result","undefined","iteration","add","SystemMessage","templates","system","render","role","instructions","addMany","messages","prompt","userMessage","UserMessage","task","context","expectedOutput","isString","globalRetriesCounter","RetryCounter","AgentError","usePlainResponse","ZodSchema","finalAnswerToolSchema","z","object","response","string","describe","String","finalAnswerTool","DynamicTool","name","description","inputSchema","handler","JSON","stringify","AssistantMessage","StringToolOutput","tools","forceFinalAnswer","Infinity","emit","llm","create","slice","toolChoice","length","stream","toolCallMessages","getToolCalls","toolCall","tool","find","toolName","toolInput","args","toolResponse","toolCallMsg","ToolMessage","type","toolCallId","getTextContent","isError","e","ToolError","use","explain","textMessages","getTextMessages","isEmpty","deleteMany","filter","msg","meta","push","reset","extraDescription","map","join","overrides","defaultTemplates","ToolCallingAgentSystemPrompt","ToolCallingAgentTaskPrompt","mapObj","key","defaultTemplate","override","PromptTemplate","createSnapshot","shallowCopy","enumerable"],"mappings":";;;;;;;;;;;;;;;;;;AAcC,SAAA,YAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GAAA,EAAA,IAAA,EAAA;;;;;;AAAA,MAAA,CAAA,YAAA,EAAA,cAAA,CAAA;;;;;AAkDM,MAAMA,yBAAyBC,kBAAAA,CAAAA;EAhEtC;;;;AAqEkBC,EAAAA,OAAAA;AAKhBC,EAAAA,WAAAA,CAA4BC,KAA8B,EAAA;AACxD,IAAK,KAAA,EAAA,EAAA,KADqBA,KAAAA,GAAAA,KAAAA,EAAAA,KALZF,OAAUG,GAAAA,mBAAAA,CAAQC,KAAKC,KAAiC,CAAA;MACtEC,SAAW,EAAA;AAAC,QAAA,OAAA;AAAS,QAAA;;MACrBC,OAAS,EAAA;KACX,CAAA;AAIE,IAAA,IAAA,CAAKL,KAAMM,CAAAA,qBAAAA,GAAwB,IAAKN,CAAAA,KAAAA,CAAMM,qBAAyB,IAAA,IAAA;AACzE;EAEA;AACE,IAAA,IAAA,CAAKC,QAAQ,EAAA;AACf;AAEA,EAAA,MAAgBC,IACdR,CAAAA,KAAAA,EACAS,OAAsC,GAAA,IACtCC,GACoC,EAAA;AACpC,IAAA,MAAMC,cAAiB,GAAA,aAAA;AACvB,IAAA,MAAMC,SAAY,GAAA;MAEhBC,eAAiB,EAAA,EAAA;MAEjB,GAAGC,wBAAc,CAAA,IAAA,CAAKd,KAAMY,CAAAA,SAAAA,IAAa,EAAC,CAAA;AAC1C,MAAA,GAAGE,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B,CAAAA,WAAW,CAAG,CAAA,CAAA;AAClE+C,SAAAA,CAAAA,IAAAA,CAAK,IAAA;AACT;AACF,KAAA;AACF;AAEA,EAAA,IACc5E,SAAuC,GAAA;AACnD,IAAA,MAAM6E,SAAY,GAAA,IAAA,CAAKpG,KAAMuB,CAAAA,SAAAA,IAAa,EAAC;AAC3C,IAAA,MAAM8E,gBAA8C,GAAA;MAClD7E,MAAQ8E,EAAAA,wCAAAA;MACRrE,IAAMsE,EAAAA;AACR,KAAA;AAEA,IAAA,OAAOC,iBAAOH,CAAAA,gBAAAA,CACZ,CAAA,CAACI,KAAKC,eAAAA,KAAAA;AACJ,MAAMC,MAAAA,QAAAA,GAAWP,SAAUK,CAAAA,GAAAA,CAAQC,IAAAA,eAAAA;AACnC,MAAA,IAAIC,oBAAoBC,2BAAgB,EAAA;AACtC,QAAOD,OAAAA,QAAAA;AACT;AACA,MAAOA,OAAAA,QAAAA,CAASD,eAAAA,CAAoBA,IAAAA,eAAAA;KACtC,CAAA;AAEJ;EAEAG,cAAiB,GAAA;AACf,IAAO,OAAA;AACL,MAAA,GAAG,MAAMA,cAAAA,EAAAA;MACT7G,KAAO8G,EAAAA,qBAAAA,CAAY,KAAK9G,KAAK,CAAA;AAC7BF,MAAAA,OAAAA,EAAS,IAAKA,CAAAA;AAChB,KAAA;AACF;AAEA,EAAA,IAAIkB,OAAOA,MAAoB,EAAA;AAC7B,IAAA,IAAA,CAAKhB,MAAMgB,MAASA,GAAAA,MAAAA;AACtB;AAEA,EAAA,IAAIA,MAAS,GAAA;AACX,IAAA,OAAO,KAAKhB,KAAMgB,CAAAA,MAAAA;AACpB;AACF;;;IAlCW+F,UAAY,EAAA","file":"agent.cjs","sourcesContent":["/**\n * Copyright 2025 © BeeAI a Series of LF Projects, LLC\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 { AgentError, BaseAgent } from \"@/agents/base.js\";\nimport { AnyTool, DynamicTool, StringToolOutput, ToolError, ToolOutput } from \"@/tools/base.js\";\nimport { BaseMemory } from \"@/memory/base.js\";\nimport { AgentMeta } from \"@/agents/types.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport type {\n ToolCallingAgentExecutionConfig,\n ToolCallingAgentTemplates,\n ToolCallingAgentCallbacks,\n ToolCallingAgentRunInput,\n ToolCallingAgentRunOptions,\n ToolCallingAgentRunOutput,\n ToolCallingAgentRunState,\n} from \"@/agents/toolCalling/types.js\";\nimport { GetRunContext } from \"@/context.js\";\nimport { ChatModel } from \"@/backend/chat.js\";\nimport { shallowCopy } from \"@/serializer/utils.js\";\nimport { UnconstrainedMemory } from \"@/memory/unconstrainedMemory.js\";\nimport { AssistantMessage, SystemMessage, ToolMessage, UserMessage } from \"@/backend/message.js\";\nimport { isEmpty, isString } from \"remeda\";\nimport { RetryCounter } from \"@/internals/helpers/counter.js\";\nimport { mapObj, omitUndefined } from \"@/internals/helpers/object.js\";\nimport { Cache } from \"@/cache/decoratorCache.js\";\nimport { PromptTemplate } from \"@/template.js\";\nimport {\n ToolCallingAgentSystemPrompt,\n ToolCallingAgentTaskPrompt,\n} from \"@/agents/toolCalling/prompts.js\";\nimport { z, ZodSchema } from \"zod\";\n\nexport type ToolCallingAgentTemplateFactory<K extends keyof ToolCallingAgentTemplates> = (\n template: ToolCallingAgentTemplates[K],\n) => ToolCallingAgentTemplates[K];\n\nexport interface ToolCallingAgentInput {\n llm: ChatModel;\n memory: BaseMemory;\n tools: AnyTool[];\n meta?: Omit<AgentMeta, \"tools\">;\n templates?: Partial<{\n [K in keyof ToolCallingAgentTemplates]:\n | ToolCallingAgentTemplates[K]\n | ToolCallingAgentTemplateFactory<K>;\n }>;\n execution?: ToolCallingAgentExecutionConfig;\n saveIntermediateSteps?: boolean;\n}\n\nexport class ToolCallingAgent extends BaseAgent<\n ToolCallingAgentRunInput,\n ToolCallingAgentRunOutput,\n ToolCallingAgentRunOptions\n> {\n public readonly emitter = Emitter.root.child<ToolCallingAgentCallbacks>({\n namespace: [\"agent\", \"toolCalling\"],\n creator: this,\n });\n\n constructor(public readonly input: ToolCallingAgentInput) {\n super();\n this.input.saveIntermediateSteps = this.input.saveIntermediateSteps ?? true;\n }\n\n static {\n this.register();\n }\n\n protected async _run(\n input: ToolCallingAgentRunInput,\n options: ToolCallingAgentRunOptions = {},\n run: GetRunContext<typeof this>,\n ): Promise<ToolCallingAgentRunOutput> {\n const tempMessageKey = \"tempMessage\" as const;\n const execution = {\n maxRetriesPerStep: 3,\n totalMaxRetries: 20,\n maxIterations: 10,\n ...omitUndefined(this.input.execution ?? {}),\n ...omitUndefined(options.execution ?? {}),\n };\n\n const state: ToolCallingAgentRunState = {\n memory: new UnconstrainedMemory(),\n result: undefined,\n iteration: 0,\n };\n await state.memory.add(\n new SystemMessage(\n this.templates.system.render({\n role: undefined,\n instructions: undefined,\n }),\n ),\n );\n await state.memory.addMany(this.memory.messages);\n\n if (input.prompt) {\n const userMessage = new UserMessage(\n this.templates.task.render({\n prompt: input.prompt,\n context: input.context,\n expectedOutput: isString(input.expectedOutput) ? input.expectedOutput : undefined,\n }),\n );\n await state.memory.add(userMessage);\n }\n\n const globalRetriesCounter = new RetryCounter(execution.totalMaxRetries || 1, AgentError);\n\n const usePlainResponse = !input.expectedOutput || !(input.expectedOutput instanceof ZodSchema);\n const finalAnswerToolSchema = usePlainResponse\n ? z.object({\n response: z.string().describe(String(input.expectedOutput ?? \"\")),\n })\n : (input.expectedOutput as ZodSchema);\n\n const finalAnswerTool = new DynamicTool({\n name: \"final_answer\",\n description: \"Sends the final answer to the user\",\n inputSchema: finalAnswerToolSchema,\n handler: async (input) => {\n const result = usePlainResponse ? input.response : JSON.stringify(input.response);\n state.result = new AssistantMessage(result);\n return new StringToolOutput(\"Message has been sent\");\n },\n });\n\n const tools = [...this.input.tools, finalAnswerTool];\n let forceFinalAnswer = false;\n\n while (!state.result) {\n state.iteration++;\n if (state.iteration > (execution.totalMaxRetries ?? Infinity)) {\n throw new AgentError(\n `Agent was not able to resolve the task in ${state.iteration} iterations.`,\n );\n }\n\n await run.emitter.emit(\"start\", { state });\n const response = await this.input.llm.create({\n messages: state.memory.messages.slice(),\n tools,\n toolChoice: forceFinalAnswer ? finalAnswerTool : tools.length > 1 ? \"required\" : tools[0],\n stream: false,\n });\n await state.memory.addMany(response.messages);\n\n const toolCallMessages = response.getToolCalls();\n for (const toolCall of toolCallMessages) {\n try {\n const tool = tools.find((tool) => tool.name === toolCall.toolName);\n if (!tool) {\n throw new AgentError(`Tool ${toolCall.toolName} does not exist!`);\n }\n\n const toolInput: any = toolCall.args;\n const toolResponse: ToolOutput = await tool.run(toolInput).context({\n state,\n toolCallMsg: toolCall,\n });\n await state.memory.add(\n new ToolMessage({\n type: \"tool-result\",\n toolCallId: toolCall.toolCallId,\n toolName: toolCall.toolName,\n result: toolResponse.getTextContent(),\n isError: false,\n }),\n );\n } catch (e) {\n if (e instanceof ToolError) {\n globalRetriesCounter.use(e);\n await state.memory.add(\n new ToolMessage({\n type: \"tool-result\",\n toolCallId: toolCall.toolCallId,\n toolName: toolCall.toolName,\n result: e.explain(),\n isError: true,\n }),\n );\n } else {\n throw e;\n }\n }\n }\n\n // handle empty messages for some models\n const textMessages = response.getTextMessages();\n if (isEmpty(toolCallMessages) && isEmpty(textMessages)) {\n await state.memory.add(new AssistantMessage(\"\\n\", { [tempMessageKey]: true }));\n } else {\n await state.memory.deleteMany(\n state.memory.messages.filter((msg) => msg.meta[tempMessageKey]),\n );\n }\n\n // Fallback for providers that do not support structured outputs\n if (!isEmpty(textMessages) && isEmpty(toolCallMessages)) {\n forceFinalAnswer = true;\n tools.length = 0;\n tools.push(finalAnswerTool);\n }\n\n await run.emitter.emit(\"success\", { state });\n }\n\n if (this.input.saveIntermediateSteps) {\n this.memory.reset();\n await this.memory.addMany(state.memory.messages.slice(1));\n } else {\n await this.memory.addMany(state.memory.messages.slice(-2));\n }\n return { memory: state.memory, result: state.result };\n }\n\n get meta(): AgentMeta {\n const tools = this.input.tools.slice();\n\n if (this.input.meta) {\n return { ...this.input.meta, tools };\n }\n\n return {\n name: \"ToolCalling\",\n tools,\n description: \"ToolCallingAgent that uses tools to accomplish the task.\",\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 @Cache({ enumerable: false })\n protected get templates(): ToolCallingAgentTemplates {\n const overrides = this.input.templates ?? {};\n const defaultTemplates: ToolCallingAgentTemplates = {\n system: ToolCallingAgentSystemPrompt,\n task: ToolCallingAgentTaskPrompt,\n } as const;\n\n return mapObj(defaultTemplates)(\n (key, defaultTemplate: ToolCallingAgentTemplates[typeof key]) => {\n const override = overrides[key] ?? defaultTemplate;\n if (override instanceof PromptTemplate) {\n return override;\n }\n return override(defaultTemplate) ?? defaultTemplate;\n },\n );\n }\n\n createSnapshot() {\n return {\n ...super.createSnapshot(),\n input: shallowCopy(this.input),\n emitter: this.emitter,\n };\n }\n\n set memory(memory: BaseMemory) {\n this.input.memory = memory;\n }\n\n get memory() {\n return this.input.memory;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["agent.ts"],"names":["ToolCallingAgent","BaseAgent","emitter","constructor","input","Emitter","root","child","namespace","creator","saveIntermediateSteps","register","_run","options","run","tempMessageKey","execution","totalMaxRetries","omitUndefined","state","memory","UnconstrainedMemory","result","undefined","iteration","add","SystemMessage","templates","system","render","role","instructions","addMany","messages","prompt","userMessage","UserMessage","task","context","expectedOutput","isString","globalRetriesCounter","RetryCounter","AgentError","usePlainResponse","ZodSchema","finalAnswerToolSchema","z","object","response","string","describe","String","finalAnswerTool","DynamicTool","name","description","inputSchema","handler","JSON","stringify","AssistantMessage","StringToolOutput","tools","forceFinalAnswer","Infinity","emit","llm","create","slice","toolChoice","length","stream","toolCallMessages","getToolCalls","toolCall","tool","find","toolName","toolInput","args","toolResponse","toolCallMsg","ToolMessage","type","toolCallId","getTextContent","isError","e","ToolError","use","explain","textMessages","getTextMessages","isEmpty","deleteMany","filter","msg","meta","push","reset","extraDescription","map","join","overrides","defaultTemplates","ToolCallingAgentSystemPrompt","ToolCallingAgentTaskPrompt","mapObj","key","defaultTemplate","override","PromptTemplate","createSnapshot","shallowCopy","enumerable"],"mappings":";;;;;;;;;;;;;;;;;;AAcC,SAAA,YAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GAAA,EAAA,IAAA,EAAA;;;;;;AAAA,MAAA,CAAA,YAAA,EAAA,cAAA,CAAA;;;;;AAkDM,MAAMA,yBAAyBC,kBAAAA,CAAAA;EAhEtC;;;;AAqEkBC,EAAAA,OAAAA;AAKhBC,EAAAA,WAAAA,CAA4BC,KAA8B,EAAA;AACxD,IAAK,KAAA,EAAA,EAAA,KADqBA,KAAAA,GAAAA,KAAAA,EAAAA,KALZF,OAAUG,GAAAA,mBAAAA,CAAQC,KAAKC,KAAiC,CAAA;MACtEC,SAAW,EAAA;AAAC,QAAA,OAAA;AAAS,QAAA;;MACrBC,OAAS,EAAA;KACX,CAAA;AAIE,IAAA,IAAA,CAAKL,KAAMM,CAAAA,qBAAAA,GAAwB,IAAKN,CAAAA,KAAAA,CAAMM,qBAAyB,IAAA,IAAA;AACzE;EAEA;AACE,IAAA,IAAA,CAAKC,QAAQ,EAAA;AACf;AAEA,EAAA,MAAgBC,IACdR,CAAAA,KAAAA,EACAS,OAAsC,GAAA,IACtCC,GACoC,EAAA;AACpC,IAAA,MAAMC,cAAiB,GAAA,aAAA;AACvB,IAAA,MAAMC,SAAY,GAAA;MAEhBC,eAAiB,EAAA,EAAA;MAEjB,GAAGC,wBAAc,CAAA,IAAA,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CAAA,MAAA,EAASA,KAAKrB,IAAI,CAAA,GAAA,EAAMqB,IAAKpB,CAAAA,WAAW,CAAG,CAAA,CAAA;AAClE+C,SAAAA,CAAAA,IAAAA,CAAK,IAAA;AACT;AACF,KAAA;AACF;AAEA,EAAA,IACc5E,SAAuC,GAAA;AACnD,IAAA,MAAM6E,SAAY,GAAA,IAAA,CAAKpG,KAAMuB,CAAAA,SAAAA,IAAa,EAAC;AAC3C,IAAA,MAAM8E,gBAA8C,GAAA;MAClD7E,MAAQ8E,EAAAA,wCAAAA;MACRrE,IAAMsE,EAAAA;AACR,KAAA;AAEA,IAAA,OAAOC,iBAAOH,CAAAA,gBAAAA,CACZ,CAAA,CAACI,KAAKC,eAAAA,KAAAA;AACJ,MAAMC,MAAAA,QAAAA,GAAWP,SAAUK,CAAAA,GAAAA,CAAQC,IAAAA,eAAAA;AACnC,MAAA,IAAIC,oBAAoBC,2BAAgB,EAAA;AACtC,QAAOD,OAAAA,QAAAA;AACT;AACA,MAAOA,OAAAA,QAAAA,CAASD,eAAAA,CAAoBA,IAAAA,eAAAA;KACtC,CAAA;AAEJ;EAEAG,cAAiB,GAAA;AACf,IAAO,OAAA;AACL,MAAA,GAAG,MAAMA,cAAAA,EAAAA;MACT7G,KAAO8G,EAAAA,qBAAAA,CAAY,KAAK9G,KAAK,CAAA;AAC7BF,MAAAA,OAAAA,EAAS,IAAKA,CAAAA;AAChB,KAAA;AACF;AAEA,EAAA,IAAIkB,OAAOA,MAAoB,EAAA;AAC7B,IAAA,IAAA,CAAKhB,MAAMgB,MAASA,GAAAA,MAAAA;AACtB;AAEA,EAAA,IAAIA,MAAS,GAAA;AACX,IAAA,OAAO,KAAKhB,KAAMgB,CAAAA,MAAAA;AACpB;AACF;;;IAlCW+F,UAAY,EAAA","file":"agent.cjs","sourcesContent":["/**\n * Copyright 2025 © BeeAI a Series of LF Projects, LLC\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 { AgentError, BaseAgent } from \"@/agents/base.js\";\nimport { AnyTool, DynamicTool, StringToolOutput, ToolError, ToolOutput } from \"@/tools/base.js\";\nimport { BaseMemory } from \"@/memory/base.js\";\nimport { AgentMeta } from \"@/agents/types.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport type {\n ToolCallingAgentExecutionConfig,\n ToolCallingAgentTemplates,\n ToolCallingAgentCallbacks,\n ToolCallingAgentRunInput,\n ToolCallingAgentRunOptions,\n ToolCallingAgentRunOutput,\n ToolCallingAgentRunState,\n} from \"@/agents/toolCalling/types.js\";\nimport { GetRunContext } from \"@/context.js\";\nimport { ChatModel } from \"@/backend/chat.js\";\nimport { shallowCopy } from \"@/serializer/utils.js\";\nimport { UnconstrainedMemory } from \"@/memory/unconstrainedMemory.js\";\nimport { AssistantMessage, SystemMessage, ToolMessage, UserMessage } from \"@/backend/message.js\";\nimport { isEmpty, isString } from \"remeda\";\nimport { RetryCounter } from \"@/internals/helpers/counter.js\";\nimport { mapObj, omitUndefined } from \"@/internals/helpers/object.js\";\nimport { Cache } from \"@/cache/decoratorCache.js\";\nimport { PromptTemplate } from \"@/template.js\";\nimport {\n ToolCallingAgentSystemPrompt,\n ToolCallingAgentTaskPrompt,\n} from \"@/agents/toolCalling/prompts.js\";\nimport { z, ZodSchema } from \"zod\";\n\nexport type ToolCallingAgentTemplateFactory<K extends keyof ToolCallingAgentTemplates> = (\n template: ToolCallingAgentTemplates[K],\n) => ToolCallingAgentTemplates[K];\n\nexport interface ToolCallingAgentInput {\n llm: ChatModel;\n memory: BaseMemory;\n tools: AnyTool[];\n meta?: Omit<AgentMeta, \"tools\">;\n templates?: Partial<{\n [K in keyof ToolCallingAgentTemplates]:\n | ToolCallingAgentTemplates[K]\n | ToolCallingAgentTemplateFactory<K>;\n }>;\n execution?: ToolCallingAgentExecutionConfig;\n saveIntermediateSteps?: boolean;\n}\n\nexport class ToolCallingAgent extends BaseAgent<\n ToolCallingAgentRunInput,\n ToolCallingAgentRunOutput,\n ToolCallingAgentRunOptions\n> {\n public readonly emitter = Emitter.root.child<ToolCallingAgentCallbacks>({\n namespace: [\"agent\", \"toolCalling\"],\n creator: this,\n });\n\n constructor(public readonly input: ToolCallingAgentInput) {\n super();\n this.input.saveIntermediateSteps = this.input.saveIntermediateSteps ?? true;\n }\n\n static {\n this.register();\n }\n\n protected async _run(\n input: ToolCallingAgentRunInput,\n options: ToolCallingAgentRunOptions = {},\n run: GetRunContext<typeof this>,\n ): Promise<ToolCallingAgentRunOutput> {\n const tempMessageKey = \"tempMessage\" as const;\n const execution = {\n maxRetriesPerStep: 3,\n totalMaxRetries: 20,\n maxIterations: 10,\n ...omitUndefined(this.input.execution ?? {}),\n ...omitUndefined(options.execution ?? {}),\n };\n\n const state: ToolCallingAgentRunState = {\n memory: new UnconstrainedMemory(),\n result: undefined,\n iteration: 0,\n };\n await state.memory.add(\n new SystemMessage(\n this.templates.system.render({\n role: undefined,\n instructions: undefined,\n }),\n ),\n );\n await state.memory.addMany(this.memory.messages);\n\n if (input.prompt) {\n const userMessage = new UserMessage(\n this.templates.task.render({\n prompt: input.prompt,\n context: input.context,\n expectedOutput: isString(input.expectedOutput) ? input.expectedOutput : undefined,\n }),\n );\n await state.memory.add(userMessage);\n }\n\n const globalRetriesCounter = new RetryCounter(execution.totalMaxRetries || 1, AgentError);\n\n const usePlainResponse = !input.expectedOutput || !(input.expectedOutput instanceof ZodSchema);\n const finalAnswerToolSchema = usePlainResponse\n ? z.object({\n response: z.string().describe(String(input.expectedOutput ?? \"\")),\n })\n : (input.expectedOutput as ZodSchema);\n\n const finalAnswerTool = new DynamicTool({\n name: \"final_answer\",\n description: \"Sends the final answer to the user\",\n inputSchema: finalAnswerToolSchema,\n handler: async (input) => {\n const result = usePlainResponse ? input.response : JSON.stringify(input);\n state.result = new AssistantMessage(result);\n return new StringToolOutput(\"Message has been sent\");\n },\n });\n\n const tools = [...this.input.tools, finalAnswerTool];\n let forceFinalAnswer = false;\n\n while (!state.result) {\n state.iteration++;\n if (state.iteration > (execution.totalMaxRetries ?? Infinity)) {\n throw new AgentError(\n `Agent was not able to resolve the task in ${state.iteration} iterations.`,\n );\n }\n\n await run.emitter.emit(\"start\", { state });\n const response = await this.input.llm.create({\n messages: state.memory.messages.slice(),\n tools,\n toolChoice: forceFinalAnswer ? finalAnswerTool : tools.length > 1 ? \"required\" : tools[0],\n stream: false,\n });\n await state.memory.addMany(response.messages);\n\n const toolCallMessages = response.getToolCalls();\n for (const toolCall of toolCallMessages) {\n try {\n const tool = tools.find((tool) => tool.name === toolCall.toolName);\n if (!tool) {\n throw new AgentError(`Tool ${toolCall.toolName} does not exist!`);\n }\n\n const toolInput: any = toolCall.args;\n const toolResponse: ToolOutput = await tool.run(toolInput).context({\n state,\n toolCallMsg: toolCall,\n });\n await state.memory.add(\n new ToolMessage({\n type: \"tool-result\",\n toolCallId: toolCall.toolCallId,\n toolName: toolCall.toolName,\n result: toolResponse.getTextContent(),\n isError: false,\n }),\n );\n } catch (e) {\n if (e instanceof ToolError) {\n globalRetriesCounter.use(e);\n await state.memory.add(\n new ToolMessage({\n type: \"tool-result\",\n toolCallId: toolCall.toolCallId,\n toolName: toolCall.toolName,\n result: e.explain(),\n isError: true,\n }),\n );\n } else {\n throw e;\n }\n }\n }\n\n // handle empty messages for some models\n const textMessages = response.getTextMessages();\n if (isEmpty(toolCallMessages) && isEmpty(textMessages)) {\n await state.memory.add(new AssistantMessage(\"\\n\", { [tempMessageKey]: true }));\n } else {\n await state.memory.deleteMany(\n state.memory.messages.filter((msg) => msg.meta[tempMessageKey]),\n );\n }\n\n // Fallback for providers that do not support structured outputs\n if (!isEmpty(textMessages) && isEmpty(toolCallMessages)) {\n forceFinalAnswer = true;\n tools.length = 0;\n tools.push(finalAnswerTool);\n }\n\n await run.emitter.emit(\"success\", { state });\n }\n\n if (this.input.saveIntermediateSteps) {\n this.memory.reset();\n await this.memory.addMany(state.memory.messages.slice(1));\n } else {\n await this.memory.addMany(state.memory.messages.slice(-2));\n }\n return { memory: state.memory, result: state.result };\n }\n\n get meta(): AgentMeta {\n const tools = this.input.tools.slice();\n\n if (this.input.meta) {\n return { ...this.input.meta, tools };\n }\n\n return {\n name: \"ToolCalling\",\n tools,\n description: \"ToolCallingAgent that uses tools to accomplish the task.\",\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 @Cache({ enumerable: false })\n protected get templates(): ToolCallingAgentTemplates {\n const overrides = this.input.templates ?? {};\n const defaultTemplates: ToolCallingAgentTemplates = {\n system: ToolCallingAgentSystemPrompt,\n task: ToolCallingAgentTaskPrompt,\n } as const;\n\n return mapObj(defaultTemplates)(\n (key, defaultTemplate: ToolCallingAgentTemplates[typeof key]) => {\n const override = overrides[key] ?? defaultTemplate;\n if (override instanceof PromptTemplate) {\n return override;\n }\n return override(defaultTemplate) ?? defaultTemplate;\n },\n );\n }\n\n createSnapshot() {\n return {\n ...super.createSnapshot(),\n input: shallowCopy(this.input),\n emitter: this.emitter,\n };\n }\n\n set memory(memory: BaseMemory) {\n this.input.memory = memory;\n }\n\n get memory() {\n return this.input.memory;\n }\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { b as AgentMeta, a as BaseAgent } from '../../base-
|
|
1
|
+
import { b as AgentMeta, a as BaseAgent } from '../../base-szR2Izbt.cjs';
|
|
2
2
|
import { AnyTool } from '../../tools/base.cjs';
|
|
3
3
|
import { BaseMemory } from '../../memory/base.cjs';
|
|
4
|
-
import { E as Emitter } from '../../emitter-
|
|
4
|
+
import { E as Emitter } from '../../emitter-D5Mu0EEH.cjs';
|
|
5
5
|
import { ToolCallingAgentTemplates, ToolCallingAgentExecutionConfig, ToolCallingAgentRunInput, ToolCallingAgentRunOutput, ToolCallingAgentRunOptions, ToolCallingAgentCallbacks } from './types.cjs';
|
|
6
6
|
import { GetRunContext } from '../../context.cjs';
|
|
7
|
-
import { m as ChatModel } from '../../chat-
|
|
7
|
+
import { m as ChatModel } from '../../chat-DvMzAHj6.cjs';
|
|
8
8
|
import '../../errors.cjs';
|
|
9
9
|
import '../../internals/types.cjs';
|
|
10
10
|
import '../../internals/helpers/guards.cjs';
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { b as AgentMeta, a as BaseAgent } from '../../base-
|
|
1
|
+
import { b as AgentMeta, a as BaseAgent } from '../../base-BOCDDBvG.js';
|
|
2
2
|
import { AnyTool } from '../../tools/base.js';
|
|
3
3
|
import { BaseMemory } from '../../memory/base.js';
|
|
4
|
-
import { E as Emitter } from '../../emitter-
|
|
4
|
+
import { E as Emitter } from '../../emitter-C3dO-s2P.js';
|
|
5
5
|
import { ToolCallingAgentTemplates, ToolCallingAgentExecutionConfig, ToolCallingAgentRunInput, ToolCallingAgentRunOutput, ToolCallingAgentRunOptions, ToolCallingAgentCallbacks } from './types.js';
|
|
6
6
|
import { GetRunContext } from '../../context.js';
|
|
7
|
-
import { m as ChatModel } from '../../chat-
|
|
7
|
+
import { m as ChatModel } from '../../chat-BdN8hGWn.js';
|
|
8
8
|
import '../../errors.js';
|
|
9
9
|
import '../../internals/types.js';
|
|
10
10
|
import '../../internals/helpers/guards.js';
|
|
@@ -79,7 +79,7 @@ class ToolCallingAgent extends BaseAgent {
|
|
|
79
79
|
description: "Sends the final answer to the user",
|
|
80
80
|
inputSchema: finalAnswerToolSchema,
|
|
81
81
|
handler: /* @__PURE__ */ __name(async (input2) => {
|
|
82
|
-
const result = usePlainResponse ? input2.response : JSON.stringify(input2
|
|
82
|
+
const result = usePlainResponse ? input2.response : JSON.stringify(input2);
|
|
83
83
|
state.result = new AssistantMessage(result);
|
|
84
84
|
return new StringToolOutput("Message has been sent");
|
|
85
85
|
}, "handler")
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["agent.ts"],"names":["ToolCallingAgent","BaseAgent","emitter","constructor","input","Emitter","root","child","namespace","creator","saveIntermediateSteps","register","_run","options","run","tempMessageKey","execution","totalMaxRetries","omitUndefined","state","memory","UnconstrainedMemory","result","undefined","iteration","add","SystemMessage","templates","system","render","role","instructions","addMany","messages","prompt","userMessage","UserMessage","task","context","expectedOutput","isString","globalRetriesCounter","RetryCounter","AgentError","usePlainResponse","ZodSchema","finalAnswerToolSchema","z","object","response","string","describe","String","finalAnswerTool","DynamicTool","name","description","inputSchema","handler","JSON","stringify","AssistantMessage","StringToolOutput","tools","forceFinalAnswer","Infinity","emit","llm","create","slice","toolChoice","length","stream","toolCallMessages","getToolCalls","toolCall","tool","find","toolName","toolInput","args","toolResponse","toolCallMsg","ToolMessage","type","toolCallId","getTextContent","isError","e","ToolError","use","explain","textMessages","getTextMessages","isEmpty","deleteMany","filter","msg","meta","push","reset","extraDescription","map","join","overrides","defaultTemplates","ToolCallingAgentSystemPrompt","ToolCallingAgentTaskPrompt","mapObj","key","defaultTemplate","override","PromptTemplate","createSnapshot","shallowCopy","enumerable"],"mappings":";;;;;;;;;;;;;;;;AAcC,SAAA,YAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GAAA,EAAA,IAAA,EAAA;;;;;;AAAA,MAAA,CAAA,YAAA,EAAA,cAAA,CAAA;;;;;AAkDM,MAAMA,yBAAyBC,SAAAA,CAAAA;EAhEtC;;;;AAqEkBC,EAAAA,OAAAA;AAKhBC,EAAAA,WAAAA,CAA4BC,KAA8B,EAAA;AACxD,IAAK,KAAA,EAAA,EAAA,KADqBA,KAAAA,GAAAA,KAAAA,EAAAA,KALZF,OAAUG,GAAAA,OAAAA,CAAQC,KAAKC,KAAiC,CAAA;MACtEC,SAAW,EAAA;AAAC,Q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,CAAA;AAC7BF,MAAAA,OAAAA,EAAS,IAAKA,CAAAA;AAChB,KAAA;AACF;AAEA,EAAA,IAAIkB,OAAOA,MAAoB,EAAA;AAC7B,IAAA,IAAA,CAAKhB,MAAMgB,MAASA,GAAAA,MAAAA;AACtB;AAEA,EAAA,IAAIA,MAAS,GAAA;AACX,IAAA,OAAO,KAAKhB,KAAMgB,CAAAA,MAAAA;AACpB;AACF;;;IAlCW+F,UAAY,EAAA","file":"agent.js","sourcesContent":["/**\n * Copyright 2025 © BeeAI a Series of LF Projects, LLC\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 { AgentError, BaseAgent } from \"@/agents/base.js\";\nimport { AnyTool, DynamicTool, StringToolOutput, ToolError, ToolOutput } from \"@/tools/base.js\";\nimport { BaseMemory } from \"@/memory/base.js\";\nimport { AgentMeta } from \"@/agents/types.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport type {\n ToolCallingAgentExecutionConfig,\n ToolCallingAgentTemplates,\n ToolCallingAgentCallbacks,\n ToolCallingAgentRunInput,\n ToolCallingAgentRunOptions,\n ToolCallingAgentRunOutput,\n ToolCallingAgentRunState,\n} from \"@/agents/toolCalling/types.js\";\nimport { GetRunContext } from \"@/context.js\";\nimport { ChatModel } from \"@/backend/chat.js\";\nimport { shallowCopy } from \"@/serializer/utils.js\";\nimport { UnconstrainedMemory } from \"@/memory/unconstrainedMemory.js\";\nimport { AssistantMessage, SystemMessage, ToolMessage, UserMessage } from \"@/backend/message.js\";\nimport { isEmpty, isString } from \"remeda\";\nimport { RetryCounter } from \"@/internals/helpers/counter.js\";\nimport { mapObj, omitUndefined } from \"@/internals/helpers/object.js\";\nimport { Cache } from \"@/cache/decoratorCache.js\";\nimport { PromptTemplate } from \"@/template.js\";\nimport {\n ToolCallingAgentSystemPrompt,\n ToolCallingAgentTaskPrompt,\n} from \"@/agents/toolCalling/prompts.js\";\nimport { z, ZodSchema } from \"zod\";\n\nexport type ToolCallingAgentTemplateFactory<K extends keyof ToolCallingAgentTemplates> = (\n template: ToolCallingAgentTemplates[K],\n) => ToolCallingAgentTemplates[K];\n\nexport interface ToolCallingAgentInput {\n llm: ChatModel;\n memory: BaseMemory;\n tools: AnyTool[];\n meta?: Omit<AgentMeta, \"tools\">;\n templates?: Partial<{\n [K in keyof ToolCallingAgentTemplates]:\n | ToolCallingAgentTemplates[K]\n | ToolCallingAgentTemplateFactory<K>;\n }>;\n execution?: ToolCallingAgentExecutionConfig;\n saveIntermediateSteps?: boolean;\n}\n\nexport class ToolCallingAgent extends BaseAgent<\n ToolCallingAgentRunInput,\n ToolCallingAgentRunOutput,\n ToolCallingAgentRunOptions\n> {\n public readonly emitter = Emitter.root.child<ToolCallingAgentCallbacks>({\n namespace: [\"agent\", \"toolCalling\"],\n creator: this,\n });\n\n constructor(public readonly input: ToolCallingAgentInput) {\n super();\n this.input.saveIntermediateSteps = this.input.saveIntermediateSteps ?? true;\n }\n\n static {\n this.register();\n }\n\n protected async _run(\n input: ToolCallingAgentRunInput,\n options: ToolCallingAgentRunOptions = {},\n run: GetRunContext<typeof this>,\n ): Promise<ToolCallingAgentRunOutput> {\n const tempMessageKey = \"tempMessage\" as const;\n const execution = {\n maxRetriesPerStep: 3,\n totalMaxRetries: 20,\n maxIterations: 10,\n ...omitUndefined(this.input.execution ?? {}),\n ...omitUndefined(options.execution ?? {}),\n };\n\n const state: ToolCallingAgentRunState = {\n memory: new UnconstrainedMemory(),\n result: undefined,\n iteration: 0,\n };\n await state.memory.add(\n new SystemMessage(\n this.templates.system.render({\n role: undefined,\n instructions: undefined,\n }),\n ),\n );\n await state.memory.addMany(this.memory.messages);\n\n if (input.prompt) {\n const userMessage = new UserMessage(\n this.templates.task.render({\n prompt: input.prompt,\n context: input.context,\n expectedOutput: isString(input.expectedOutput) ? input.expectedOutput : undefined,\n }),\n );\n await state.memory.add(userMessage);\n }\n\n const globalRetriesCounter = new RetryCounter(execution.totalMaxRetries || 1, AgentError);\n\n const usePlainResponse = !input.expectedOutput || !(input.expectedOutput instanceof ZodSchema);\n const finalAnswerToolSchema = usePlainResponse\n ? z.object({\n response: z.string().describe(String(input.expectedOutput ?? \"\")),\n })\n : (input.expectedOutput as ZodSchema);\n\n const finalAnswerTool = new DynamicTool({\n name: \"final_answer\",\n description: \"Sends the final answer to the user\",\n inputSchema: finalAnswerToolSchema,\n handler: async (input) => {\n const result = usePlainResponse ? input.response : JSON.stringify(input.response);\n state.result = new AssistantMessage(result);\n return new StringToolOutput(\"Message has been sent\");\n },\n });\n\n const tools = [...this.input.tools, finalAnswerTool];\n let forceFinalAnswer = false;\n\n while (!state.result) {\n state.iteration++;\n if (state.iteration > (execution.totalMaxRetries ?? Infinity)) {\n throw new AgentError(\n `Agent was not able to resolve the task in ${state.iteration} iterations.`,\n );\n }\n\n await run.emitter.emit(\"start\", { state });\n const response = await this.input.llm.create({\n messages: state.memory.messages.slice(),\n tools,\n toolChoice: forceFinalAnswer ? finalAnswerTool : tools.length > 1 ? \"required\" : tools[0],\n stream: false,\n });\n await state.memory.addMany(response.messages);\n\n const toolCallMessages = response.getToolCalls();\n for (const toolCall of toolCallMessages) {\n try {\n const tool = tools.find((tool) => tool.name === toolCall.toolName);\n if (!tool) {\n throw new AgentError(`Tool ${toolCall.toolName} does not exist!`);\n }\n\n const toolInput: any = toolCall.args;\n const toolResponse: ToolOutput = await tool.run(toolInput).context({\n state,\n toolCallMsg: toolCall,\n });\n await state.memory.add(\n new ToolMessage({\n type: \"tool-result\",\n toolCallId: toolCall.toolCallId,\n toolName: toolCall.toolName,\n result: toolResponse.getTextContent(),\n isError: false,\n }),\n );\n } catch (e) {\n if (e instanceof ToolError) {\n globalRetriesCounter.use(e);\n await state.memory.add(\n new ToolMessage({\n type: \"tool-result\",\n toolCallId: toolCall.toolCallId,\n toolName: toolCall.toolName,\n result: e.explain(),\n isError: true,\n }),\n );\n } else {\n throw e;\n }\n }\n }\n\n // handle empty messages for some models\n const textMessages = response.getTextMessages();\n if (isEmpty(toolCallMessages) && isEmpty(textMessages)) {\n await state.memory.add(new AssistantMessage(\"\\n\", { [tempMessageKey]: true }));\n } else {\n await state.memory.deleteMany(\n state.memory.messages.filter((msg) => msg.meta[tempMessageKey]),\n );\n }\n\n // Fallback for providers that do not support structured outputs\n if (!isEmpty(textMessages) && isEmpty(toolCallMessages)) {\n forceFinalAnswer = true;\n tools.length = 0;\n tools.push(finalAnswerTool);\n }\n\n await run.emitter.emit(\"success\", { state });\n }\n\n if (this.input.saveIntermediateSteps) {\n this.memory.reset();\n await this.memory.addMany(state.memory.messages.slice(1));\n } else {\n await this.memory.addMany(state.memory.messages.slice(-2));\n }\n return { memory: state.memory, result: state.result };\n }\n\n get meta(): AgentMeta {\n const tools = this.input.tools.slice();\n\n if (this.input.meta) {\n return { ...this.input.meta, tools };\n }\n\n return {\n name: \"ToolCalling\",\n tools,\n description: \"ToolCallingAgent that uses tools to accomplish the task.\",\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 @Cache({ enumerable: false })\n protected get templates(): ToolCallingAgentTemplates {\n const overrides = this.input.templates ?? {};\n const defaultTemplates: ToolCallingAgentTemplates = {\n system: ToolCallingAgentSystemPrompt,\n task: ToolCallingAgentTaskPrompt,\n } as const;\n\n return mapObj(defaultTemplates)(\n (key, defaultTemplate: ToolCallingAgentTemplates[typeof key]) => {\n const override = overrides[key] ?? defaultTemplate;\n if (override instanceof PromptTemplate) {\n return override;\n }\n return override(defaultTemplate) ?? defaultTemplate;\n },\n );\n }\n\n createSnapshot() {\n return {\n ...super.createSnapshot(),\n input: shallowCopy(this.input),\n emitter: this.emitter,\n };\n }\n\n set memory(memory: BaseMemory) {\n this.input.memory = memory;\n }\n\n get memory() {\n return this.input.memory;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["agent.ts"],"names":["ToolCallingAgent","BaseAgent","emitter","constructor","input","Emitter","root","child","namespace","creator","saveIntermediateSteps","register","_run","options","run","tempMessageKey","execution","totalMaxRetries","omitUndefined","state","memory","UnconstrainedMemory","result","undefined","iteration","add","SystemMessage","templates","system","render","role","instructions","addMany","messages","prompt","userMessage","UserMessage","task","context","expectedOutput","isString","globalRetriesCounter","RetryCounter","AgentError","usePlainResponse","ZodSchema","finalAnswerToolSchema","z","object","response","string","describe","String","finalAnswerTool","DynamicTool","name","description","inputSchema","handler","JSON","stringify","AssistantMessage","StringToolOutput","tools","forceFinalAnswer","Infinity","emit","llm","create","slice","toolChoice","length","stream","toolCallMessages","getToolCalls","toolCall","tool","find","toolName","toolInput","args","toolResponse","toolCallMsg","ToolMessage","type","toolCallId","getTextContent","isError","e","ToolError","use","explain","textMessages","getTextMessages","isEmpty","deleteMany","filter","msg","meta","push","reset","extraDescription","map","join","overrides","defaultTemplates","ToolCallingAgentSystemPrompt","ToolCallingAgentTaskPrompt","mapObj","key","defaultTemplate","override","PromptTemplate","createSnapshot","shallowCopy","enumerable"],"mappings":";;;;;;;;;;;;;;;;AAcC,SAAA,YAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GAAA,EAAA,IAAA,EAAA;;;;;;AAAA,MAAA,CAAA,YAAA,EAAA,cAAA,CAAA;;;;;AAkDM,MAAMA,yBAAyBC,SAAAA,CAAAA;EAhEtC;;;;AAqEkBC,EAAAA,OAAAA;AAKhBC,EAAAA,WAAAA,CAA4BC,KAA8B,EAAA;AACxD,IAAK,KAAA,EAAA,EAAA,KADqBA,KAAAA,GAAAA,KAAAA,EAAAA,KALZF,OAAUG,GAAAA,OAAAA,CAAQC,KAAK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EAAAA,WAAAA,CAAY,KAAK9G,KAAK,CAAA;AAC7BF,MAAAA,OAAAA,EAAS,IAAKA,CAAAA;AAChB,KAAA;AACF;AAEA,EAAA,IAAIkB,OAAOA,MAAoB,EAAA;AAC7B,IAAA,IAAA,CAAKhB,MAAMgB,MAASA,GAAAA,MAAAA;AACtB;AAEA,EAAA,IAAIA,MAAS,GAAA;AACX,IAAA,OAAO,KAAKhB,KAAMgB,CAAAA,MAAAA;AACpB;AACF;;;IAlCW+F,UAAY,EAAA","file":"agent.js","sourcesContent":["/**\n * Copyright 2025 © BeeAI a Series of LF Projects, LLC\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 { AgentError, BaseAgent } from \"@/agents/base.js\";\nimport { AnyTool, DynamicTool, StringToolOutput, ToolError, ToolOutput } from \"@/tools/base.js\";\nimport { BaseMemory } from \"@/memory/base.js\";\nimport { AgentMeta } from \"@/agents/types.js\";\nimport { Emitter } from \"@/emitter/emitter.js\";\nimport type {\n ToolCallingAgentExecutionConfig,\n ToolCallingAgentTemplates,\n ToolCallingAgentCallbacks,\n ToolCallingAgentRunInput,\n ToolCallingAgentRunOptions,\n ToolCallingAgentRunOutput,\n ToolCallingAgentRunState,\n} from \"@/agents/toolCalling/types.js\";\nimport { GetRunContext } from \"@/context.js\";\nimport { ChatModel } from \"@/backend/chat.js\";\nimport { shallowCopy } from \"@/serializer/utils.js\";\nimport { UnconstrainedMemory } from \"@/memory/unconstrainedMemory.js\";\nimport { AssistantMessage, SystemMessage, ToolMessage, UserMessage } from \"@/backend/message.js\";\nimport { isEmpty, isString } from \"remeda\";\nimport { RetryCounter } from \"@/internals/helpers/counter.js\";\nimport { mapObj, omitUndefined } from \"@/internals/helpers/object.js\";\nimport { Cache } from \"@/cache/decoratorCache.js\";\nimport { PromptTemplate } from \"@/template.js\";\nimport {\n ToolCallingAgentSystemPrompt,\n ToolCallingAgentTaskPrompt,\n} from \"@/agents/toolCalling/prompts.js\";\nimport { z, ZodSchema } from \"zod\";\n\nexport type ToolCallingAgentTemplateFactory<K extends keyof ToolCallingAgentTemplates> = (\n template: ToolCallingAgentTemplates[K],\n) => ToolCallingAgentTemplates[K];\n\nexport interface ToolCallingAgentInput {\n llm: ChatModel;\n memory: BaseMemory;\n tools: AnyTool[];\n meta?: Omit<AgentMeta, \"tools\">;\n templates?: Partial<{\n [K in keyof ToolCallingAgentTemplates]:\n | ToolCallingAgentTemplates[K]\n | ToolCallingAgentTemplateFactory<K>;\n }>;\n execution?: ToolCallingAgentExecutionConfig;\n saveIntermediateSteps?: boolean;\n}\n\nexport class ToolCallingAgent extends BaseAgent<\n ToolCallingAgentRunInput,\n ToolCallingAgentRunOutput,\n ToolCallingAgentRunOptions\n> {\n public readonly emitter = Emitter.root.child<ToolCallingAgentCallbacks>({\n namespace: [\"agent\", \"toolCalling\"],\n creator: this,\n });\n\n constructor(public readonly input: ToolCallingAgentInput) {\n super();\n this.input.saveIntermediateSteps = this.input.saveIntermediateSteps ?? true;\n }\n\n static {\n this.register();\n }\n\n protected async _run(\n input: ToolCallingAgentRunInput,\n options: ToolCallingAgentRunOptions = {},\n run: GetRunContext<typeof this>,\n ): Promise<ToolCallingAgentRunOutput> {\n const tempMessageKey = \"tempMessage\" as const;\n const execution = {\n maxRetriesPerStep: 3,\n totalMaxRetries: 20,\n maxIterations: 10,\n ...omitUndefined(this.input.execution ?? {}),\n ...omitUndefined(options.execution ?? {}),\n };\n\n const state: ToolCallingAgentRunState = {\n memory: new UnconstrainedMemory(),\n result: undefined,\n iteration: 0,\n };\n await state.memory.add(\n new SystemMessage(\n this.templates.system.render({\n role: undefined,\n instructions: undefined,\n }),\n ),\n );\n await state.memory.addMany(this.memory.messages);\n\n if (input.prompt) {\n const userMessage = new UserMessage(\n this.templates.task.render({\n prompt: input.prompt,\n context: input.context,\n expectedOutput: isString(input.expectedOutput) ? input.expectedOutput : undefined,\n }),\n );\n await state.memory.add(userMessage);\n }\n\n const globalRetriesCounter = new RetryCounter(execution.totalMaxRetries || 1, AgentError);\n\n const usePlainResponse = !input.expectedOutput || !(input.expectedOutput instanceof ZodSchema);\n const finalAnswerToolSchema = usePlainResponse\n ? z.object({\n response: z.string().describe(String(input.expectedOutput ?? \"\")),\n })\n : (input.expectedOutput as ZodSchema);\n\n const finalAnswerTool = new DynamicTool({\n name: \"final_answer\",\n description: \"Sends the final answer to the user\",\n inputSchema: finalAnswerToolSchema,\n handler: async (input) => {\n const result = usePlainResponse ? input.response : JSON.stringify(input);\n state.result = new AssistantMessage(result);\n return new StringToolOutput(\"Message has been sent\");\n },\n });\n\n const tools = [...this.input.tools, finalAnswerTool];\n let forceFinalAnswer = false;\n\n while (!state.result) {\n state.iteration++;\n if (state.iteration > (execution.totalMaxRetries ?? Infinity)) {\n throw new AgentError(\n `Agent was not able to resolve the task in ${state.iteration} iterations.`,\n );\n }\n\n await run.emitter.emit(\"start\", { state });\n const response = await this.input.llm.create({\n messages: state.memory.messages.slice(),\n tools,\n toolChoice: forceFinalAnswer ? finalAnswerTool : tools.length > 1 ? \"required\" : tools[0],\n stream: false,\n });\n await state.memory.addMany(response.messages);\n\n const toolCallMessages = response.getToolCalls();\n for (const toolCall of toolCallMessages) {\n try {\n const tool = tools.find((tool) => tool.name === toolCall.toolName);\n if (!tool) {\n throw new AgentError(`Tool ${toolCall.toolName} does not exist!`);\n }\n\n const toolInput: any = toolCall.args;\n const toolResponse: ToolOutput = await tool.run(toolInput).context({\n state,\n toolCallMsg: toolCall,\n });\n await state.memory.add(\n new ToolMessage({\n type: \"tool-result\",\n toolCallId: toolCall.toolCallId,\n toolName: toolCall.toolName,\n result: toolResponse.getTextContent(),\n isError: false,\n }),\n );\n } catch (e) {\n if (e instanceof ToolError) {\n globalRetriesCounter.use(e);\n await state.memory.add(\n new ToolMessage({\n type: \"tool-result\",\n toolCallId: toolCall.toolCallId,\n toolName: toolCall.toolName,\n result: e.explain(),\n isError: true,\n }),\n );\n } else {\n throw e;\n }\n }\n }\n\n // handle empty messages for some models\n const textMessages = response.getTextMessages();\n if (isEmpty(toolCallMessages) && isEmpty(textMessages)) {\n await state.memory.add(new AssistantMessage(\"\\n\", { [tempMessageKey]: true }));\n } else {\n await state.memory.deleteMany(\n state.memory.messages.filter((msg) => msg.meta[tempMessageKey]),\n );\n }\n\n // Fallback for providers that do not support structured outputs\n if (!isEmpty(textMessages) && isEmpty(toolCallMessages)) {\n forceFinalAnswer = true;\n tools.length = 0;\n tools.push(finalAnswerTool);\n }\n\n await run.emitter.emit(\"success\", { state });\n }\n\n if (this.input.saveIntermediateSteps) {\n this.memory.reset();\n await this.memory.addMany(state.memory.messages.slice(1));\n } else {\n await this.memory.addMany(state.memory.messages.slice(-2));\n }\n return { memory: state.memory, result: state.result };\n }\n\n get meta(): AgentMeta {\n const tools = this.input.tools.slice();\n\n if (this.input.meta) {\n return { ...this.input.meta, tools };\n }\n\n return {\n name: \"ToolCalling\",\n tools,\n description: \"ToolCallingAgent that uses tools to accomplish the task.\",\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 @Cache({ enumerable: false })\n protected get templates(): ToolCallingAgentTemplates {\n const overrides = this.input.templates ?? {};\n const defaultTemplates: ToolCallingAgentTemplates = {\n system: ToolCallingAgentSystemPrompt,\n task: ToolCallingAgentTaskPrompt,\n } as const;\n\n return mapObj(defaultTemplates)(\n (key, defaultTemplate: ToolCallingAgentTemplates[typeof key]) => {\n const override = overrides[key] ?? defaultTemplate;\n if (override instanceof PromptTemplate) {\n return override;\n }\n return override(defaultTemplate) ?? defaultTemplate;\n },\n );\n }\n\n createSnapshot() {\n return {\n ...super.createSnapshot(),\n input: shallowCopy(this.input),\n emitter: this.emitter,\n };\n }\n\n set memory(memory: BaseMemory) {\n this.input.memory = memory;\n }\n\n get memory() {\n return this.input.memory;\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseMemory } from '../../memory/base.cjs';
|
|
2
2
|
import { AssistantMessage } from '../../backend/message.cjs';
|
|
3
|
-
import { C as Callback } from '../../emitter-
|
|
3
|
+
import { C as Callback } from '../../emitter-D5Mu0EEH.cjs';
|
|
4
4
|
import { ToolCallingAgentSystemPrompt, ToolCallingAgentTaskPrompt } from './prompts.cjs';
|
|
5
5
|
import { ZodSchema } from 'zod';
|
|
6
6
|
import '../../errors.cjs';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseMemory } from '../../memory/base.js';
|
|
2
2
|
import { AssistantMessage } from '../../backend/message.js';
|
|
3
|
-
import { C as Callback } from '../../emitter-
|
|
3
|
+
import { C as Callback } from '../../emitter-C3dO-s2P.js';
|
|
4
4
|
import { ToolCallingAgentSystemPrompt, ToolCallingAgentTaskPrompt } from './prompts.js';
|
|
5
5
|
import { ZodSchema } from 'zod';
|
|
6
6
|
import '../../errors.js';
|
package/dist/agents/types.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { d as AgentCallback, c as AgentCallbackValue, b as AgentMeta, f as AnyAgent, G as GetAgentInput, e as GetAgentOutput, I as InternalAgentCallbackValue, P as PublicAgentCallbackValue } from '../base-
|
|
1
|
+
export { d as AgentCallback, c as AgentCallbackValue, b as AgentMeta, f as AnyAgent, G as GetAgentInput, e as GetAgentOutput, I as InternalAgentCallbackValue, P as PublicAgentCallbackValue } from '../base-szR2Izbt.cjs';
|
|
2
2
|
import '../internals/types.cjs';
|
|
3
3
|
import '../tools/base.cjs';
|
|
4
4
|
import '../context.cjs';
|
|
5
|
-
import '../emitter-
|
|
5
|
+
import '../emitter-D5Mu0EEH.cjs';
|
|
6
6
|
import '../internals/serializable.cjs';
|
|
7
7
|
import '../internals/helpers/guards.cjs';
|
|
8
8
|
import '../internals/helpers/promise.cjs';
|
package/dist/agents/types.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export { d as AgentCallback, c as AgentCallbackValue, b as AgentMeta, f as AnyAgent, G as GetAgentInput, e as GetAgentOutput, I as InternalAgentCallbackValue, P as PublicAgentCallbackValue } from '../base-
|
|
1
|
+
export { d as AgentCallback, c as AgentCallbackValue, b as AgentMeta, f as AnyAgent, G as GetAgentInput, e as GetAgentOutput, I as InternalAgentCallbackValue, P as PublicAgentCallbackValue } from '../base-BOCDDBvG.js';
|
|
2
2
|
import '../internals/types.js';
|
|
3
3
|
import '../tools/base.js';
|
|
4
4
|
import '../context.js';
|
|
5
|
-
import '../emitter-
|
|
5
|
+
import '../emitter-C3dO-s2P.js';
|
|
6
6
|
import '../internals/serializable.js';
|
|
7
7
|
import '../internals/helpers/guards.js';
|
|
8
8
|
import '../internals/helpers/promise.js';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Serializable } from '../internals/serializable.cjs';
|
|
2
|
-
import { m as ChatModel, F as FullModelName } from '../chat-
|
|
2
|
+
import { m as ChatModel, F as FullModelName } from '../chat-DvMzAHj6.cjs';
|
|
3
3
|
import { EmbeddingModel } from './embedding.cjs';
|
|
4
4
|
import { ProviderName } from './constants.cjs';
|
|
5
5
|
import { OptionalExcept } from '../internals/types.cjs';
|
|
6
6
|
import './message.cjs';
|
|
7
7
|
import 'ai';
|
|
8
8
|
import '../context.cjs';
|
|
9
|
-
import '../emitter-
|
|
9
|
+
import '../emitter-D5Mu0EEH.cjs';
|
|
10
10
|
import '../internals/helpers/promise.cjs';
|
|
11
11
|
import '../errors.cjs';
|
|
12
12
|
import 'promise-based-task';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Serializable } from '../internals/serializable.js';
|
|
2
|
-
import { m as ChatModel, F as FullModelName } from '../chat-
|
|
2
|
+
import { m as ChatModel, F as FullModelName } from '../chat-BdN8hGWn.js';
|
|
3
3
|
import { EmbeddingModel } from './embedding.js';
|
|
4
4
|
import { ProviderName } from './constants.js';
|
|
5
5
|
import { OptionalExcept } from '../internals/types.js';
|
|
6
6
|
import './message.js';
|
|
7
7
|
import 'ai';
|
|
8
8
|
import '../context.js';
|
|
9
|
-
import '../emitter-
|
|
9
|
+
import '../emitter-C3dO-s2P.js';
|
|
10
10
|
import '../internals/helpers/promise.js';
|
|
11
11
|
import '../errors.js';
|
|
12
12
|
import 'promise-based-task';
|
package/dist/backend/chat.d.cts
CHANGED
|
@@ -2,11 +2,11 @@ import './message.cjs';
|
|
|
2
2
|
import 'ai';
|
|
3
3
|
import '../context.cjs';
|
|
4
4
|
import '../internals/serializable.cjs';
|
|
5
|
-
import '../emitter-
|
|
5
|
+
import '../emitter-D5Mu0EEH.cjs';
|
|
6
6
|
import '../errors.cjs';
|
|
7
7
|
import 'promise-based-task';
|
|
8
8
|
import '../cache/base.cjs';
|
|
9
|
-
export { k as ChatConfig, m as ChatModel, i as ChatModelCache, h as ChatModelEmitter, g as ChatModelEvents, e as ChatModelFinishReason, d as ChatModelInput, a as ChatModelObjectInput, b as ChatModelObjectOutput, n as ChatModelOutput, C as ChatModelParameters, c as ChatModelToolChoice, l as ChatModelToolChoiceSupport, f as ChatModelUsage, j as ConfigFn } from '../chat-
|
|
9
|
+
export { k as ChatConfig, m as ChatModel, i as ChatModelCache, h as ChatModelEmitter, g as ChatModelEvents, e as ChatModelFinishReason, d as ChatModelInput, a as ChatModelObjectInput, b as ChatModelObjectOutput, n as ChatModelOutput, C as ChatModelParameters, c as ChatModelToolChoice, l as ChatModelToolChoiceSupport, f as ChatModelUsage, j as ConfigFn } from '../chat-DvMzAHj6.cjs';
|
|
10
10
|
import './constants.cjs';
|
|
11
11
|
import '../tools/base.cjs';
|
|
12
12
|
import 'zod';
|
package/dist/backend/chat.d.ts
CHANGED
|
@@ -2,11 +2,11 @@ import './message.js';
|
|
|
2
2
|
import 'ai';
|
|
3
3
|
import '../context.js';
|
|
4
4
|
import '../internals/serializable.js';
|
|
5
|
-
import '../emitter-
|
|
5
|
+
import '../emitter-C3dO-s2P.js';
|
|
6
6
|
import '../errors.js';
|
|
7
7
|
import 'promise-based-task';
|
|
8
8
|
import '../cache/base.js';
|
|
9
|
-
export { k as ChatConfig, m as ChatModel, i as ChatModelCache, h as ChatModelEmitter, g as ChatModelEvents, e as ChatModelFinishReason, d as ChatModelInput, a as ChatModelObjectInput, b as ChatModelObjectOutput, n as ChatModelOutput, C as ChatModelParameters, c as ChatModelToolChoice, l as ChatModelToolChoiceSupport, f as ChatModelUsage, j as ConfigFn } from '../chat-
|
|
9
|
+
export { k as ChatConfig, m as ChatModel, i as ChatModelCache, h as ChatModelEmitter, g as ChatModelEvents, e as ChatModelFinishReason, d as ChatModelInput, a as ChatModelObjectInput, b as ChatModelObjectOutput, n as ChatModelOutput, C as ChatModelParameters, c as ChatModelToolChoice, l as ChatModelToolChoiceSupport, f as ChatModelUsage, j as ConfigFn } from '../chat-BdN8hGWn.js';
|
|
10
10
|
import './constants.js';
|
|
11
11
|
import '../tools/base.js';
|
|
12
12
|
import 'zod';
|
package/dist/backend/core.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Backend } from './backend.cjs';
|
|
2
|
-
export { k as ChatConfig, m as ChatModel, i as ChatModelCache, h as ChatModelEmitter, g as ChatModelEvents, e as ChatModelFinishReason, d as ChatModelInput, a as ChatModelObjectInput, b as ChatModelObjectOutput, n as ChatModelOutput, C as ChatModelParameters, c as ChatModelToolChoice, l as ChatModelToolChoiceSupport, f as ChatModelUsage, j as ConfigFn } from '../chat-
|
|
2
|
+
export { k as ChatConfig, m as ChatModel, i as ChatModelCache, h as ChatModelEmitter, g as ChatModelEvents, e as ChatModelFinishReason, d as ChatModelInput, a as ChatModelObjectInput, b as ChatModelObjectOutput, n as ChatModelOutput, C as ChatModelParameters, c as ChatModelToolChoice, l as ChatModelToolChoiceSupport, f as ChatModelUsage, j as ConfigFn } from '../chat-DvMzAHj6.cjs';
|
|
3
3
|
export { EmbeddingModel, EmbeddingModelEmitter, EmbeddingModelEvents, EmbeddingModelInput, EmbeddingModelOutput } from './embedding.cjs';
|
|
4
4
|
export { AssistantMessage, CustomMessage, Message, MessageContentPart, MessageInput, MessageMeta, MessageRole, Role, SystemMessage, ToolMessage, UserMessage } from './message.cjs';
|
|
5
5
|
export { BackendError, ChatModelError, EmbeddingModelError } from './errors.cjs';
|
|
@@ -9,7 +9,7 @@ import '../internals/helpers/guards.cjs';
|
|
|
9
9
|
import './constants.cjs';
|
|
10
10
|
import 'ai';
|
|
11
11
|
import '../context.cjs';
|
|
12
|
-
import '../emitter-
|
|
12
|
+
import '../emitter-D5Mu0EEH.cjs';
|
|
13
13
|
import '../internals/helpers/promise.cjs';
|
|
14
14
|
import '../errors.cjs';
|
|
15
15
|
import 'promise-based-task';
|
package/dist/backend/core.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Backend } from './backend.js';
|
|
2
|
-
export { k as ChatConfig, m as ChatModel, i as ChatModelCache, h as ChatModelEmitter, g as ChatModelEvents, e as ChatModelFinishReason, d as ChatModelInput, a as ChatModelObjectInput, b as ChatModelObjectOutput, n as ChatModelOutput, C as ChatModelParameters, c as ChatModelToolChoice, l as ChatModelToolChoiceSupport, f as ChatModelUsage, j as ConfigFn } from '../chat-
|
|
2
|
+
export { k as ChatConfig, m as ChatModel, i as ChatModelCache, h as ChatModelEmitter, g as ChatModelEvents, e as ChatModelFinishReason, d as ChatModelInput, a as ChatModelObjectInput, b as ChatModelObjectOutput, n as ChatModelOutput, C as ChatModelParameters, c as ChatModelToolChoice, l as ChatModelToolChoiceSupport, f as ChatModelUsage, j as ConfigFn } from '../chat-BdN8hGWn.js';
|
|
3
3
|
export { EmbeddingModel, EmbeddingModelEmitter, EmbeddingModelEvents, EmbeddingModelInput, EmbeddingModelOutput } from './embedding.js';
|
|
4
4
|
export { AssistantMessage, CustomMessage, Message, MessageContentPart, MessageInput, MessageMeta, MessageRole, Role, SystemMessage, ToolMessage, UserMessage } from './message.js';
|
|
5
5
|
export { BackendError, ChatModelError, EmbeddingModelError } from './errors.js';
|
|
@@ -9,7 +9,7 @@ import '../internals/helpers/guards.js';
|
|
|
9
9
|
import './constants.js';
|
|
10
10
|
import 'ai';
|
|
11
11
|
import '../context.js';
|
|
12
|
-
import '../emitter-
|
|
12
|
+
import '../emitter-C3dO-s2P.js';
|
|
13
13
|
import '../internals/helpers/promise.js';
|
|
14
14
|
import '../errors.js';
|
|
15
15
|
import 'promise-based-task';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Run, GetRunContext } from '../context.cjs';
|
|
2
2
|
import { Serializable } from '../internals/serializable.cjs';
|
|
3
|
-
import { C as Callback, E as Emitter } from '../emitter-
|
|
3
|
+
import { C as Callback, E as Emitter } from '../emitter-D5Mu0EEH.cjs';
|
|
4
4
|
import { FrameworkError } from '../errors.cjs';
|
|
5
|
-
import { F as FullModelName } from '../chat-
|
|
5
|
+
import { F as FullModelName } from '../chat-DvMzAHj6.cjs';
|
|
6
6
|
import { ProviderName } from './constants.cjs';
|
|
7
7
|
import '../internals/helpers/promise.cjs';
|
|
8
8
|
import '../internals/types.cjs';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Run, GetRunContext } from '../context.js';
|
|
2
2
|
import { Serializable } from '../internals/serializable.js';
|
|
3
|
-
import { C as Callback, E as Emitter } from '../emitter-
|
|
3
|
+
import { C as Callback, E as Emitter } from '../emitter-C3dO-s2P.js';
|
|
4
4
|
import { FrameworkError } from '../errors.js';
|
|
5
|
-
import { F as FullModelName } from '../chat-
|
|
5
|
+
import { F as FullModelName } from '../chat-BdN8hGWn.js';
|
|
6
6
|
import { ProviderName } from './constants.js';
|
|
7
7
|
import '../internals/helpers/promise.js';
|
|
8
8
|
import '../internals/types.js';
|
package/dist/backend/utils.d.cts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import '../internals/types.cjs';
|
|
2
2
|
import './constants.cjs';
|
|
3
3
|
import '../tools/base.cjs';
|
|
4
|
-
export { F as FullModelName, r as filterToolsByToolChoice, q as generateToolUnionSchema, o as loadModel, p as parseModel } from '../chat-
|
|
4
|
+
export { F as FullModelName, r as filterToolsByToolChoice, q as generateToolUnionSchema, o as loadModel, p as parseModel } from '../chat-DvMzAHj6.cjs';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import '../internals/helpers/guards.cjs';
|
|
7
7
|
import 'ajv';
|
|
8
8
|
import '../context.cjs';
|
|
9
|
-
import '../emitter-
|
|
9
|
+
import '../emitter-D5Mu0EEH.cjs';
|
|
10
10
|
import '../internals/serializable.cjs';
|
|
11
11
|
import '../internals/helpers/promise.cjs';
|
|
12
12
|
import '../errors.cjs';
|
package/dist/backend/utils.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import '../internals/types.js';
|
|
2
2
|
import './constants.js';
|
|
3
3
|
import '../tools/base.js';
|
|
4
|
-
export { F as FullModelName, r as filterToolsByToolChoice, q as generateToolUnionSchema, o as loadModel, p as parseModel } from '../chat-
|
|
4
|
+
export { F as FullModelName, r as filterToolsByToolChoice, q as generateToolUnionSchema, o as loadModel, p as parseModel } from '../chat-BdN8hGWn.js';
|
|
5
5
|
import 'zod';
|
|
6
6
|
import '../internals/helpers/guards.js';
|
|
7
7
|
import 'ajv';
|
|
8
8
|
import '../context.js';
|
|
9
|
-
import '../emitter-
|
|
9
|
+
import '../emitter-C3dO-s2P.js';
|
|
10
10
|
import '../internals/serializable.js';
|
|
11
11
|
import '../internals/helpers/promise.js';
|
|
12
12
|
import '../errors.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Run, GetRunContext } from './context.js';
|
|
2
2
|
import { FrameworkError } from './errors.js';
|
|
3
3
|
import { Serializable } from './internals/serializable.js';
|
|
4
|
-
import { E as Emitter } from './emitter-
|
|
4
|
+
import { E as Emitter } from './emitter-C3dO-s2P.js';
|
|
5
5
|
import { BaseMemory } from './memory/base.js';
|
|
6
6
|
import { OmitEmpty } from './internals/types.js';
|
|
7
7
|
import { AnyTool } from './tools/base.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Run, GetRunContext } from './context.cjs';
|
|
2
2
|
import { FrameworkError } from './errors.cjs';
|
|
3
3
|
import { Serializable } from './internals/serializable.cjs';
|
|
4
|
-
import { E as Emitter } from './emitter-
|
|
4
|
+
import { E as Emitter } from './emitter-D5Mu0EEH.cjs';
|
|
5
5
|
import { BaseMemory } from './memory/base.cjs';
|
|
6
6
|
import { OmitEmpty } from './internals/types.cjs';
|
|
7
7
|
import { AnyTool } from './tools/base.cjs';
|