beeai-framework 0.1.6 → 0.1.7
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/vercel/backend/chat.cjs +0 -1
- package/dist/adapters/vercel/backend/chat.cjs.map +1 -1
- package/dist/adapters/vercel/backend/chat.js +0 -1
- package/dist/adapters/vercel/backend/chat.js.map +1 -1
- package/dist/adapters/watsonx/backend/chat.cjs +6 -2
- package/dist/adapters/watsonx/backend/chat.cjs.map +1 -1
- package/dist/adapters/watsonx/backend/chat.d.cts +1 -1
- package/dist/adapters/watsonx/backend/chat.d.ts +1 -1
- package/dist/adapters/watsonx/backend/chat.js +6 -2
- package/dist/adapters/watsonx/backend/chat.js.map +1 -1
- package/dist/agent-Bf2FaCKy.d.ts +84 -0
- package/dist/agent-Bpt7IFa_.d.cts +84 -0
- package/dist/agents/experimental/remote/agent.cjs +25 -18
- package/dist/agents/experimental/remote/agent.cjs.map +1 -1
- package/dist/agents/experimental/remote/agent.d.cts +4 -3
- package/dist/agents/experimental/remote/agent.d.ts +4 -3
- package/dist/agents/experimental/remote/agent.js +26 -19
- package/dist/agents/experimental/remote/agent.js.map +1 -1
- package/dist/agents/{bee → react}/agent.cjs +5 -5
- package/dist/agents/react/agent.cjs.map +1 -0
- package/dist/agents/{bee → react}/agent.d.cts +1 -1
- package/dist/agents/{bee → react}/agent.d.ts +1 -1
- package/dist/agents/{bee → react}/agent.js +5 -5
- package/dist/agents/react/agent.js.map +1 -0
- package/dist/agents/{bee → react}/prompts.cjs +18 -18
- package/dist/agents/react/prompts.cjs.map +1 -0
- package/dist/agents/{bee → react}/prompts.d.cts +10 -10
- package/dist/agents/{bee → react}/prompts.d.ts +10 -10
- package/dist/agents/{bee → react}/prompts.js +10 -10
- package/dist/agents/react/prompts.js.map +1 -0
- package/dist/agents/{bee → react}/runners/base.cjs +1 -1
- package/dist/agents/{bee → react}/runners/base.cjs.map +1 -1
- package/dist/agents/{bee → react}/runners/base.d.cts +1 -1
- package/dist/agents/{bee → react}/runners/base.d.ts +1 -1
- package/dist/agents/{bee → react}/runners/base.js +1 -1
- package/dist/agents/{bee → react}/runners/base.js.map +1 -1
- package/dist/agents/{bee → react}/runners/deep-think/prompts.cjs +14 -14
- package/dist/agents/react/runners/deep-think/prompts.cjs.map +1 -0
- package/dist/agents/{bee/runners/granite → react/runners/deep-think}/prompts.d.cts +8 -8
- package/dist/agents/{bee/runners/granite → react/runners/deep-think}/prompts.d.ts +8 -8
- package/dist/agents/{bee → react}/runners/deep-think/prompts.js +9 -9
- package/dist/agents/react/runners/deep-think/prompts.js.map +1 -0
- package/dist/agents/{bee → react}/runners/deep-think/runner.cjs +10 -10
- package/dist/agents/react/runners/deep-think/runner.cjs.map +1 -0
- package/dist/agents/{bee → react}/runners/deep-think/runner.d.cts +4 -4
- package/dist/agents/{bee → react}/runners/deep-think/runner.d.ts +4 -4
- package/dist/agents/{bee → react}/runners/deep-think/runner.js +12 -12
- package/dist/agents/react/runners/deep-think/runner.js.map +1 -0
- package/dist/agents/{bee → react}/runners/default/runner.cjs +10 -10
- package/dist/agents/react/runners/default/runner.cjs.map +1 -0
- package/dist/agents/{bee → react}/runners/default/runner.d.cts +7 -7
- package/dist/agents/{bee → react}/runners/default/runner.d.ts +7 -7
- package/dist/agents/{bee → react}/runners/default/runner.js +11 -11
- package/dist/agents/react/runners/default/runner.js.map +1 -0
- package/dist/agents/{bee → react}/runners/default/runner.spec.cjs +5 -5
- package/dist/agents/react/runners/default/runner.spec.cjs.map +1 -0
- package/dist/agents/{bee → react}/runners/default/runner.spec.js +6 -6
- package/dist/agents/react/runners/default/runner.spec.js.map +1 -0
- package/dist/agents/{bee → react}/runners/granite/prompts.cjs +14 -14
- package/dist/agents/react/runners/granite/prompts.cjs.map +1 -0
- package/dist/agents/{bee/runners/deep-think → react/runners/granite}/prompts.d.cts +8 -8
- package/dist/agents/{bee/runners/deep-think → react/runners/granite}/prompts.d.ts +8 -8
- package/dist/agents/{bee → react}/runners/granite/prompts.js +9 -9
- package/dist/agents/react/runners/granite/prompts.js.map +1 -0
- package/dist/agents/{bee → react}/runners/granite/runner.cjs +10 -10
- package/dist/agents/react/runners/granite/runner.cjs.map +1 -0
- package/dist/agents/{bee → react}/runners/granite/runner.d.cts +4 -4
- package/dist/agents/{bee → react}/runners/granite/runner.d.ts +4 -4
- package/dist/agents/{bee → react}/runners/granite/runner.js +12 -12
- package/dist/agents/react/runners/granite/runner.js.map +1 -0
- package/dist/agents/{bee → react}/types.d.cts +45 -45
- package/dist/agents/{bee → react}/types.d.ts +45 -45
- package/dist/agents/toolCalling/agent.cjs +208 -0
- package/dist/agents/toolCalling/agent.cjs.map +1 -0
- package/dist/agents/toolCalling/agent.d.cts +70 -0
- package/dist/agents/toolCalling/agent.d.ts +70 -0
- package/dist/agents/toolCalling/agent.js +206 -0
- package/dist/agents/toolCalling/agent.js.map +1 -0
- package/dist/agents/toolCalling/prompts.cjs +65 -0
- package/dist/agents/toolCalling/prompts.cjs.map +1 -0
- package/dist/agents/toolCalling/prompts.d.cts +49 -0
- package/dist/agents/toolCalling/prompts.d.ts +49 -0
- package/dist/agents/toolCalling/prompts.js +62 -0
- package/dist/agents/toolCalling/prompts.js.map +1 -0
- package/dist/agents/toolCalling/types.cjs +4 -0
- package/dist/agents/toolCalling/types.cjs.map +1 -0
- package/dist/agents/toolCalling/types.d.cts +66 -0
- package/dist/agents/toolCalling/types.d.ts +66 -0
- package/dist/agents/toolCalling/types.js +3 -0
- package/dist/agents/toolCalling/types.js.map +1 -0
- package/dist/backend/chat.cjs +3 -0
- package/dist/backend/chat.cjs.map +1 -1
- package/dist/backend/chat.d.cts +2 -1
- package/dist/backend/chat.d.ts +2 -1
- package/dist/backend/chat.js +3 -0
- package/dist/backend/chat.js.map +1 -1
- package/dist/backend/message.cjs +9 -0
- package/dist/backend/message.cjs.map +1 -1
- package/dist/backend/message.d.cts +2 -0
- package/dist/backend/message.d.ts +2 -0
- package/dist/backend/message.js +9 -0
- package/dist/backend/message.js.map +1 -1
- package/dist/instrumentation/create-telemetry-middleware.cjs.map +1 -1
- package/dist/instrumentation/create-telemetry-middleware.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.js +1 -1
- package/dist/workflows/agent.cjs +2 -2
- package/dist/workflows/agent.cjs.map +1 -1
- package/dist/workflows/agent.d.cts +4 -4
- package/dist/workflows/agent.d.ts +4 -4
- package/dist/workflows/agent.js +2 -2
- package/dist/workflows/agent.js.map +1 -1
- package/package.json +3 -3
- package/dist/agent-BZ-_ATuJ.d.cts +0 -84
- package/dist/agent-BqoZ6FbM.d.ts +0 -84
- package/dist/agents/bee/agent.cjs.map +0 -1
- package/dist/agents/bee/agent.js.map +0 -1
- package/dist/agents/bee/prompts.cjs.map +0 -1
- package/dist/agents/bee/prompts.js.map +0 -1
- package/dist/agents/bee/runners/deep-think/prompts.cjs.map +0 -1
- package/dist/agents/bee/runners/deep-think/prompts.js.map +0 -1
- package/dist/agents/bee/runners/deep-think/runner.cjs.map +0 -1
- package/dist/agents/bee/runners/deep-think/runner.js.map +0 -1
- package/dist/agents/bee/runners/default/runner.cjs.map +0 -1
- package/dist/agents/bee/runners/default/runner.js.map +0 -1
- package/dist/agents/bee/runners/default/runner.spec.cjs.map +0 -1
- package/dist/agents/bee/runners/default/runner.spec.js.map +0 -1
- package/dist/agents/bee/runners/granite/prompts.cjs.map +0 -1
- package/dist/agents/bee/runners/granite/prompts.js.map +0 -1
- package/dist/agents/bee/runners/granite/runner.cjs.map +0 -1
- package/dist/agents/bee/runners/granite/runner.js.map +0 -1
- /package/dist/agents/{bee → react}/runners/default/runner.spec.d.cts +0 -0
- /package/dist/agents/{bee → react}/runners/default/runner.spec.d.ts +0 -0
- /package/dist/agents/{bee → react}/types.cjs +0 -0
- /package/dist/agents/{bee → react}/types.cjs.map +0 -0
- /package/dist/agents/{bee → react}/types.js +0 -0
- /package/dist/agents/{bee → react}/types.js.map +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { b as AgentMeta, a as BaseAgent } from '../../base-daM6fHUP.cjs';
|
|
2
|
+
import { AnyTool } from '../../tools/base.cjs';
|
|
3
|
+
import { BaseMemory } from '../../memory/base.cjs';
|
|
4
|
+
import { E as Emitter } from '../../emitter-C9EN5B0j.cjs';
|
|
5
|
+
import { ToolCallingAgentTemplates, ToolCallingAgentExecutionConfig, ToolCallingAgentRunInput, ToolCallingAgentRunOutput, ToolCallingAgentRunOptions, ToolCallingAgentCallbacks } from './types.cjs';
|
|
6
|
+
import { GetRunContext } from '../../context.cjs';
|
|
7
|
+
import { ChatModel } from '../../backend/chat.cjs';
|
|
8
|
+
import '../../errors.cjs';
|
|
9
|
+
import '../../internals/types.cjs';
|
|
10
|
+
import '../../internals/helpers/guards.cjs';
|
|
11
|
+
import '../../internals/serializable.cjs';
|
|
12
|
+
import 'ajv';
|
|
13
|
+
import 'promise-based-task';
|
|
14
|
+
import '../../cache/base.cjs';
|
|
15
|
+
import '../../internals/helpers/schema.cjs';
|
|
16
|
+
import 'zod';
|
|
17
|
+
import 'zod-to-json-schema';
|
|
18
|
+
import '../../internals/helpers/promise.cjs';
|
|
19
|
+
import '../../backend/message.cjs';
|
|
20
|
+
import 'ai';
|
|
21
|
+
import './prompts.cjs';
|
|
22
|
+
import '../../template.cjs';
|
|
23
|
+
import '../../backend/utils.cjs';
|
|
24
|
+
import '../../backend/constants.cjs';
|
|
25
|
+
import '@ai-sdk/provider';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Copyright 2025 IBM Corp.
|
|
29
|
+
*
|
|
30
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
31
|
+
* you may not use this file except in compliance with the License.
|
|
32
|
+
* You may obtain a copy of the License at
|
|
33
|
+
*
|
|
34
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
35
|
+
*
|
|
36
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
37
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
38
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
39
|
+
* See the License for the specific language governing permissions and
|
|
40
|
+
* limitations under the License.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
type ToolCallingAgentTemplateFactory<K extends keyof ToolCallingAgentTemplates> = (template: ToolCallingAgentTemplates[K]) => ToolCallingAgentTemplates[K];
|
|
44
|
+
interface ToolCallingAgentInput {
|
|
45
|
+
llm: ChatModel;
|
|
46
|
+
memory: BaseMemory;
|
|
47
|
+
tools: AnyTool[];
|
|
48
|
+
meta?: Omit<AgentMeta, "tools">;
|
|
49
|
+
templates?: Partial<{
|
|
50
|
+
[K in keyof ToolCallingAgentTemplates]: ToolCallingAgentTemplates[K] | ToolCallingAgentTemplateFactory<K>;
|
|
51
|
+
}>;
|
|
52
|
+
execution?: ToolCallingAgentExecutionConfig;
|
|
53
|
+
}
|
|
54
|
+
declare class ToolCallingAgent extends BaseAgent<ToolCallingAgentRunInput, ToolCallingAgentRunOutput, ToolCallingAgentRunOptions> {
|
|
55
|
+
readonly input: ToolCallingAgentInput;
|
|
56
|
+
readonly emitter: Emitter<ToolCallingAgentCallbacks>;
|
|
57
|
+
constructor(input: ToolCallingAgentInput);
|
|
58
|
+
protected _run(input: ToolCallingAgentRunInput, options: ToolCallingAgentRunOptions | undefined, run: GetRunContext<typeof this>): Promise<ToolCallingAgentRunOutput>;
|
|
59
|
+
get meta(): AgentMeta;
|
|
60
|
+
protected get templates(): ToolCallingAgentTemplates;
|
|
61
|
+
createSnapshot(): {
|
|
62
|
+
input: ToolCallingAgentInput;
|
|
63
|
+
emitter: Emitter<ToolCallingAgentCallbacks>;
|
|
64
|
+
isRunning: boolean;
|
|
65
|
+
};
|
|
66
|
+
set memory(memory: BaseMemory);
|
|
67
|
+
get memory(): BaseMemory;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { ToolCallingAgent, type ToolCallingAgentInput, type ToolCallingAgentTemplateFactory };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { b as AgentMeta, a as BaseAgent } from '../../base-mmG-8Pk9.js';
|
|
2
|
+
import { AnyTool } from '../../tools/base.js';
|
|
3
|
+
import { BaseMemory } from '../../memory/base.js';
|
|
4
|
+
import { E as Emitter } from '../../emitter-BxVxGBbJ.js';
|
|
5
|
+
import { ToolCallingAgentTemplates, ToolCallingAgentExecutionConfig, ToolCallingAgentRunInput, ToolCallingAgentRunOutput, ToolCallingAgentRunOptions, ToolCallingAgentCallbacks } from './types.js';
|
|
6
|
+
import { GetRunContext } from '../../context.js';
|
|
7
|
+
import { ChatModel } from '../../backend/chat.js';
|
|
8
|
+
import '../../errors.js';
|
|
9
|
+
import '../../internals/types.js';
|
|
10
|
+
import '../../internals/helpers/guards.js';
|
|
11
|
+
import '../../internals/serializable.js';
|
|
12
|
+
import 'ajv';
|
|
13
|
+
import 'promise-based-task';
|
|
14
|
+
import '../../cache/base.js';
|
|
15
|
+
import '../../internals/helpers/schema.js';
|
|
16
|
+
import 'zod';
|
|
17
|
+
import 'zod-to-json-schema';
|
|
18
|
+
import '../../internals/helpers/promise.js';
|
|
19
|
+
import '../../backend/message.js';
|
|
20
|
+
import 'ai';
|
|
21
|
+
import './prompts.js';
|
|
22
|
+
import '../../template.js';
|
|
23
|
+
import '../../backend/utils.js';
|
|
24
|
+
import '../../backend/constants.js';
|
|
25
|
+
import '@ai-sdk/provider';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Copyright 2025 IBM Corp.
|
|
29
|
+
*
|
|
30
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
31
|
+
* you may not use this file except in compliance with the License.
|
|
32
|
+
* You may obtain a copy of the License at
|
|
33
|
+
*
|
|
34
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
35
|
+
*
|
|
36
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
37
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
38
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
39
|
+
* See the License for the specific language governing permissions and
|
|
40
|
+
* limitations under the License.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
type ToolCallingAgentTemplateFactory<K extends keyof ToolCallingAgentTemplates> = (template: ToolCallingAgentTemplates[K]) => ToolCallingAgentTemplates[K];
|
|
44
|
+
interface ToolCallingAgentInput {
|
|
45
|
+
llm: ChatModel;
|
|
46
|
+
memory: BaseMemory;
|
|
47
|
+
tools: AnyTool[];
|
|
48
|
+
meta?: Omit<AgentMeta, "tools">;
|
|
49
|
+
templates?: Partial<{
|
|
50
|
+
[K in keyof ToolCallingAgentTemplates]: ToolCallingAgentTemplates[K] | ToolCallingAgentTemplateFactory<K>;
|
|
51
|
+
}>;
|
|
52
|
+
execution?: ToolCallingAgentExecutionConfig;
|
|
53
|
+
}
|
|
54
|
+
declare class ToolCallingAgent extends BaseAgent<ToolCallingAgentRunInput, ToolCallingAgentRunOutput, ToolCallingAgentRunOptions> {
|
|
55
|
+
readonly input: ToolCallingAgentInput;
|
|
56
|
+
readonly emitter: Emitter<ToolCallingAgentCallbacks>;
|
|
57
|
+
constructor(input: ToolCallingAgentInput);
|
|
58
|
+
protected _run(input: ToolCallingAgentRunInput, options: ToolCallingAgentRunOptions | undefined, run: GetRunContext<typeof this>): Promise<ToolCallingAgentRunOutput>;
|
|
59
|
+
get meta(): AgentMeta;
|
|
60
|
+
protected get templates(): ToolCallingAgentTemplates;
|
|
61
|
+
createSnapshot(): {
|
|
62
|
+
input: ToolCallingAgentInput;
|
|
63
|
+
emitter: Emitter<ToolCallingAgentCallbacks>;
|
|
64
|
+
isRunning: boolean;
|
|
65
|
+
};
|
|
66
|
+
set memory(memory: BaseMemory);
|
|
67
|
+
get memory(): BaseMemory;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export { ToolCallingAgent, type ToolCallingAgentInput, type ToolCallingAgentTemplateFactory };
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { BaseAgent, AgentError } from '../base.js';
|
|
2
|
+
import { ToolError } from '../../tools/base.js';
|
|
3
|
+
import { Emitter } from '../../emitter/emitter.js';
|
|
4
|
+
import { shallowCopy } from '../../serializer/utils.js';
|
|
5
|
+
import { UnconstrainedMemory } from '../../memory/unconstrainedMemory.js';
|
|
6
|
+
import { SystemMessage, UserMessage, ToolMessage, AssistantMessage } from '../../backend/message.js';
|
|
7
|
+
import { isString, isEmpty } from 'remeda';
|
|
8
|
+
import { RetryCounter } from '../../internals/helpers/counter.js';
|
|
9
|
+
import { omitUndefined, mapObj } from '../../internals/helpers/object.js';
|
|
10
|
+
import { Cache } from '../../cache/decoratorCache.js';
|
|
11
|
+
import { PromptTemplate } from '../../template.js';
|
|
12
|
+
import { ToolCallingAgentTaskPrompt, ToolCallingAgentSystemPrompt } from './prompts.js';
|
|
13
|
+
import { ZodSchema } from 'zod';
|
|
14
|
+
|
|
15
|
+
var __defProp = Object.defineProperty;
|
|
16
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
17
|
+
function _ts_decorate(decorators, target, key, desc) {
|
|
18
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
19
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
20
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
21
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
22
|
+
}
|
|
23
|
+
__name(_ts_decorate, "_ts_decorate");
|
|
24
|
+
function _ts_metadata(k, v) {
|
|
25
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
26
|
+
}
|
|
27
|
+
__name(_ts_metadata, "_ts_metadata");
|
|
28
|
+
class ToolCallingAgent extends BaseAgent {
|
|
29
|
+
static {
|
|
30
|
+
__name(this, "ToolCallingAgent");
|
|
31
|
+
}
|
|
32
|
+
input;
|
|
33
|
+
emitter;
|
|
34
|
+
constructor(input) {
|
|
35
|
+
super(), this.input = input, this.emitter = Emitter.root.child({
|
|
36
|
+
namespace: [
|
|
37
|
+
"agent",
|
|
38
|
+
"toolCalling"
|
|
39
|
+
],
|
|
40
|
+
creator: this
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
static {
|
|
44
|
+
this.register();
|
|
45
|
+
}
|
|
46
|
+
async _run(input, options = {}, run) {
|
|
47
|
+
const tempMessageKey = "tempMessage";
|
|
48
|
+
const execution = {
|
|
49
|
+
totalMaxRetries: 20,
|
|
50
|
+
...omitUndefined(this.input.execution ?? {}),
|
|
51
|
+
...omitUndefined(options.execution ?? {})
|
|
52
|
+
};
|
|
53
|
+
const state = {
|
|
54
|
+
memory: new UnconstrainedMemory(),
|
|
55
|
+
result: void 0,
|
|
56
|
+
iteration: 0
|
|
57
|
+
};
|
|
58
|
+
await state.memory.add(new SystemMessage(this.templates.system.render({
|
|
59
|
+
role: void 0,
|
|
60
|
+
instructions: void 0
|
|
61
|
+
})));
|
|
62
|
+
if (input.prompt) {
|
|
63
|
+
const userMessage = new UserMessage(this.templates.task.render({
|
|
64
|
+
prompt: input.prompt,
|
|
65
|
+
context: input.context,
|
|
66
|
+
expectedOutput: isString(input.expectedOutput) ? input.expectedOutput : void 0
|
|
67
|
+
}));
|
|
68
|
+
await state.memory.add(userMessage);
|
|
69
|
+
}
|
|
70
|
+
const globalRetriesCounter = new RetryCounter(execution.totalMaxRetries || 1, AgentError);
|
|
71
|
+
while (!state.result) {
|
|
72
|
+
state.iteration++;
|
|
73
|
+
if (state.iteration > (execution.totalMaxRetries ?? Infinity)) {
|
|
74
|
+
throw new AgentError(`Agent was not able to resolve the task in ${state.iteration} iterations.`);
|
|
75
|
+
}
|
|
76
|
+
await run.emitter.emit("start", {
|
|
77
|
+
state
|
|
78
|
+
});
|
|
79
|
+
const response = await this.input.llm.create({
|
|
80
|
+
messages: state.memory.messages.slice(),
|
|
81
|
+
tools: this.input.tools,
|
|
82
|
+
stream: false
|
|
83
|
+
});
|
|
84
|
+
await state.memory.addMany(response.messages);
|
|
85
|
+
const toolCallMessages = response.getToolCalls();
|
|
86
|
+
for (const toolCall of toolCallMessages) {
|
|
87
|
+
try {
|
|
88
|
+
const tool = this.input.tools.find((tool2) => tool2.name === toolCall.toolName);
|
|
89
|
+
if (!tool) {
|
|
90
|
+
throw new AgentError(`Tool ${toolCall.toolName} does not exist!`);
|
|
91
|
+
}
|
|
92
|
+
const toolInput = toolCall.args;
|
|
93
|
+
const toolResponse = await tool.run(toolInput).context({
|
|
94
|
+
state,
|
|
95
|
+
toolCallMsg: toolCall
|
|
96
|
+
});
|
|
97
|
+
await state.memory.add(new ToolMessage({
|
|
98
|
+
type: "tool-result",
|
|
99
|
+
toolCallId: toolCall.toolCallId,
|
|
100
|
+
toolName: toolCall.toolName,
|
|
101
|
+
result: toolResponse.getTextContent(),
|
|
102
|
+
isError: false
|
|
103
|
+
}));
|
|
104
|
+
} catch (e) {
|
|
105
|
+
if (e instanceof ToolError) {
|
|
106
|
+
globalRetriesCounter.use(e);
|
|
107
|
+
await state.memory.add(new ToolMessage({
|
|
108
|
+
type: "tool-result",
|
|
109
|
+
toolCallId: toolCall.toolCallId,
|
|
110
|
+
toolName: toolCall.toolName,
|
|
111
|
+
result: e.explain(),
|
|
112
|
+
isError: true
|
|
113
|
+
}));
|
|
114
|
+
} else {
|
|
115
|
+
throw e;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const textMessages = response.getTextMessages();
|
|
120
|
+
if (isEmpty(toolCallMessages) && isEmpty(textMessages)) {
|
|
121
|
+
await state.memory.add(new AssistantMessage("\n", {
|
|
122
|
+
[tempMessageKey]: true
|
|
123
|
+
}));
|
|
124
|
+
} else {
|
|
125
|
+
await state.memory.deleteMany(state.memory.messages.filter((msg) => msg.meta[tempMessageKey]));
|
|
126
|
+
}
|
|
127
|
+
if (!isEmpty(textMessages) && isEmpty(toolCallMessages)) {
|
|
128
|
+
if (input.expectedOutput && input.expectedOutput instanceof ZodSchema) {
|
|
129
|
+
const structured = await this.input.llm.createStructure({
|
|
130
|
+
schema: input.expectedOutput,
|
|
131
|
+
messages: state.memory.messages.slice()
|
|
132
|
+
});
|
|
133
|
+
state.result = new AssistantMessage(JSON.stringify(structured, null, 4));
|
|
134
|
+
} else {
|
|
135
|
+
state.result = AssistantMessage.fromChunks(textMessages);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
await run.emitter.emit("success", {
|
|
139
|
+
state
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
await this.memory.addMany(state.memory.messages.slice(1));
|
|
143
|
+
return {
|
|
144
|
+
memory: state.memory,
|
|
145
|
+
result: state.result
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
get meta() {
|
|
149
|
+
const tools = this.input.tools.slice();
|
|
150
|
+
if (this.input.meta) {
|
|
151
|
+
return {
|
|
152
|
+
...this.input.meta,
|
|
153
|
+
tools
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return {
|
|
157
|
+
name: "ToolCalling",
|
|
158
|
+
tools,
|
|
159
|
+
description: "ToolCallingAgent that uses tools to accomplish the task.",
|
|
160
|
+
...tools.length > 0 && {
|
|
161
|
+
extraDescription: [
|
|
162
|
+
`Tools that I can use to accomplish given task.`,
|
|
163
|
+
...tools.map((tool) => `Tool '${tool.name}': ${tool.description}.`)
|
|
164
|
+
].join("\n")
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
get templates() {
|
|
169
|
+
const overrides = this.input.templates ?? {};
|
|
170
|
+
const defaultTemplates = {
|
|
171
|
+
system: ToolCallingAgentSystemPrompt,
|
|
172
|
+
task: ToolCallingAgentTaskPrompt
|
|
173
|
+
};
|
|
174
|
+
return mapObj(defaultTemplates)((key, defaultTemplate) => {
|
|
175
|
+
const override = overrides[key] ?? defaultTemplate;
|
|
176
|
+
if (override instanceof PromptTemplate) {
|
|
177
|
+
return override;
|
|
178
|
+
}
|
|
179
|
+
return override(defaultTemplate) ?? defaultTemplate;
|
|
180
|
+
});
|
|
181
|
+
}
|
|
182
|
+
createSnapshot() {
|
|
183
|
+
return {
|
|
184
|
+
...super.createSnapshot(),
|
|
185
|
+
input: shallowCopy(this.input),
|
|
186
|
+
emitter: this.emitter
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
set memory(memory) {
|
|
190
|
+
this.input.memory = memory;
|
|
191
|
+
}
|
|
192
|
+
get memory() {
|
|
193
|
+
return this.input.memory;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
_ts_decorate([
|
|
197
|
+
Cache({
|
|
198
|
+
enumerable: false
|
|
199
|
+
}),
|
|
200
|
+
_ts_metadata("design:type", typeof ToolCallingAgentTemplates === "undefined" ? Object : ToolCallingAgentTemplates),
|
|
201
|
+
_ts_metadata("design:paramtypes", [])
|
|
202
|
+
], ToolCallingAgent.prototype, "templates", null);
|
|
203
|
+
|
|
204
|
+
export { ToolCallingAgent };
|
|
205
|
+
//# sourceMappingURL=agent.js.map
|
|
206
|
+
//# sourceMappingURL=agent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["agent.ts"],"names":["ToolCallingAgent","BaseAgent","emitter","constructor","input","Emitter","root","child","namespace","creator","register","_run","options","run","tempMessageKey","execution","totalMaxRetries","omitUndefined","state","memory","UnconstrainedMemory","result","undefined","iteration","add","SystemMessage","templates","system","render","role","instructions","prompt","userMessage","UserMessage","task","context","expectedOutput","isString","globalRetriesCounter","RetryCounter","AgentError","Infinity","emit","response","llm","create","messages","slice","tools","stream","addMany","toolCallMessages","getToolCalls","toolCall","tool","find","name","toolName","toolInput","args","toolResponse","toolCallMsg","ToolMessage","type","toolCallId","getTextContent","isError","e","ToolError","use","explain","textMessages","getTextMessages","isEmpty","AssistantMessage","deleteMany","filter","msg","meta","ZodSchema","structured","createStructure","schema","JSON","stringify","fromChunks","description","length","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;;;;;AAiDM,MAAMA,yBAAyBC,SAAAA,CAAAA;EA/DtC;;;;AAoEkBC,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,QAAA,OAAA;AAAS,QAAA;;MACrBC,OAAS,EAAA;KACX,CAAA;AAIA;EAEA;AACE,IAAA,IAAA,CAAKC,QAAQ,EAAA;AACf;AAEA,EAAA,MAAgBC,IACdP,CAAAA,KAAAA,EACAQ,OAAsC,GAAA,IACtCC,GACoC,EAAA;AACpC,IAAA,MAAMC,cAAiB,GAAA,aAAA;AACvB,IAAA,MAAMC,SAAY,GAAA;MAEhBC,eAAiB,EAAA,EAAA;MAEjB,GAAGC,aAAc,CAAA,IAAA,CAAKb,KAAMW,CAAAA,SAAAA,IAAa,EAAC,CAAA;AAC1C,MAAA,GAAGE,aAAcL,CAAAA,OAAAA,CAAQG,SAAa,IAAA,EAAC;AACzC,KAAA;AAEA,IAAA,MAAMG,KAAkC,GAAA;AACtCC,MAAAA,MAAAA,EAAQ,IAAIC,mBAAAA,EAAAA;MACZC,MAAQC,EAAAA,MAAAA;MACRC,SAAW,EAAA;AACb,KAAA;AACA,IAAML,MAAAA,KAAAA,CAAMC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A,GAAAA,CAAI,CAACnC,IAAS,KAAA,CAAA,MAAA,EAASA,KAAKE,IAAI,CAAA,GAAA,EAAMF,IAAKgC,CAAAA,WAAW,CAAG,CAAA,CAAA;AAClEI,SAAAA,CAAAA,IAAAA,CAAK,IAAA;AACT;AACF,KAAA;AACF;AAEA,EAAA,IACchE,SAAuC,GAAA;AACnD,IAAA,MAAMiE,SAAY,GAAA,IAAA,CAAKvF,KAAMsB,CAAAA,SAAAA,IAAa,EAAC;AAC3C,IAAA,MAAMkE,gBAA8C,GAAA;MAClDjE,MAAQkE,EAAAA,4BAAAA;MACR3D,IAAM4D,EAAAA;AACR,KAAA;AAEA,IAAA,OAAOC,MAAOH,CAAAA,gBAAAA,CACZ,CAAA,CAACI,KAAKC,eAAAA,KAAAA;AACJ,MAAMC,MAAAA,QAAAA,GAAWP,SAAUK,CAAAA,GAAAA,CAAQC,IAAAA,eAAAA;AACnC,MAAA,IAAIC,oBAAoBC,cAAgB,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;MACThG,KAAOiG,EAAAA,WAAAA,CAAY,KAAKjG,KAAK,CAAA;AAC7BF,MAAAA,OAAAA,EAAS,IAAKA,CAAAA;AAChB,KAAA;AACF;AAEA,EAAA,IAAIiB,OAAOA,MAAoB,EAAA;AAC7B,IAAA,IAAA,CAAKf,MAAMe,MAASA,GAAAA,MAAAA;AACtB;AAEA,EAAA,IAAIA,MAAS,GAAA;AACX,IAAA,OAAO,KAAKf,KAAMe,CAAAA,MAAAA;AACpB;AACF;;;IAlCWmF,UAAY,EAAA","file":"agent.js","sourcesContent":["/**\n * Copyright 2025 IBM Corp.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { AgentError, BaseAgent } from \"@/agents/base.js\";\nimport { AnyTool, 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 { 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}\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 }\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\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 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: this.input.tools,\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 = this.input.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 if (!isEmpty(textMessages) && isEmpty(toolCallMessages)) {\n if (input.expectedOutput && input.expectedOutput instanceof ZodSchema) {\n const structured = await this.input.llm.createStructure({\n schema: input.expectedOutput,\n messages: state.memory.messages.slice(),\n });\n state.result = new AssistantMessage(JSON.stringify(structured, null, 4));\n } else {\n state.result = AssistantMessage.fromChunks(textMessages);\n }\n }\n\n await run.emitter.emit(\"success\", { state });\n }\n\n await this.memory.addMany(state.memory.messages.slice(1));\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"]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var template_cjs = require('../../template.cjs');
|
|
4
|
+
var zod = require('zod');
|
|
5
|
+
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
const ToolCallingAgentSystemPrompt = new template_cjs.PromptTemplate({
|
|
9
|
+
schema: zod.z.object({
|
|
10
|
+
role: zod.z.string(),
|
|
11
|
+
instructions: zod.z.string().optional()
|
|
12
|
+
}),
|
|
13
|
+
functions: {
|
|
14
|
+
formatDate: /* @__PURE__ */ __name(function() {
|
|
15
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
16
|
+
dateStyle: "full",
|
|
17
|
+
timeStyle: "medium"
|
|
18
|
+
}).format(/* @__PURE__ */ new Date());
|
|
19
|
+
}, "formatDate")
|
|
20
|
+
},
|
|
21
|
+
defaults: {
|
|
22
|
+
role: "A helpful AI assistant",
|
|
23
|
+
instructions: ""
|
|
24
|
+
},
|
|
25
|
+
template: `Assume the role of {{role}}.
|
|
26
|
+
{{#instructions}}
|
|
27
|
+
|
|
28
|
+
Your instructions are:
|
|
29
|
+
{{.}}
|
|
30
|
+
{{/instructions}}
|
|
31
|
+
|
|
32
|
+
When the user sends a message, figure out a solution and provide a final answer.
|
|
33
|
+
You can use tools to improve your answers if available.
|
|
34
|
+
|
|
35
|
+
# Best practices
|
|
36
|
+
- Use markdown syntax to format code snippets, links, JSON, tables, images, and files.
|
|
37
|
+
- If the provided task is unclear, ask the user for clarification.
|
|
38
|
+
- Do not refer to tools or tool outputs by name when responding.
|
|
39
|
+
|
|
40
|
+
The current date and time is: {{formatDate}}
|
|
41
|
+
`
|
|
42
|
+
});
|
|
43
|
+
const ToolCallingAgentTaskPrompt = new template_cjs.PromptTemplate({
|
|
44
|
+
schema: zod.z.object({
|
|
45
|
+
prompt: zod.z.string(),
|
|
46
|
+
context: zod.z.string().optional(),
|
|
47
|
+
expectedOutput: zod.z.string().optional()
|
|
48
|
+
}),
|
|
49
|
+
template: `{{#context}}This is the context that you are working with:
|
|
50
|
+
{{.}}
|
|
51
|
+
|
|
52
|
+
{{/context}}
|
|
53
|
+
{{#expectedOutput}}
|
|
54
|
+
This is the expected criteria for your output:
|
|
55
|
+
{{.}}
|
|
56
|
+
|
|
57
|
+
{{/expectedOutput}}
|
|
58
|
+
Your task: {{prompt}}
|
|
59
|
+
`
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
exports.ToolCallingAgentSystemPrompt = ToolCallingAgentSystemPrompt;
|
|
63
|
+
exports.ToolCallingAgentTaskPrompt = ToolCallingAgentTaskPrompt;
|
|
64
|
+
//# sourceMappingURL=prompts.cjs.map
|
|
65
|
+
//# sourceMappingURL=prompts.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["prompts.ts"],"names":["ToolCallingAgentSystemPrompt","PromptTemplate","schema","z","object","role","string","instructions","optional","functions","formatDate","Intl","DateTimeFormat","dateStyle","timeStyle","format","Date","defaults","template","ToolCallingAgentTaskPrompt","prompt","context","expectedOutput"],"mappings":";;;;;;;AAmBaA,MAAAA,4BAAAA,GAA+B,IAAIC,2BAAe,CAAA;AAC7DC,EAAAA,MAAAA,EAAQC,MAAEC,MAAO,CAAA;AACfC,IAAAA,IAAAA,EAAMF,MAAEG,MAAM,EAAA;IACdC,YAAcJ,EAAAA,KAAAA,CAAEG,MAAM,EAAA,CAAGE,QAAQ;GACnC,CAAA;EACAC,SAAW,EAAA;AACTC,IAAAA,UAAAA,kBAAY,MAAA,CAAA,WAAA;AACV,MAAO,OAAA,IAAIC,IAAKC,CAAAA,cAAAA,CAAe,OAAS,EAAA;QACtCC,SAAW,EAAA,MAAA;QACXC,SAAW,EAAA;AACb,OAAA,CAAGC,CAAAA,MAAAA,iBAAWC,IAAAA,IAAAA,EAAAA,CAAAA;KAJJ,EAAA,YAAA;AAMd,GAAA;EACAC,QAAU,EAAA;IAAEZ,IAAM,EAAA,wBAAA;IAA0BE,YAAc,EAAA;AAAG,GAAA;EAC7DW,QAAU,EAAA,CAAA;;;;;;;;;;;;;;;;;AAiBZ,CAAA;AAEaC,MAAAA,0BAAAA,GAA6B,IAAIlB,2BAAe,CAAA;AAC3DC,EAAAA,MAAAA,EAAQC,MAAEC,MAAO,CAAA;AACfgB,IAAAA,MAAAA,EAAQjB,MAAEG,MAAM,EAAA;IAChBe,OAASlB,EAAAA,KAAAA,CAAEG,MAAM,EAAA,CAAGE,QAAQ,EAAA;IAC5Bc,cAAgBnB,EAAAA,KAAAA,CAAEG,MAAM,EAAA,CAAGE,QAAQ;GACrC,CAAA;EACAU,QAAU,EAAA,CAAA;;;;;;;;;;;AAWZ,CAAA","file":"prompts.cjs","sourcesContent":["/**\n * Copyright 2025 IBM Corp.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PromptTemplate } from \"@/template.js\";\nimport { z } from \"zod\";\n\nexport const ToolCallingAgentSystemPrompt = new PromptTemplate({\n schema: z.object({\n role: z.string(),\n instructions: z.string().optional(),\n }),\n functions: {\n formatDate: function () {\n return new Intl.DateTimeFormat(\"en-US\", {\n dateStyle: \"full\",\n timeStyle: \"medium\",\n }).format(new Date());\n },\n },\n defaults: { role: \"A helpful AI assistant\", instructions: \"\" },\n template: `Assume the role of {{role}}.\n{{#instructions}}\n\nYour instructions are:\n{{.}}\n{{/instructions}}\n\nWhen the user sends a message, figure out a solution and provide a final answer.\nYou can use tools to improve your answers if available.\n\n# Best practices\n- Use markdown syntax to format code snippets, links, JSON, tables, images, and files.\n- If the provided task is unclear, ask the user for clarification.\n- Do not refer to tools or tool outputs by name when responding.\n\nThe current date and time is: {{formatDate}}\n`,\n});\n\nexport const ToolCallingAgentTaskPrompt = new PromptTemplate({\n schema: z.object({\n prompt: z.string(),\n context: z.string().optional(),\n expectedOutput: z.string().optional(),\n }),\n template: `{{#context}}This is the context that you are working with:\n{{.}}\n\n{{/context}}\n{{#expectedOutput}}\nThis is the expected criteria for your output:\n{{.}}\n\n{{/expectedOutput}}\nYour task: {{prompt}}\n`,\n});\n"]}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { PromptTemplate } from '../../template.cjs';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import '../../errors.cjs';
|
|
4
|
+
import '../../internals/types.cjs';
|
|
5
|
+
import '../../internals/helpers/guards.cjs';
|
|
6
|
+
import '../../internals/serializable.cjs';
|
|
7
|
+
import 'ajv';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Copyright 2025 IBM Corp.
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
declare const ToolCallingAgentSystemPrompt: PromptTemplate<z.ZodObject<{
|
|
26
|
+
role: z.ZodString;
|
|
27
|
+
instructions: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
role: string;
|
|
30
|
+
instructions?: string | undefined;
|
|
31
|
+
}, {
|
|
32
|
+
role: string;
|
|
33
|
+
instructions?: string | undefined;
|
|
34
|
+
}>>;
|
|
35
|
+
declare const ToolCallingAgentTaskPrompt: PromptTemplate<z.ZodObject<{
|
|
36
|
+
prompt: z.ZodString;
|
|
37
|
+
context: z.ZodOptional<z.ZodString>;
|
|
38
|
+
expectedOutput: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
prompt: string;
|
|
41
|
+
context?: string | undefined;
|
|
42
|
+
expectedOutput?: string | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
prompt: string;
|
|
45
|
+
context?: string | undefined;
|
|
46
|
+
expectedOutput?: string | undefined;
|
|
47
|
+
}>>;
|
|
48
|
+
|
|
49
|
+
export { ToolCallingAgentSystemPrompt, ToolCallingAgentTaskPrompt };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { PromptTemplate } from '../../template.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import '../../errors.js';
|
|
4
|
+
import '../../internals/types.js';
|
|
5
|
+
import '../../internals/helpers/guards.js';
|
|
6
|
+
import '../../internals/serializable.js';
|
|
7
|
+
import 'ajv';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Copyright 2025 IBM Corp.
|
|
11
|
+
*
|
|
12
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License.
|
|
14
|
+
* You may obtain a copy of the License at
|
|
15
|
+
*
|
|
16
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
19
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
20
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
21
|
+
* See the License for the specific language governing permissions and
|
|
22
|
+
* limitations under the License.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
declare const ToolCallingAgentSystemPrompt: PromptTemplate<z.ZodObject<{
|
|
26
|
+
role: z.ZodString;
|
|
27
|
+
instructions: z.ZodOptional<z.ZodString>;
|
|
28
|
+
}, "strip", z.ZodTypeAny, {
|
|
29
|
+
role: string;
|
|
30
|
+
instructions?: string | undefined;
|
|
31
|
+
}, {
|
|
32
|
+
role: string;
|
|
33
|
+
instructions?: string | undefined;
|
|
34
|
+
}>>;
|
|
35
|
+
declare const ToolCallingAgentTaskPrompt: PromptTemplate<z.ZodObject<{
|
|
36
|
+
prompt: z.ZodString;
|
|
37
|
+
context: z.ZodOptional<z.ZodString>;
|
|
38
|
+
expectedOutput: z.ZodOptional<z.ZodString>;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
prompt: string;
|
|
41
|
+
context?: string | undefined;
|
|
42
|
+
expectedOutput?: string | undefined;
|
|
43
|
+
}, {
|
|
44
|
+
prompt: string;
|
|
45
|
+
context?: string | undefined;
|
|
46
|
+
expectedOutput?: string | undefined;
|
|
47
|
+
}>>;
|
|
48
|
+
|
|
49
|
+
export { ToolCallingAgentSystemPrompt, ToolCallingAgentTaskPrompt };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { PromptTemplate } from '../../template.js';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
const ToolCallingAgentSystemPrompt = new PromptTemplate({
|
|
7
|
+
schema: z.object({
|
|
8
|
+
role: z.string(),
|
|
9
|
+
instructions: z.string().optional()
|
|
10
|
+
}),
|
|
11
|
+
functions: {
|
|
12
|
+
formatDate: /* @__PURE__ */ __name(function() {
|
|
13
|
+
return new Intl.DateTimeFormat("en-US", {
|
|
14
|
+
dateStyle: "full",
|
|
15
|
+
timeStyle: "medium"
|
|
16
|
+
}).format(/* @__PURE__ */ new Date());
|
|
17
|
+
}, "formatDate")
|
|
18
|
+
},
|
|
19
|
+
defaults: {
|
|
20
|
+
role: "A helpful AI assistant",
|
|
21
|
+
instructions: ""
|
|
22
|
+
},
|
|
23
|
+
template: `Assume the role of {{role}}.
|
|
24
|
+
{{#instructions}}
|
|
25
|
+
|
|
26
|
+
Your instructions are:
|
|
27
|
+
{{.}}
|
|
28
|
+
{{/instructions}}
|
|
29
|
+
|
|
30
|
+
When the user sends a message, figure out a solution and provide a final answer.
|
|
31
|
+
You can use tools to improve your answers if available.
|
|
32
|
+
|
|
33
|
+
# Best practices
|
|
34
|
+
- Use markdown syntax to format code snippets, links, JSON, tables, images, and files.
|
|
35
|
+
- If the provided task is unclear, ask the user for clarification.
|
|
36
|
+
- Do not refer to tools or tool outputs by name when responding.
|
|
37
|
+
|
|
38
|
+
The current date and time is: {{formatDate}}
|
|
39
|
+
`
|
|
40
|
+
});
|
|
41
|
+
const ToolCallingAgentTaskPrompt = new PromptTemplate({
|
|
42
|
+
schema: z.object({
|
|
43
|
+
prompt: z.string(),
|
|
44
|
+
context: z.string().optional(),
|
|
45
|
+
expectedOutput: z.string().optional()
|
|
46
|
+
}),
|
|
47
|
+
template: `{{#context}}This is the context that you are working with:
|
|
48
|
+
{{.}}
|
|
49
|
+
|
|
50
|
+
{{/context}}
|
|
51
|
+
{{#expectedOutput}}
|
|
52
|
+
This is the expected criteria for your output:
|
|
53
|
+
{{.}}
|
|
54
|
+
|
|
55
|
+
{{/expectedOutput}}
|
|
56
|
+
Your task: {{prompt}}
|
|
57
|
+
`
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export { ToolCallingAgentSystemPrompt, ToolCallingAgentTaskPrompt };
|
|
61
|
+
//# sourceMappingURL=prompts.js.map
|
|
62
|
+
//# sourceMappingURL=prompts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["prompts.ts"],"names":["ToolCallingAgentSystemPrompt","PromptTemplate","schema","z","object","role","string","instructions","optional","functions","formatDate","Intl","DateTimeFormat","dateStyle","timeStyle","format","Date","defaults","template","ToolCallingAgentTaskPrompt","prompt","context","expectedOutput"],"mappings":";;;;;AAmBaA,MAAAA,4BAAAA,GAA+B,IAAIC,cAAe,CAAA;AAC7DC,EAAAA,MAAAA,EAAQC,EAAEC,MAAO,CAAA;AACfC,IAAAA,IAAAA,EAAMF,EAAEG,MAAM,EAAA;IACdC,YAAcJ,EAAAA,CAAAA,CAAEG,MAAM,EAAA,CAAGE,QAAQ;GACnC,CAAA;EACAC,SAAW,EAAA;AACTC,IAAAA,UAAAA,kBAAY,MAAA,CAAA,WAAA;AACV,MAAO,OAAA,IAAIC,IAAKC,CAAAA,cAAAA,CAAe,OAAS,EAAA;QACtCC,SAAW,EAAA,MAAA;QACXC,SAAW,EAAA;AACb,OAAA,CAAGC,CAAAA,MAAAA,iBAAWC,IAAAA,IAAAA,EAAAA,CAAAA;KAJJ,EAAA,YAAA;AAMd,GAAA;EACAC,QAAU,EAAA;IAAEZ,IAAM,EAAA,wBAAA;IAA0BE,YAAc,EAAA;AAAG,GAAA;EAC7DW,QAAU,EAAA,CAAA;;;;;;;;;;;;;;;;;AAiBZ,CAAA;AAEaC,MAAAA,0BAAAA,GAA6B,IAAIlB,cAAe,CAAA;AAC3DC,EAAAA,MAAAA,EAAQC,EAAEC,MAAO,CAAA;AACfgB,IAAAA,MAAAA,EAAQjB,EAAEG,MAAM,EAAA;IAChBe,OAASlB,EAAAA,CAAAA,CAAEG,MAAM,EAAA,CAAGE,QAAQ,EAAA;IAC5Bc,cAAgBnB,EAAAA,CAAAA,CAAEG,MAAM,EAAA,CAAGE,QAAQ;GACrC,CAAA;EACAU,QAAU,EAAA,CAAA;;;;;;;;;;;AAWZ,CAAA","file":"prompts.js","sourcesContent":["/**\n * Copyright 2025 IBM Corp.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { PromptTemplate } from \"@/template.js\";\nimport { z } from \"zod\";\n\nexport const ToolCallingAgentSystemPrompt = new PromptTemplate({\n schema: z.object({\n role: z.string(),\n instructions: z.string().optional(),\n }),\n functions: {\n formatDate: function () {\n return new Intl.DateTimeFormat(\"en-US\", {\n dateStyle: \"full\",\n timeStyle: \"medium\",\n }).format(new Date());\n },\n },\n defaults: { role: \"A helpful AI assistant\", instructions: \"\" },\n template: `Assume the role of {{role}}.\n{{#instructions}}\n\nYour instructions are:\n{{.}}\n{{/instructions}}\n\nWhen the user sends a message, figure out a solution and provide a final answer.\nYou can use tools to improve your answers if available.\n\n# Best practices\n- Use markdown syntax to format code snippets, links, JSON, tables, images, and files.\n- If the provided task is unclear, ask the user for clarification.\n- Do not refer to tools or tool outputs by name when responding.\n\nThe current date and time is: {{formatDate}}\n`,\n});\n\nexport const ToolCallingAgentTaskPrompt = new PromptTemplate({\n schema: z.object({\n prompt: z.string(),\n context: z.string().optional(),\n expectedOutput: z.string().optional(),\n }),\n template: `{{#context}}This is the context that you are working with:\n{{.}}\n\n{{/context}}\n{{#expectedOutput}}\nThis is the expected criteria for your output:\n{{.}}\n\n{{/expectedOutput}}\nYour task: {{prompt}}\n`,\n});\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"types.cjs"}
|