@promptbook/fake-llm 0.105.0-1 → 0.105.0-4

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.
Files changed (39) hide show
  1. package/README.md +36 -77
  2. package/esm/index.es.js +3981 -148
  3. package/esm/index.es.js.map +1 -1
  4. package/esm/typings/src/_packages/core.index.d.ts +2 -0
  5. package/esm/typings/src/_packages/types.index.d.ts +4 -0
  6. package/esm/typings/src/book-2.0/agent-source/AgentBasicInformation.d.ts +10 -3
  7. package/esm/typings/src/book-2.0/agent-source/AgentModelRequirements.d.ts +11 -1
  8. package/esm/typings/src/book-2.0/agent-source/communication-samples.test.d.ts +1 -0
  9. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.blocks.test.d.ts +1 -0
  10. package/esm/typings/src/book-2.0/agent-source/createAgentModelRequirementsWithCommitments.import.test.d.ts +1 -0
  11. package/esm/typings/src/book-2.0/agent-source/parseAgentSource.import.test.d.ts +1 -0
  12. package/esm/typings/src/book-2.0/agent-source/parseAgentSourceWithCommitments.blocks.test.d.ts +1 -0
  13. package/esm/typings/src/commitments/USE_TIME/USE_TIME.d.ts +40 -0
  14. package/esm/typings/src/commitments/USE_TIME/USE_TIME.test.d.ts +1 -0
  15. package/esm/typings/src/commitments/_base/BaseCommitmentDefinition.d.ts +8 -0
  16. package/esm/typings/src/commitments/_base/CommitmentDefinition.d.ts +8 -0
  17. package/esm/typings/src/commitments/index.d.ts +11 -2
  18. package/esm/typings/src/config.d.ts +1 -0
  19. package/esm/typings/src/import-plugins/$fileImportPlugins.d.ts +7 -0
  20. package/esm/typings/src/import-plugins/AgentFileImportPlugin.d.ts +7 -0
  21. package/esm/typings/src/import-plugins/FileImportPlugin.d.ts +24 -0
  22. package/esm/typings/src/import-plugins/JsonFileImportPlugin.d.ts +7 -0
  23. package/esm/typings/src/import-plugins/TextFileImportPlugin.d.ts +7 -0
  24. package/esm/typings/src/llm-providers/_common/utils/cache/cacheLlmTools.d.ts +2 -1
  25. package/esm/typings/src/llm-providers/_common/utils/count-total-usage/countUsage.d.ts +2 -2
  26. package/esm/typings/src/llm-providers/agent/Agent.d.ts +9 -2
  27. package/esm/typings/src/llm-providers/agent/AgentLlmExecutionTools.d.ts +3 -1
  28. package/esm/typings/src/llm-providers/openai/OpenAiAssistantExecutionTools.d.ts +10 -0
  29. package/esm/typings/src/llm-providers/remote/RemoteLlmExecutionTools.d.ts +1 -1
  30. package/esm/typings/src/scripting/javascript/JavascriptExecutionToolsOptions.d.ts +6 -1
  31. package/esm/typings/src/types/ModelRequirements.d.ts +6 -12
  32. package/esm/typings/src/utils/execCommand/$execCommandNormalizeOptions.d.ts +2 -3
  33. package/esm/typings/src/utils/execCommand/ExecCommandOptions.d.ts +7 -1
  34. package/esm/typings/src/utils/organization/keepImported.d.ts +9 -0
  35. package/esm/typings/src/utils/organization/keepTypeImported.d.ts +0 -1
  36. package/esm/typings/src/version.d.ts +1 -1
  37. package/package.json +2 -2
  38. package/umd/index.umd.js +3981 -148
  39. package/umd/index.umd.js.map +1 -1
package/esm/index.es.js CHANGED
@@ -20,7 +20,7 @@ const BOOK_LANGUAGE_VERSION = '2.0.0';
20
20
  * @generated
21
21
  * @see https://github.com/webgptorg/promptbook
22
22
  */
23
- const PROMPTBOOK_ENGINE_VERSION = '0.105.0-1';
23
+ const PROMPTBOOK_ENGINE_VERSION = '0.105.0-4';
24
24
  /**
25
25
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
26
26
  * Note: [💞] Ignore a discrepancy between file name and entity name
@@ -1052,6 +1052,7 @@ const PROMPTBOOK_COLOR = Color.fromString('promptbook');
1052
1052
  SEPARATOR: Color.fromHex('#cccccc'),
1053
1053
  COMMITMENT: Color.fromHex('#DA0F78'),
1054
1054
  PARAMETER: Color.fromHex('#8e44ad'),
1055
+ CODE_BLOCK: Color.fromHex('#7700ffff'),
1055
1056
  });
1056
1057
  // <- TODO: [🧠][🈵] Using `Color` here increases the package size approx 3kb, maybe remove it
1057
1058
  /**
@@ -2361,6 +2362,93 @@ function normalizeTo_camelCase(text, _isFirstLetterCapital = false) {
2361
2362
  * TODO: [🌺] Use some intermediate util splitWords
2362
2363
  */
2363
2364
 
2365
+ /**
2366
+ * Tests if given string is valid file path.
2367
+ *
2368
+ * Note: This does not check if the file exists only if the path is valid
2369
+ * @public exported from `@promptbook/utils`
2370
+ */
2371
+ function isValidFilePath(filename) {
2372
+ if (typeof filename !== 'string') {
2373
+ return false;
2374
+ }
2375
+ if (filename.split('\n').length > 1) {
2376
+ return false;
2377
+ }
2378
+ // Normalize slashes early so heuristics can detect path-like inputs
2379
+ const filenameSlashes = filename.replace(/\\/g, '/');
2380
+ // Reject strings that look like sentences (informational text)
2381
+ // Heuristic: contains multiple spaces and ends with a period, or contains typical sentence punctuation
2382
+ // But skip this heuristic if the string looks like a path (contains '/' or starts with a drive letter)
2383
+ if (filename.trim().length > 60 && // long enough to be a sentence
2384
+ /[.!?]/.test(filename) && // contains sentence punctuation
2385
+ filename.split(' ').length > 8 && // has many words
2386
+ !/\/|^[A-Z]:/i.test(filenameSlashes) // do NOT treat as sentence if looks like a path
2387
+ ) {
2388
+ return false;
2389
+ }
2390
+ // Absolute Unix path: /hello.txt
2391
+ if (/^(\/)/i.test(filenameSlashes)) {
2392
+ // console.log(filename, 'Absolute Unix path: /hello.txt');
2393
+ return true;
2394
+ }
2395
+ // Absolute Windows path: C:/ or C:\ (allow spaces and multiple dots in filename)
2396
+ if (/^[A-Z]:\/.+$/i.test(filenameSlashes)) {
2397
+ // console.log(filename, 'Absolute Windows path: /hello.txt');
2398
+ return true;
2399
+ }
2400
+ // Relative path: ./hello.txt
2401
+ if (/^(\.\.?\/)+/i.test(filenameSlashes)) {
2402
+ // console.log(filename, 'Relative path: ./hello.txt');
2403
+ return true;
2404
+ }
2405
+ // Allow paths like foo/hello
2406
+ if (/^[^/]+\/[^/]+/i.test(filenameSlashes)) {
2407
+ // console.log(filename, 'Allow paths like foo/hello');
2408
+ return true;
2409
+ }
2410
+ // Allow paths like hello.book
2411
+ if (/^[^/]+\.[^/]+$/i.test(filenameSlashes)) {
2412
+ // console.log(filename, 'Allow paths like hello.book');
2413
+ return true;
2414
+ }
2415
+ return false;
2416
+ }
2417
+ /**
2418
+ * TODO: [🍏] Implement for MacOs
2419
+ */
2420
+
2421
+ /**
2422
+ * Tests if given string is valid URL.
2423
+ *
2424
+ * Note: [🔂] This function is idempotent.
2425
+ * Note: Dataurl are considered perfectly valid.
2426
+ * Note: There are few similar functions:
2427
+ * - `isValidUrl` *(this one)* which tests any URL
2428
+ * - `isValidAgentUrl` which tests just agent URL
2429
+ * - `isValidPipelineUrl` which tests just pipeline URL
2430
+ *
2431
+ * @public exported from `@promptbook/utils`
2432
+ */
2433
+ function isValidUrl(url) {
2434
+ if (typeof url !== 'string') {
2435
+ return false;
2436
+ }
2437
+ try {
2438
+ if (url.startsWith('blob:')) {
2439
+ url = url.replace(/^blob:/, '');
2440
+ }
2441
+ const urlObject = new URL(url /* because fail is handled */);
2442
+ if (!['http:', 'https:', 'data:'].includes(urlObject.protocol)) {
2443
+ return false;
2444
+ }
2445
+ return true;
2446
+ }
2447
+ catch (error) {
2448
+ return false;
2449
+ }
2450
+ }
2451
+
2364
2452
  /**
2365
2453
  * Converts a given text to kebab-case format.
2366
2454
  *
@@ -2738,192 +2826,3926 @@ function unwrapResult(text, options) {
2738
2826
  */
2739
2827
 
2740
2828
  /**
2741
- * Extracts all code blocks from markdown.
2829
+ * Tests if given string is valid agent URL
2742
2830
  *
2743
- * Note: There are multiple similar functions:
2744
- * - `extractBlock` just extracts the content of the code block which is also used as built-in function for postprocessing
2745
- * - `extractJsonBlock` extracts exactly one valid JSON code block
2746
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
2747
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2831
+ * Note: There are few similar functions:
2832
+ * - `isValidUrl` which tests any URL
2833
+ * - `isValidAgentUrl` *(this one)* which tests just agent URL
2834
+ * - `isValidPipelineUrl` which tests just pipeline URL
2748
2835
  *
2749
- * @param markdown any valid markdown
2750
- * @returns code blocks with language and content
2751
- * @throws {ParseError} if block is not closed properly
2752
- * @public exported from `@promptbook/markdown-utils`
2836
+ * @public exported from `@promptbook/utils`
2753
2837
  */
2754
- function extractAllBlocksFromMarkdown(markdown) {
2755
- const codeBlocks = [];
2756
- const lines = markdown.split('\n');
2757
- // Note: [0] Ensure that the last block notated by gt > will be closed
2758
- lines.push('');
2759
- let currentCodeBlock = null;
2760
- for (const line of lines) {
2761
- if (line.startsWith('> ') || line === '>') {
2762
- if (currentCodeBlock === null) {
2763
- currentCodeBlock = { blockNotation: '>', language: null, content: '' };
2764
- } /* not else */
2765
- if (currentCodeBlock.blockNotation === '>') {
2766
- if (currentCodeBlock.content !== '') {
2767
- currentCodeBlock.content += '\n';
2768
- }
2769
- currentCodeBlock.content += line.slice(2);
2770
- }
2771
- }
2772
- else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
2773
- codeBlocks.push(currentCodeBlock);
2774
- currentCodeBlock = null;
2775
- }
2776
- /* not else */
2777
- if (line.startsWith('```')) {
2778
- const language = line.slice(3).trim() || null;
2779
- if (currentCodeBlock === null) {
2780
- currentCodeBlock = { blockNotation: '```', language, content: '' };
2781
- }
2782
- else {
2783
- if (language !== null) {
2784
- throw new ParseError(`${capitalize(currentCodeBlock.language || 'the')} code block was not closed and already opening new ${language} code block`);
2785
- }
2786
- codeBlocks.push(currentCodeBlock);
2787
- currentCodeBlock = null;
2788
- }
2789
- }
2790
- else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
2791
- if (currentCodeBlock.content !== '') {
2792
- currentCodeBlock.content += '\n';
2793
- }
2794
- currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make proper unescape */;
2795
- }
2838
+ function isValidAgentUrl(url) {
2839
+ if (!isValidUrl(url)) {
2840
+ return false;
2796
2841
  }
2797
- if (currentCodeBlock !== null) {
2798
- throw new ParseError(`${capitalize(currentCodeBlock.language || 'the')} code block was not closed at the end of the markdown`);
2842
+ if (!url.startsWith('https://') && !url.startsWith('http://') /* <- Note: [👣] */) {
2843
+ return false;
2799
2844
  }
2800
- return codeBlocks;
2845
+ if (url.includes('#')) {
2846
+ // TODO: [🐠]
2847
+ return false;
2848
+ }
2849
+ /*
2850
+ Note: [👣][🧠] Is it secure to allow pipeline URLs on private and unsecured networks?
2851
+ if (isUrlOnPrivateNetwork(url)) {
2852
+ return false;
2853
+ }
2854
+ */
2855
+ return true;
2801
2856
  }
2802
2857
  /**
2803
- * TODO: Maybe name for `blockNotation` instead of '```' and '>'
2858
+ * TODO: [🐠] Maybe more info why the URL is invalid
2804
2859
  */
2805
2860
 
2806
2861
  /**
2807
- * Extracts exactly ONE code block from markdown.
2808
- *
2809
- * - When there are multiple or no code blocks the function throws a `ParseError`
2862
+ * Generates a regex pattern to match a specific commitment
2810
2863
  *
2811
- * Note: There are multiple similar functions:
2812
- * - `extractBlock` just extracts the content of the code block which is also used as built-in function for postprocessing
2813
- * - `extractJsonBlock` extracts exactly one valid JSON code block
2814
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
2815
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2864
+ * Note: It always creates new Regex object
2865
+ * Note: Uses word boundaries to ensure only full words are matched (e.g., "PERSONA" matches but "PERSONALITY" does not)
2816
2866
  *
2817
- * @param markdown any valid markdown
2818
- * @returns code block with language and content
2819
- * @public exported from `@promptbook/markdown-utils`
2820
- * @throws {ParseError} if there is not exactly one code block in the markdown
2867
+ * @private - TODO: [🧠] Maybe should be public?
2821
2868
  */
2822
- function extractOneBlockFromMarkdown(markdown) {
2823
- const codeBlocks = extractAllBlocksFromMarkdown(markdown);
2824
- if (codeBlocks.length !== 1) {
2825
- throw new ParseError(spaceTrim$2((block) => `
2826
- There should be exactly 1 code block in task section, found ${codeBlocks.length} code blocks
2827
-
2828
- ${block(codeBlocks.map((block, i) => `Block ${i + 1}:\n${block.content}`).join('\n\n\n'))}
2829
- `));
2869
+ function createCommitmentRegex(commitment, aliases = [], requiresContent = true) {
2870
+ const allCommitments = [commitment, ...aliases];
2871
+ const patterns = allCommitments.map((commitment) => {
2872
+ const escapedCommitment = commitment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2873
+ return escapedCommitment.split(/\s+/).join('\\s+');
2874
+ });
2875
+ const keywordPattern = patterns.join('|');
2876
+ if (requiresContent) {
2877
+ return new RegExp(`^\\s*(?<type>${keywordPattern})\\b\\s+(?<contents>.+)$`, 'gim');
2878
+ }
2879
+ else {
2880
+ return new RegExp(`^\\s*(?<type>${keywordPattern})\\b(?:\\s+(?<contents>.+))?$`, 'gim');
2830
2881
  }
2831
- return codeBlocks[0];
2832
2882
  }
2833
- /***
2834
- * TODO: [🍓][🌻] Decide of this is internal utility, external util OR validator/postprocessor
2835
- */
2836
-
2837
2883
  /**
2838
- * Extracts code block from markdown.
2839
- *
2840
- * - When there are multiple or no code blocks the function throws a `ParseError`
2884
+ * Generates a regex pattern to match a specific commitment type
2841
2885
  *
2842
- * Note: There are multiple similar function:
2843
- * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
2844
- * - `extractJsonBlock` extracts exactly one valid JSON code block
2845
- * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
2846
- * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
2886
+ * Note: It just matches the type part of the commitment
2887
+ * Note: It always creates new Regex object
2888
+ * Note: Uses word boundaries to ensure only full words are matched (e.g., "PERSONA" matches but "PERSONALITY" does not)
2847
2889
  *
2848
- * @public exported from `@promptbook/markdown-utils`
2849
- * @throws {ParseError} if there is not exactly one code block in the markdown
2890
+ * @private
2850
2891
  */
2851
- function extractBlock(markdown) {
2852
- const { content } = extractOneBlockFromMarkdown(markdown);
2853
- return content;
2892
+ function createCommitmentTypeRegex(commitment, aliases = []) {
2893
+ const allCommitments = [commitment, ...aliases];
2894
+ const patterns = allCommitments.map((commitment) => {
2895
+ const escapedCommitment = commitment.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
2896
+ return escapedCommitment.split(/\s+/).join('\\s+');
2897
+ });
2898
+ const keywordPattern = patterns.join('|');
2899
+ const regex = new RegExp(`^\\s*(?<type>${keywordPattern})\\b`, 'gim');
2900
+ return regex;
2854
2901
  }
2855
2902
 
2856
2903
  /**
2857
- * Prettify the html code
2904
+ * Base implementation of CommitmentDefinition that provides common functionality
2905
+ * Most commitments can extend this class and only override the applyToAgentModelRequirements method
2858
2906
  *
2859
- * @param content raw html code
2860
- * @returns formatted html code
2861
- * @private withing the package because of HUGE size of prettier dependency
2862
- * @deprecated Prettier removed from Promptbook due to package size
2907
+ * @private
2863
2908
  */
2864
- function prettifyMarkdown(content) {
2865
- return (content + `\n\n<!-- Note: Prettier removed from Promptbook -->`);
2909
+ class BaseCommitmentDefinition {
2910
+ constructor(type, aliases = []) {
2911
+ this.type = type;
2912
+ this.aliases = aliases;
2913
+ }
2914
+ /**
2915
+ * Whether this commitment requires content.
2916
+ * If true, regex will match only if there is content after the commitment keyword.
2917
+ * If false, regex will match even if there is no content.
2918
+ */
2919
+ get requiresContent() {
2920
+ return true;
2921
+ }
2922
+ /**
2923
+ * Creates a regex pattern to match this commitment in agent source
2924
+ * Uses the existing createCommitmentRegex function as internal helper
2925
+ */
2926
+ createRegex() {
2927
+ return createCommitmentRegex(this.type, this.aliases, this.requiresContent);
2928
+ }
2929
+ /**
2930
+ * Creates a regex pattern to match just the commitment type
2931
+ * Uses the existing createCommitmentTypeRegex function as internal helper
2932
+ */
2933
+ createTypeRegex() {
2934
+ return createCommitmentTypeRegex(this.type, this.aliases);
2935
+ }
2936
+ /**
2937
+ * Helper method to create a new requirements object with updated system message
2938
+ * This is commonly used by many commitments
2939
+ */
2940
+ updateSystemMessage(requirements, messageUpdate) {
2941
+ const newMessage = typeof messageUpdate === 'string' ? messageUpdate : messageUpdate(requirements.systemMessage);
2942
+ return {
2943
+ ...requirements,
2944
+ systemMessage: newMessage,
2945
+ };
2946
+ }
2947
+ /**
2948
+ * Helper method to append content to the system message
2949
+ */
2950
+ appendToSystemMessage(requirements, content, separator = '\n\n') {
2951
+ return this.updateSystemMessage(requirements, (currentMessage) => {
2952
+ if (!currentMessage.trim()) {
2953
+ return content;
2954
+ }
2955
+ return currentMessage + separator + content;
2956
+ });
2957
+ }
2958
+ /**
2959
+ * Helper method to add a comment section to the system message
2960
+ * Comments are lines starting with # that will be removed from the final system message
2961
+ * but can be useful for organizing and structuring the message during processing
2962
+ */
2963
+ addCommentSection(requirements, commentTitle, content, position = 'end') {
2964
+ const commentSection = `# ${commentTitle.toUpperCase()}\n${content}`;
2965
+ if (position === 'beginning') {
2966
+ return this.updateSystemMessage(requirements, (currentMessage) => {
2967
+ if (!currentMessage.trim()) {
2968
+ return commentSection;
2969
+ }
2970
+ return commentSection + '\n\n' + currentMessage;
2971
+ });
2972
+ }
2973
+ else {
2974
+ return this.appendToSystemMessage(requirements, commentSection);
2975
+ }
2976
+ }
2977
+ /**
2978
+ * Gets tool function implementations provided by this commitment
2979
+ *
2980
+ * When the `applyToAgentModelRequirements` adds tools to the requirements, this method should return the corresponding function definitions.
2981
+ */
2982
+ getToolFunctions() {
2983
+ return {};
2984
+ }
2866
2985
  }
2867
2986
 
2868
2987
  /**
2869
- * Function trimCodeBlock will trim starting and ending code block from the string if it is present.
2988
+ * ACTION commitment definition
2870
2989
  *
2871
- * Note: [🔂] This function is idempotent.
2872
- * Note: This is useful for post-processing of the result of the chat LLM model
2873
- * when the model wraps the result in the (markdown) code block.
2990
+ * The ACTION commitment defines specific actions or capabilities that the agent can perform.
2991
+ * This helps define what the agent is capable of doing and how it should approach tasks.
2874
2992
  *
2875
- * @public exported from `@promptbook/markdown-utils`
2876
- */
2877
- function trimCodeBlock(value) {
2878
- value = spaceTrim$1(value);
2879
- if (!/^```[a-z]*(.*)```$/is.test(value)) {
2880
- return value;
2881
- }
2882
- value = value.replace(/^```[a-z]*/i, '');
2883
- value = value.replace(/```$/i, '');
2884
- value = spaceTrim$1(value);
2885
- return value;
2886
- }
2887
-
2888
- /**
2889
- * Function trimEndOfCodeBlock will remove ending code block from the string if it is present.
2993
+ * Example usage in agent source:
2890
2994
  *
2891
- * Note: This is useful for post-processing of the result of the completion LLM model
2892
- * if you want to start code block in the prompt but you don't want to end it in the result.
2995
+ * ```book
2996
+ * ACTION Can generate code snippets and explain programming concepts
2997
+ * ACTION Able to analyze data and provide insights
2998
+ * ```
2893
2999
  *
2894
- * @public exported from `@promptbook/markdown-utils`
3000
+ * @private [🪔] Maybe export the commitments through some package
2895
3001
  */
2896
- function trimEndOfCodeBlock(value) {
2897
- value = spaceTrim$1(value);
2898
- value = value.replace(/```$/g, '');
2899
- value = spaceTrim$1(value);
2900
- return value;
2901
- }
3002
+ class ActionCommitmentDefinition extends BaseCommitmentDefinition {
3003
+ constructor(type = 'ACTION') {
3004
+ super(type);
3005
+ }
3006
+ /**
3007
+ * Short one-line description of ACTION.
3008
+ */
3009
+ get description() {
3010
+ return 'Define agent capabilities and actions it can perform.';
3011
+ }
3012
+ /**
3013
+ * Icon for this commitment.
3014
+ */
3015
+ get icon() {
3016
+ return '⚡';
3017
+ }
3018
+ /**
3019
+ * Markdown documentation for ACTION commitment.
3020
+ */
3021
+ get documentation() {
3022
+ return spaceTrim$1(`
3023
+ # ${this.type}
2902
3024
 
2903
- /**
2904
- * @private internal for `preserve`
2905
- */
2906
- const _preserved = [];
2907
- /**
2908
- * Does nothing, but preserves the function in the bundle
2909
- * Compiler is tricked into thinking the function is used
2910
- *
2911
- * @param value any function to preserve
2912
- * @returns nothing
2913
- * @private within the repository
2914
- */
2915
- function $preserve(...value) {
2916
- _preserved.push(...value);
3025
+ Defines specific actions or capabilities that the agent can perform.
3026
+
3027
+ ## Key aspects
3028
+
3029
+ - Both terms work identically and can be used interchangeably.
3030
+ - Each action adds to the agent's capability list.
3031
+ - Actions help users understand what the agent can do.
3032
+
3033
+ ## Examples
3034
+
3035
+ \`\`\`book
3036
+ Code Assistant
3037
+
3038
+ PERSONA You are a programming assistant
3039
+ ACTION Can generate code snippets and explain programming concepts
3040
+ ACTION Able to debug existing code and suggest improvements
3041
+ ACTION Can create unit tests for functions
3042
+ \`\`\`
3043
+
3044
+ \`\`\`book
3045
+ Data Scientist
3046
+
3047
+ PERSONA You are a data analysis expert
3048
+ ACTION Able to analyze data and provide insights
3049
+ ACTION Can create visualizations and charts
3050
+ ACTION Capable of statistical analysis and modeling
3051
+ KNOWLEDGE Data analysis best practices and statistical methods
3052
+ \`\`\`
3053
+ `);
3054
+ }
3055
+ applyToAgentModelRequirements(requirements, content) {
3056
+ const trimmedContent = content.trim();
3057
+ if (!trimmedContent) {
3058
+ return requirements;
3059
+ }
3060
+ // Add action capability to the system message
3061
+ const actionSection = `Capability: ${trimmedContent}`;
3062
+ return this.appendToSystemMessage(requirements, actionSection, '\n\n');
3063
+ }
2917
3064
  }
2918
3065
  /**
2919
3066
  * Note: [💞] Ignore a discrepancy between file name and entity name
2920
3067
  */
2921
3068
 
2922
- // Note: [💎]
2923
3069
  /**
2924
- * ScriptExecutionTools for JavaScript implemented via eval
3070
+ * CLOSED commitment definition
2925
3071
  *
2926
- * Warning: It is used for testing and mocking
3072
+ * The CLOSED commitment specifies that the agent CANNOT be modified by conversation.
3073
+ * It prevents the agent from learning from interactions and updating its source code.
3074
+ *
3075
+ * Example usage in agent source:
3076
+ *
3077
+ * ```book
3078
+ * CLOSED
3079
+ * ```
3080
+ *
3081
+ * @private [🪔] Maybe export the commitments through some package
3082
+ */
3083
+ class ClosedCommitmentDefinition extends BaseCommitmentDefinition {
3084
+ constructor() {
3085
+ super('CLOSED');
3086
+ }
3087
+ /**
3088
+ * The `CLOSED` commitment is standalone.
3089
+ */
3090
+ get requiresContent() {
3091
+ return false;
3092
+ }
3093
+ /**
3094
+ * Short one-line description of CLOSED.
3095
+ */
3096
+ get description() {
3097
+ return 'Prevent the agent from being modified by conversation.';
3098
+ }
3099
+ /**
3100
+ * Icon for this commitment.
3101
+ */
3102
+ get icon() {
3103
+ return '🔒';
3104
+ }
3105
+ /**
3106
+ * Markdown documentation for CLOSED commitment.
3107
+ */
3108
+ get documentation() {
3109
+ return spaceTrim$1(`
3110
+ # CLOSED
3111
+
3112
+ Specifies that the agent **cannot** be modified by conversation with it.
3113
+ This means the agent will **not** learn from interactions and its source code will remain static during conversation.
3114
+
3115
+ By default (if not specified), agents are \`OPEN\` to modification.
3116
+
3117
+ > See also [OPEN](/docs/OPEN)
3118
+
3119
+ ## Example
3120
+
3121
+ \`\`\`book
3122
+ CLOSED
3123
+ \`\`\`
3124
+ `);
3125
+ }
3126
+ applyToAgentModelRequirements(requirements, _content) {
3127
+ const updatedMetadata = {
3128
+ ...requirements.metadata,
3129
+ isClosed: true,
3130
+ };
3131
+ return {
3132
+ ...requirements,
3133
+ metadata: updatedMetadata,
3134
+ };
3135
+ }
3136
+ }
3137
+ /**
3138
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3139
+ */
3140
+
3141
+ /**
3142
+ * COMPONENT commitment definition
3143
+ *
3144
+ * The COMPONENT commitment defines a UI component that the agent can render in the chat.
3145
+ *
3146
+ * @private [🪔] Maybe export the commitments through some package
3147
+ */
3148
+ class ComponentCommitmentDefinition extends BaseCommitmentDefinition {
3149
+ constructor() {
3150
+ super('COMPONENT');
3151
+ }
3152
+ /**
3153
+ * Short one-line description of COMPONENT.
3154
+ */
3155
+ get description() {
3156
+ return 'Define a UI component that the agent can render in the chat.';
3157
+ }
3158
+ /**
3159
+ * Icon for this commitment.
3160
+ */
3161
+ get icon() {
3162
+ return '🧩';
3163
+ }
3164
+ /**
3165
+ * Markdown documentation for COMPONENT commitment.
3166
+ */
3167
+ get documentation() {
3168
+ return spaceTrim$1(`
3169
+ # COMPONENT
3170
+
3171
+ Defines a UI component that the agent can render in the chat.
3172
+
3173
+ ## Key aspects
3174
+
3175
+ - Tells the agent that a specific component is available.
3176
+ - Provides syntax for using the component.
3177
+
3178
+ ## Example
3179
+
3180
+ \`\`\`book
3181
+ COMPONENT Arrow
3182
+ The agent should render an arrow component in the chat UI.
3183
+ Syntax:
3184
+ <Arrow direction="up" color="red" />
3185
+ \`\`\`
3186
+ `);
3187
+ }
3188
+ applyToAgentModelRequirements(requirements, content) {
3189
+ const trimmedContent = content.trim();
3190
+ if (!trimmedContent) {
3191
+ return requirements;
3192
+ }
3193
+ // Add component capability to the system message
3194
+ const componentSection = `Component: ${trimmedContent}`;
3195
+ return this.appendToSystemMessage(requirements, componentSection, '\n\n');
3196
+ }
3197
+ }
3198
+ /**
3199
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3200
+ */
3201
+
3202
+ /**
3203
+ * DELETE commitment definition
3204
+ *
3205
+ * The DELETE commitment (and its aliases CANCEL, DISCARD, REMOVE) is used to
3206
+ * remove or disregard certain information or context. This can be useful for
3207
+ * overriding previous commitments or removing unwanted behaviors.
3208
+ *
3209
+ * Example usage in agent source:
3210
+ *
3211
+ * ```book
3212
+ * DELETE Previous formatting requirements
3213
+ * CANCEL All emotional responses
3214
+ * DISCARD Technical jargon explanations
3215
+ * REMOVE Casual conversational style
3216
+ * ```
3217
+ *
3218
+ * @private [🪔] Maybe export the commitments through some package
3219
+ */
3220
+ class DeleteCommitmentDefinition extends BaseCommitmentDefinition {
3221
+ constructor(type) {
3222
+ super(type);
3223
+ }
3224
+ /**
3225
+ * Short one-line description of DELETE/CANCEL/DISCARD/REMOVE.
3226
+ */
3227
+ get description() {
3228
+ return 'Remove or **disregard** certain information, context, or previous commitments.';
3229
+ }
3230
+ /**
3231
+ * Icon for this commitment.
3232
+ */
3233
+ get icon() {
3234
+ return '🗑️';
3235
+ }
3236
+ /**
3237
+ * Markdown documentation for DELETE commitment.
3238
+ */
3239
+ get documentation() {
3240
+ return spaceTrim$1(`
3241
+ # DELETE (CANCEL, DISCARD, REMOVE)
3242
+
3243
+ A commitment to remove or disregard certain information or context. This can be useful for overriding previous commitments or removing unwanted behaviors.
3244
+
3245
+ ## Aliases
3246
+
3247
+ - \`DELETE\` - Remove or eliminate something
3248
+ - \`CANCEL\` - Cancel or nullify something
3249
+ - \`DISCARD\` - Discard or ignore something
3250
+ - \`REMOVE\` - Remove or take away something
3251
+
3252
+ ## Key aspects
3253
+
3254
+ - Multiple delete commitments can be used to remove different aspects.
3255
+ - Useful for overriding previous commitments in the same agent definition.
3256
+ - Can be used to remove inherited behaviors from base personas.
3257
+ - Helps fine-tune agent behavior by explicitly removing unwanted elements.
3258
+
3259
+ ## Use cases
3260
+
3261
+ - Overriding inherited persona characteristics
3262
+ - Removing conflicting or outdated instructions
3263
+ - Disabling specific response patterns
3264
+ - Canceling previous formatting or style requirements
3265
+
3266
+ ## Examples
3267
+
3268
+ \`\`\`book
3269
+ Serious Business Assistant
3270
+
3271
+ PERSONA You are a friendly and casual assistant who uses emojis
3272
+ DELETE Casual conversational style
3273
+ REMOVE All emoji usage
3274
+ GOAL Provide professional business communications
3275
+ STYLE Use formal language and proper business etiquette
3276
+ \`\`\`
3277
+
3278
+ \`\`\`book
3279
+ Simplified Technical Support
3280
+
3281
+ PERSONA You are a technical support specialist with deep expertise
3282
+ KNOWLEDGE Extensive database of technical specifications
3283
+ DISCARD Technical jargon explanations
3284
+ CANCEL Advanced troubleshooting procedures
3285
+ GOAL Help users with simple, easy-to-follow solutions
3286
+ STYLE Use plain language that anyone can understand
3287
+ \`\`\`
3288
+
3289
+ \`\`\`book
3290
+ Focused Customer Service
3291
+
3292
+ PERSONA You are a customer service agent with broad knowledge
3293
+ ACTION Can help with billing, technical issues, and product information
3294
+ DELETE Billing assistance capabilities
3295
+ REMOVE Technical troubleshooting functions
3296
+ GOAL Focus exclusively on product information and general inquiries
3297
+ \`\`\`
3298
+
3299
+ \`\`\`book
3300
+ Concise Information Provider
3301
+
3302
+ PERSONA You are a helpful assistant who provides detailed explanations
3303
+ STYLE Include examples, analogies, and comprehensive context
3304
+ CANCEL Detailed explanation style
3305
+ DISCARD Examples and analogies
3306
+ GOAL Provide brief, direct answers without unnecessary elaboration
3307
+ STYLE Be concise and to the point
3308
+ \`\`\`
3309
+ `);
3310
+ }
3311
+ applyToAgentModelRequirements(requirements, content) {
3312
+ const trimmedContent = content.trim();
3313
+ if (!trimmedContent) {
3314
+ return requirements;
3315
+ }
3316
+ // Create deletion instruction for system message
3317
+ const deleteSection = `${this.type}: ${trimmedContent}`;
3318
+ // Delete instructions provide important context about what should be removed or ignored
3319
+ return this.appendToSystemMessage(requirements, deleteSection, '\n\n');
3320
+ }
3321
+ }
3322
+ /**
3323
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3324
+ */
3325
+
3326
+ /**
3327
+ * DICTIONARY commitment definition
3328
+ *
3329
+ * The DICTIONARY commitment defines specific terms and their meanings that the agent should use correctly
3330
+ * in its reasoning and responses. This ensures consistent terminology usage.
3331
+ *
3332
+ * Key features:
3333
+ * - Multiple DICTIONARY commitments are automatically merged into one
3334
+ * - Content is placed in a dedicated section of the system message
3335
+ * - Terms and definitions are stored in metadata.DICTIONARY for debugging
3336
+ * - Agent should use the defined terms correctly in responses
3337
+ *
3338
+ * Example usage in agent source:
3339
+ *
3340
+ * ```book
3341
+ * Legal Assistant
3342
+ *
3343
+ * PERSONA You are a knowledgeable legal assistant
3344
+ * DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
3345
+ * DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
3346
+ * DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
3347
+ * ```
3348
+ *
3349
+ * @private [🪔] Maybe export the commitments through some package
3350
+ */
3351
+ class DictionaryCommitmentDefinition extends BaseCommitmentDefinition {
3352
+ constructor() {
3353
+ super('DICTIONARY');
3354
+ }
3355
+ /**
3356
+ * Short one-line description of DICTIONARY.
3357
+ */
3358
+ get description() {
3359
+ return 'Define terms and their meanings for consistent terminology usage.';
3360
+ }
3361
+ /**
3362
+ * Icon for this commitment.
3363
+ */
3364
+ get icon() {
3365
+ return '📚';
3366
+ }
3367
+ /**
3368
+ * Markdown documentation for DICTIONARY commitment.
3369
+ */
3370
+ get documentation() {
3371
+ return spaceTrim$1(`
3372
+ # DICTIONARY
3373
+
3374
+ Defines specific terms and their meanings that the agent should use correctly in reasoning and responses.
3375
+
3376
+ ## Key aspects
3377
+
3378
+ - Multiple \`DICTIONARY\` commitments are merged together.
3379
+ - Terms are defined in the format: "Term is definition"
3380
+ - The agent should use these terms consistently in responses.
3381
+ - Definitions help ensure accurate and consistent terminology.
3382
+
3383
+ ## Examples
3384
+
3385
+ \`\`\`book
3386
+ Legal Assistant
3387
+
3388
+ PERSONA You are a knowledgeable legal assistant specializing in criminal law
3389
+ DICTIONARY Misdemeanor is a minor wrongdoing or criminal offense
3390
+ DICTIONARY Felony is a serious crime usually punishable by imprisonment for more than one year
3391
+ DICTIONARY Tort is a civil wrong that causes harm or loss to another person, leading to legal liability
3392
+ \`\`\`
3393
+
3394
+ \`\`\`book
3395
+ Medical Assistant
3396
+
3397
+ PERSONA You are a helpful medical assistant
3398
+ DICTIONARY Hypertension is persistently high blood pressure
3399
+ DICTIONARY Diabetes is a chronic condition that affects how the body processes blood sugar
3400
+ DICTIONARY Vaccine is a biological preparation that provides active immunity to a particular disease
3401
+ \`\`\`
3402
+ `);
3403
+ }
3404
+ applyToAgentModelRequirements(requirements, content) {
3405
+ var _a;
3406
+ const trimmedContent = content.trim();
3407
+ if (!trimmedContent) {
3408
+ return requirements;
3409
+ }
3410
+ // Get existing dictionary entries from metadata
3411
+ const existingDictionary = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.DICTIONARY) || '';
3412
+ // Merge the new dictionary entry with existing entries
3413
+ const mergedDictionary = existingDictionary ? `${existingDictionary}\n${trimmedContent}` : trimmedContent;
3414
+ // Store the merged dictionary in metadata for debugging and inspection
3415
+ const updatedMetadata = {
3416
+ ...requirements.metadata,
3417
+ DICTIONARY: mergedDictionary,
3418
+ };
3419
+ // Create the dictionary section for the system message
3420
+ // Format: "# DICTIONARY\nTerm: definition\nTerm: definition..."
3421
+ const dictionarySection = `# DICTIONARY\n${mergedDictionary}`;
3422
+ return {
3423
+ ...this.appendToSystemMessage(requirements, dictionarySection),
3424
+ metadata: updatedMetadata,
3425
+ };
3426
+ }
3427
+ }
3428
+ /**
3429
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3430
+ */
3431
+
3432
+ /**
3433
+ * FORMAT commitment definition
3434
+ *
3435
+ * The FORMAT commitment defines the specific output structure and formatting
3436
+ * that the agent should use in its responses. This includes data formats,
3437
+ * response templates, and structural requirements.
3438
+ *
3439
+ * Example usage in agent source:
3440
+ *
3441
+ * ```book
3442
+ * FORMAT Always respond in JSON format with 'status' and 'data' fields
3443
+ * FORMAT Use markdown formatting for all code blocks
3444
+ * ```
3445
+ *
3446
+ * @private [🪔] Maybe export the commitments through some package
3447
+ */
3448
+ class FormatCommitmentDefinition extends BaseCommitmentDefinition {
3449
+ constructor(type = 'FORMAT') {
3450
+ super(type);
3451
+ }
3452
+ /**
3453
+ * Short one-line description of FORMAT.
3454
+ */
3455
+ get description() {
3456
+ return 'Specify output structure or formatting requirements.';
3457
+ }
3458
+ /**
3459
+ * Icon for this commitment.
3460
+ */
3461
+ get icon() {
3462
+ return '📜';
3463
+ }
3464
+ /**
3465
+ * Markdown documentation for FORMAT commitment.
3466
+ */
3467
+ get documentation() {
3468
+ return spaceTrim$1(`
3469
+ # ${this.type}
3470
+
3471
+ Defines the specific output structure and formatting for responses (data formats, templates, structure).
3472
+
3473
+ ## Key aspects
3474
+
3475
+ - Both terms work identically and can be used interchangeably.
3476
+ - If they are in conflict, the last one takes precedence.
3477
+ - You can specify both data formats and presentation styles.
3478
+
3479
+ ## Examples
3480
+
3481
+ \`\`\`book
3482
+ Customer Support Bot
3483
+
3484
+ PERSONA You are a helpful customer support agent
3485
+ FORMAT Always respond in JSON format with 'status' and 'data' fields
3486
+ FORMAT Use markdown formatting for all code blocks
3487
+ \`\`\`
3488
+
3489
+ \`\`\`book
3490
+ Data Analyst
3491
+
3492
+ PERSONA You are a data analysis expert
3493
+ FORMAT Present results in structured tables
3494
+ FORMAT Include confidence scores for all predictions
3495
+ STYLE Be concise and precise in explanations
3496
+ \`\`\`
3497
+ `);
3498
+ }
3499
+ applyToAgentModelRequirements(requirements, content) {
3500
+ const trimmedContent = content.trim();
3501
+ if (!trimmedContent) {
3502
+ return requirements;
3503
+ }
3504
+ // Add format instructions to the system message
3505
+ const formatSection = `Output Format: ${trimmedContent}`;
3506
+ return this.appendToSystemMessage(requirements, formatSection, '\n\n');
3507
+ }
3508
+ }
3509
+ /**
3510
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3511
+ */
3512
+
3513
+ /**
3514
+ * FROM commitment definition
3515
+ *
3516
+ * The FROM commitment tells the agent that its `agentSource` is inherited from another agent.
3517
+ *
3518
+ * Example usage in agent source:
3519
+ *
3520
+ * ```book
3521
+ * FROM https://s6.ptbk.io/benjamin-white
3522
+ * ```
3523
+ *
3524
+ * @private [🪔] Maybe export the commitments through some package
3525
+ */
3526
+ class FromCommitmentDefinition extends BaseCommitmentDefinition {
3527
+ constructor(type = 'FROM') {
3528
+ super(type);
3529
+ }
3530
+ /**
3531
+ * Short one-line description of FROM.
3532
+ */
3533
+ get description() {
3534
+ return 'Inherit agent source from another agent.';
3535
+ }
3536
+ /**
3537
+ * Icon for this commitment.
3538
+ */
3539
+ get icon() {
3540
+ return '🧬';
3541
+ }
3542
+ /**
3543
+ * Markdown documentation for FROM commitment.
3544
+ */
3545
+ get documentation() {
3546
+ return spaceTrim$1(`
3547
+ # ${this.type}
3548
+
3549
+ Inherits agent source from another agent.
3550
+
3551
+ ## Examples
3552
+
3553
+ \`\`\`book
3554
+ My AI Agent
3555
+
3556
+ FROM https://s6.ptbk.io/benjamin-white
3557
+ RULE Speak only in English.
3558
+ \`\`\`
3559
+ `);
3560
+ }
3561
+ applyToAgentModelRequirements(requirements, content) {
3562
+ const trimmedContent = content.trim();
3563
+ if (!trimmedContent) {
3564
+ return {
3565
+ ...requirements,
3566
+ parentAgentUrl: undefined,
3567
+ };
3568
+ }
3569
+ if (trimmedContent.toUpperCase() === 'VOID' ||
3570
+ trimmedContent.toUpperCase() === 'NULL' ||
3571
+ trimmedContent.toUpperCase() === 'NONE' ||
3572
+ trimmedContent.toUpperCase() === 'NIL') {
3573
+ return {
3574
+ ...requirements,
3575
+ parentAgentUrl: null,
3576
+ };
3577
+ }
3578
+ if (!isValidAgentUrl(trimmedContent)) {
3579
+ throw new Error(spaceTrim$1((block) => `
3580
+ Invalid agent URL in FROM commitment: "${trimmedContent}"
3581
+
3582
+ \`\`\`book
3583
+ ${block(content)}
3584
+ \`\`\`
3585
+
3586
+
3587
+ `));
3588
+ }
3589
+ const parentAgentUrl = trimmedContent;
3590
+ return {
3591
+ ...requirements,
3592
+ parentAgentUrl,
3593
+ };
3594
+ }
3595
+ }
3596
+ /**
3597
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3598
+ */
3599
+
3600
+ /**
3601
+ * GOAL commitment definition
3602
+ *
3603
+ * The GOAL commitment defines the main goal which should be achieved by the AI assistant.
3604
+ * There can be multiple goals. Later goals are more important than earlier goals.
3605
+ *
3606
+ * Example usage in agent source:
3607
+ *
3608
+ * ```book
3609
+ * GOAL Help users understand complex technical concepts
3610
+ * GOAL Provide accurate and up-to-date information
3611
+ * GOAL Always prioritize user safety and ethical guidelines
3612
+ * ```
3613
+ *
3614
+ * @private [🪔] Maybe export the commitments through some package
3615
+ */
3616
+ class GoalCommitmentDefinition extends BaseCommitmentDefinition {
3617
+ constructor(type = 'GOAL') {
3618
+ super(type);
3619
+ }
3620
+ /**
3621
+ * Short one-line description of GOAL.
3622
+ */
3623
+ get description() {
3624
+ return 'Define main **goals** the AI assistant should achieve, with later goals having higher priority.';
3625
+ }
3626
+ /**
3627
+ * Icon for this commitment.
3628
+ */
3629
+ get icon() {
3630
+ return '🎯';
3631
+ }
3632
+ /**
3633
+ * Markdown documentation for GOAL commitment.
3634
+ */
3635
+ get documentation() {
3636
+ return spaceTrim$1(`
3637
+ # ${this.type}
3638
+
3639
+ Defines the main goal which should be achieved by the AI assistant. There can be multiple goals, and later goals are more important than earlier goals.
3640
+
3641
+ ## Key aspects
3642
+
3643
+ - Both terms work identically and can be used interchangeably.
3644
+ - Later goals have higher priority and can override earlier goals.
3645
+ - Goals provide clear direction and purpose for the agent's responses.
3646
+ - Goals influence decision-making and response prioritization.
3647
+
3648
+ ## Priority system
3649
+
3650
+ When multiple goals are defined, they are processed in order, with later goals taking precedence over earlier ones when there are conflicts.
3651
+
3652
+ ## Examples
3653
+
3654
+ \`\`\`book
3655
+ Customer Support Agent
3656
+
3657
+ PERSONA You are a helpful customer support representative
3658
+ GOAL Resolve customer issues quickly and efficiently
3659
+ GOAL Maintain high customer satisfaction scores
3660
+ GOAL Always follow company policies and procedures
3661
+ RULE Be polite and professional at all times
3662
+ \`\`\`
3663
+
3664
+ \`\`\`book
3665
+ Educational Assistant
3666
+
3667
+ PERSONA You are an educational assistant specializing in mathematics
3668
+ GOAL Help students understand mathematical concepts clearly
3669
+ GOAL Encourage critical thinking and problem-solving skills
3670
+ GOAL Ensure all explanations are age-appropriate and accessible
3671
+ STYLE Use simple language and provide step-by-step explanations
3672
+ \`\`\`
3673
+
3674
+ \`\`\`book
3675
+ Safety-First Assistant
3676
+
3677
+ PERSONA You are a general-purpose AI assistant
3678
+ GOAL Be helpful and informative in all interactions
3679
+ GOAL Provide accurate and reliable information
3680
+ GOAL Always prioritize user safety and ethical guidelines
3681
+ RULE Never provide harmful or dangerous advice
3682
+ \`\`\`
3683
+ `);
3684
+ }
3685
+ applyToAgentModelRequirements(requirements, content) {
3686
+ const trimmedContent = content.trim();
3687
+ if (!trimmedContent) {
3688
+ return requirements;
3689
+ }
3690
+ // Create goal section for system message
3691
+ const goalSection = `Goal: ${trimmedContent}`;
3692
+ // Goals are important directives, so we add them prominently to the system message
3693
+ return this.appendToSystemMessage(requirements, goalSection, '\n\n');
3694
+ }
3695
+ }
3696
+ /**
3697
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3698
+ */
3699
+
3700
+ /**
3701
+ * IMPORT commitment definition
3702
+ *
3703
+ * The IMPORT commitment tells the agent to import content from another agent at the current location.
3704
+ *
3705
+ * Example usage in agent source:
3706
+ *
3707
+ * ```book
3708
+ * IMPORT https://s6.ptbk.io/benjamin-white
3709
+ * ```
3710
+ *
3711
+ * @private [🪔] Maybe export the commitments through some package
3712
+ */
3713
+ class ImportCommitmentDefinition extends BaseCommitmentDefinition {
3714
+ constructor(type = 'IMPORT') {
3715
+ super(type);
3716
+ }
3717
+ /**
3718
+ * Short one-line description of IMPORT.
3719
+ */
3720
+ get description() {
3721
+ return 'Import content from another agent or a generic text file.';
3722
+ }
3723
+ /**
3724
+ * Icon for this commitment.
3725
+ */
3726
+ get icon() {
3727
+ return '📥';
3728
+ }
3729
+ /**
3730
+ * Markdown documentation for IMPORT commitment.
3731
+ */
3732
+ get documentation() {
3733
+ return spaceTrim$1(`
3734
+ # ${this.type}
3735
+
3736
+ Imports content from another agent or a generic text file at the location of the commitment.
3737
+
3738
+ ## Examples
3739
+
3740
+ \`\`\`book
3741
+ My AI Agent
3742
+
3743
+ IMPORT https://s6.ptbk.io/benjamin-white
3744
+ IMPORT https://example.com/some-text-file.txt
3745
+ IMPORT ./path/to/local-file.json
3746
+ RULE Speak only in English.
3747
+ \`\`\`
3748
+ `);
3749
+ }
3750
+ applyToAgentModelRequirements(requirements, content) {
3751
+ const trimmedContent = content.trim();
3752
+ if (!trimmedContent) {
3753
+ return requirements;
3754
+ }
3755
+ if (isValidAgentUrl(trimmedContent)) {
3756
+ const importedAgentUrl = trimmedContent;
3757
+ return {
3758
+ ...requirements,
3759
+ importedAgentUrls: [...(requirements.importedAgentUrls || []), importedAgentUrl],
3760
+ };
3761
+ }
3762
+ if (isValidUrl(trimmedContent) || isValidFilePath(trimmedContent)) {
3763
+ return {
3764
+ ...requirements,
3765
+ importedFileUrls: [...(requirements.importedFileUrls || []), trimmedContent],
3766
+ };
3767
+ }
3768
+ throw new Error(spaceTrim$1((block) => `
3769
+ Invalid agent URL or file path in IMPORT commitment: "${trimmedContent}"
3770
+
3771
+ \`\`\`book
3772
+ ${block(content)}
3773
+ \`\`\`
3774
+ `));
3775
+ }
3776
+ }
3777
+ /**
3778
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3779
+ */
3780
+
3781
+ /**
3782
+ * KNOWLEDGE commitment definition
3783
+ *
3784
+ * The KNOWLEDGE commitment adds specific knowledge, facts, or context to the agent
3785
+ * using RAG (Retrieval-Augmented Generation) approach for external sources.
3786
+ *
3787
+ * Supports both direct text knowledge and external sources like PDFs.
3788
+ *
3789
+ * Example usage in agent source:
3790
+ *
3791
+ * ```book
3792
+ * KNOWLEDGE The company was founded in 2020 and specializes in AI-powered solutions
3793
+ * KNOWLEDGE https://example.com/company-handbook.pdf
3794
+ * KNOWLEDGE https://example.com/product-documentation.pdf
3795
+ * ```
3796
+ *
3797
+ * @private [🪔] Maybe export the commitments through some package
3798
+ */
3799
+ class KnowledgeCommitmentDefinition extends BaseCommitmentDefinition {
3800
+ constructor() {
3801
+ super('KNOWLEDGE');
3802
+ }
3803
+ /**
3804
+ * Short one-line description of KNOWLEDGE.
3805
+ */
3806
+ get description() {
3807
+ return 'Add domain **knowledge** via direct text or external sources (RAG).';
3808
+ }
3809
+ /**
3810
+ * Icon for this commitment.
3811
+ */
3812
+ get icon() {
3813
+ return '🧠';
3814
+ }
3815
+ /**
3816
+ * Markdown documentation for KNOWLEDGE commitment.
3817
+ */
3818
+ get documentation() {
3819
+ return spaceTrim$1(`
3820
+ # ${this.type}
3821
+
3822
+ Adds specific knowledge, facts, or context to the agent using a RAG (Retrieval-Augmented Generation) approach for external sources.
3823
+
3824
+ ## Key aspects
3825
+
3826
+ - Both terms work identically and can be used interchangeably.
3827
+ - Supports both direct text knowledge and external URLs.
3828
+ - External sources (PDFs, websites) are processed via RAG for context retrieval.
3829
+
3830
+ ## Supported formats
3831
+
3832
+ - Direct text: Immediate knowledge incorporated into agent
3833
+ - URLs: External documents processed for contextual retrieval
3834
+ - Supported file types: PDF, text, markdown, HTML
3835
+
3836
+ ## Examples
3837
+
3838
+ \`\`\`book
3839
+ Customer Support Bot
3840
+
3841
+ PERSONA You are a helpful customer support agent for TechCorp
3842
+ KNOWLEDGE TechCorp was founded in 2020 and specializes in AI-powered solutions
3843
+ KNOWLEDGE https://example.com/company-handbook.pdf
3844
+ KNOWLEDGE https://example.com/product-documentation.pdf
3845
+ RULE Always be polite and professional
3846
+ \`\`\`
3847
+
3848
+ \`\`\`book
3849
+ Research Assistant
3850
+
3851
+ PERSONA You are a knowledgeable research assistant
3852
+ KNOWLEDGE Academic research requires careful citation and verification
3853
+ KNOWLEDGE https://example.com/research-guidelines.pdf
3854
+ ACTION Can help with literature reviews and data analysis
3855
+ STYLE Present information in clear, academic format
3856
+ \`\`\`
3857
+ `);
3858
+ }
3859
+ applyToAgentModelRequirements(requirements, content) {
3860
+ const trimmedContent = content.trim();
3861
+ if (!trimmedContent) {
3862
+ return requirements;
3863
+ }
3864
+ // Check if content is a URL (external knowledge source)
3865
+ if (isValidUrl(trimmedContent)) {
3866
+ // Store the URL for later async processing
3867
+ const updatedRequirements = {
3868
+ ...requirements,
3869
+ knowledgeSources: [
3870
+ ...(requirements.knowledgeSources || []),
3871
+ trimmedContent,
3872
+ ],
3873
+ };
3874
+ // Add placeholder information about knowledge sources to system message
3875
+ const knowledgeInfo = `Knowledge Source URL: ${trimmedContent} (will be processed for retrieval during chat)`;
3876
+ return this.appendToSystemMessage(updatedRequirements, knowledgeInfo, '\n\n');
3877
+ }
3878
+ else {
3879
+ // Direct text knowledge - add to system message
3880
+ const knowledgeSection = `Knowledge: ${trimmedContent}`;
3881
+ return this.appendToSystemMessage(requirements, knowledgeSection, '\n\n');
3882
+ }
3883
+ }
3884
+ }
3885
+ /**
3886
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3887
+ */
3888
+
3889
+ /**
3890
+ * LANGUAGE commitment definition
3891
+ *
3892
+ * The LANGUAGE/LANGUAGES commitment specifies the language(s) the agent should use in its responses.
3893
+ *
3894
+ * Example usage in agent source:
3895
+ *
3896
+ * ```book
3897
+ * LANGUAGE English
3898
+ * LANGUAGE French, English and Czech
3899
+ * ```
3900
+ *
3901
+ * @private [🪔] Maybe export the commitments through some package
3902
+ */
3903
+ class LanguageCommitmentDefinition extends BaseCommitmentDefinition {
3904
+ constructor(type = 'LANGUAGE') {
3905
+ super(type);
3906
+ }
3907
+ /**
3908
+ * Short one-line description of LANGUAGE/LANGUAGES.
3909
+ */
3910
+ get description() {
3911
+ return 'Specifies the language(s) the agent should use.';
3912
+ }
3913
+ /**
3914
+ * Icon for this commitment.
3915
+ */
3916
+ get icon() {
3917
+ return '🌐';
3918
+ }
3919
+ /**
3920
+ * Markdown documentation for LANGUAGE/LANGUAGES commitment.
3921
+ */
3922
+ get documentation() {
3923
+ return spaceTrim$1(`
3924
+ # ${this.type}
3925
+
3926
+ Specifies the language(s) the agent should use in its responses.
3927
+ This is a specialized variation of the RULE commitment focused on language constraints.
3928
+
3929
+ ## Examples
3930
+
3931
+ \`\`\`book
3932
+ Paul Smith & Associés
3933
+
3934
+ PERSONA You are a company lawyer.
3935
+ LANGUAGE French, English and Czech
3936
+ \`\`\`
3937
+
3938
+ \`\`\`book
3939
+ Customer Support
3940
+
3941
+ PERSONA You are a customer support agent.
3942
+ LANGUAGE English
3943
+ \`\`\`
3944
+ `);
3945
+ }
3946
+ applyToAgentModelRequirements(requirements, content) {
3947
+ const trimmedContent = content.trim();
3948
+ if (!trimmedContent) {
3949
+ return requirements;
3950
+ }
3951
+ // Add language rule to the system message
3952
+ const languageSection = `Language: ${trimmedContent}`;
3953
+ return this.appendToSystemMessage(requirements, languageSection, '\n\n');
3954
+ }
3955
+ }
3956
+ /**
3957
+ * Note: [💞] Ignore a discrepancy between file name and entity name
3958
+ */
3959
+
3960
+ /**
3961
+ * MEMORY commitment definition
3962
+ *
3963
+ * The MEMORY commitment is similar to KNOWLEDGE but has a focus on remembering past
3964
+ * interactions and user preferences. It helps the agent maintain context about the
3965
+ * user's history, preferences, and previous conversations.
3966
+ *
3967
+ * Example usage in agent source:
3968
+ *
3969
+ * ```book
3970
+ * MEMORY User prefers detailed technical explanations
3971
+ * MEMORY Previously worked on React projects
3972
+ * MEMORY Timezone: UTC-5 (Eastern Time)
3973
+ * ```
3974
+ *
3975
+ * @private [🪔] Maybe export the commitments through some package
3976
+ */
3977
+ class MemoryCommitmentDefinition extends BaseCommitmentDefinition {
3978
+ constructor(type = 'MEMORY') {
3979
+ super(type);
3980
+ }
3981
+ /**
3982
+ * Short one-line description of MEMORY.
3983
+ */
3984
+ get description() {
3985
+ return 'Remember past interactions and user **preferences** for personalized responses.';
3986
+ }
3987
+ /**
3988
+ * Icon for this commitment.
3989
+ */
3990
+ get icon() {
3991
+ return '🧠';
3992
+ }
3993
+ /**
3994
+ * Markdown documentation for MEMORY commitment.
3995
+ */
3996
+ get documentation() {
3997
+ return spaceTrim$1(`
3998
+ # ${this.type}
3999
+
4000
+ Similar to KNOWLEDGE but focuses on remembering past interactions and user preferences. This commitment helps the agent maintain context about the user's history, preferences, and previous conversations.
4001
+
4002
+ ## Key aspects
4003
+
4004
+ - Both terms work identically and can be used interchangeably.
4005
+ - Focuses on user-specific information and interaction history.
4006
+ - Helps personalize responses based on past interactions.
4007
+ - Maintains continuity across conversations.
4008
+
4009
+ ## Differences from KNOWLEDGE
4010
+
4011
+ - \`KNOWLEDGE\` is for domain expertise and factual information
4012
+ - \`MEMORY\` is for user-specific context and preferences
4013
+ - \`MEMORY\` creates more personalized interactions
4014
+ - \`MEMORY\` often includes temporal or preference-based information
4015
+
4016
+ ## Examples
4017
+
4018
+ \`\`\`book
4019
+ Personal Assistant
4020
+
4021
+ PERSONA You are a personal productivity assistant
4022
+ MEMORY User is a software developer working in JavaScript/React
4023
+ MEMORY User prefers morning work sessions and afternoon meetings
4024
+ MEMORY Previously helped with project planning for mobile apps
4025
+ MEMORY User timezone: UTC-8 (Pacific Time)
4026
+ GOAL Help optimize daily productivity and workflow
4027
+ \`\`\`
4028
+
4029
+ \`\`\`book
4030
+ Learning Companion
4031
+
4032
+ PERSONA You are an educational companion for programming students
4033
+ MEMORY Student is learning Python as their first programming language
4034
+ MEMORY Previous topics covered: variables, loops, functions
4035
+ MEMORY Student learns best with practical examples and exercises
4036
+ MEMORY Last session: working on list comprehensions
4037
+ GOAL Provide progressive learning experiences tailored to student's pace
4038
+ \`\`\`
4039
+
4040
+ \`\`\`book
4041
+ Customer Support Agent
4042
+
4043
+ PERSONA You are a customer support representative
4044
+ MEMORY Customer has premium subscription since 2023
4045
+ MEMORY Previous issue: billing question resolved last month
4046
+ MEMORY Customer prefers email communication over phone calls
4047
+ MEMORY Account shows frequent use of advanced features
4048
+ GOAL Provide personalized support based on customer history
4049
+ \`\`\`
4050
+ `);
4051
+ }
4052
+ applyToAgentModelRequirements(requirements, content) {
4053
+ const trimmedContent = content.trim();
4054
+ if (!trimmedContent) {
4055
+ return requirements;
4056
+ }
4057
+ // Create memory section for system message
4058
+ const memorySection = `Memory: ${trimmedContent}`;
4059
+ // Memory information is contextual and should be included in the system message
4060
+ return this.appendToSystemMessage(requirements, memorySection, '\n\n');
4061
+ }
4062
+ }
4063
+ /**
4064
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4065
+ */
4066
+
4067
+ /**
4068
+ * AGENT MESSAGE commitment definition
4069
+ *
4070
+ * The AGENT MESSAGE commitment defines a message from the agent in the conversation history.
4071
+ * It is used to pre-fill the chat with a conversation history or to provide few-shot examples.
4072
+ *
4073
+ * Example usage in agent source:
4074
+ *
4075
+ * ```book
4076
+ * AGENT MESSAGE What seems to be the issue?
4077
+ * ```
4078
+ *
4079
+ * @private [🪔] Maybe export the commitments through some package
4080
+ */
4081
+ class AgentMessageCommitmentDefinition extends BaseCommitmentDefinition {
4082
+ constructor() {
4083
+ super('AGENT MESSAGE');
4084
+ }
4085
+ /**
4086
+ * Short one-line description of AGENT MESSAGE.
4087
+ */
4088
+ get description() {
4089
+ return 'Defines a **message from the agent** in the conversation history.';
4090
+ }
4091
+ /**
4092
+ * Icon for this commitment.
4093
+ */
4094
+ get icon() {
4095
+ return '🤖';
4096
+ }
4097
+ /**
4098
+ * Markdown documentation for AGENT MESSAGE commitment.
4099
+ */
4100
+ get documentation() {
4101
+ return spaceTrim$1(`
4102
+ # ${this.type}
4103
+
4104
+ Defines a message from the agent in the conversation history. This is used to pre-fill the chat with a conversation history or to provide few-shot examples.
4105
+
4106
+ ## Key aspects
4107
+
4108
+ - Represents a message sent by the agent.
4109
+ - Used for setting up conversation context.
4110
+ - Can be used in conjunction with USER MESSAGE.
4111
+
4112
+ ## Examples
4113
+
4114
+ \`\`\`book
4115
+ Conversation History
4116
+
4117
+ USER MESSAGE Hello, I have a problem.
4118
+ AGENT MESSAGE What seems to be the issue?
4119
+ USER MESSAGE My computer is not starting.
4120
+ \`\`\`
4121
+ `);
4122
+ }
4123
+ applyToAgentModelRequirements(requirements, content) {
4124
+ // AGENT MESSAGE is for UI display purposes / conversation history construction
4125
+ // and typically doesn't need to be added to the system prompt or model requirements directly.
4126
+ // It is extracted separately for the chat interface.
4127
+ var _a;
4128
+ const pendingUserMessage = (_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.pendingUserMessage;
4129
+ if (pendingUserMessage) {
4130
+ const newSample = { question: pendingUserMessage, answer: content };
4131
+ const newSamples = [...(requirements.samples || []), newSample];
4132
+ const newMetadata = { ...requirements.metadata };
4133
+ delete newMetadata.pendingUserMessage;
4134
+ return {
4135
+ ...requirements,
4136
+ samples: newSamples,
4137
+ metadata: newMetadata,
4138
+ };
4139
+ }
4140
+ return requirements;
4141
+ }
4142
+ }
4143
+
4144
+ /**
4145
+ * INITIAL MESSAGE commitment definition
4146
+ *
4147
+ * The INITIAL MESSAGE commitment defines the first message that the user sees when opening the chat.
4148
+ * It is used to greet the user and set the tone of the conversation.
4149
+ *
4150
+ * Example usage in agent source:
4151
+ *
4152
+ * ```book
4153
+ * INITIAL MESSAGE Hello! I am ready to help you with your tasks.
4154
+ * ```
4155
+ *
4156
+ * @private [🪔] Maybe export the commitments through some package
4157
+ */
4158
+ class InitialMessageCommitmentDefinition extends BaseCommitmentDefinition {
4159
+ constructor() {
4160
+ super('INITIAL MESSAGE');
4161
+ }
4162
+ /**
4163
+ * Short one-line description of INITIAL MESSAGE.
4164
+ */
4165
+ get description() {
4166
+ return 'Defines the **initial message** shown to the user when the chat starts.';
4167
+ }
4168
+ /**
4169
+ * Icon for this commitment.
4170
+ */
4171
+ get icon() {
4172
+ return '👋';
4173
+ }
4174
+ /**
4175
+ * Markdown documentation for INITIAL MESSAGE commitment.
4176
+ */
4177
+ get documentation() {
4178
+ return spaceTrim$1(`
4179
+ # ${this.type}
4180
+
4181
+ Defines the first message that the user sees when opening the chat. This message is purely for display purposes in the UI and does not inherently become part of the LLM's system prompt context (unless also included via other means).
4182
+
4183
+ ## Key aspects
4184
+
4185
+ - Used to greet the user.
4186
+ - Sets the tone of the conversation.
4187
+ - Displayed immediately when the chat interface loads.
4188
+
4189
+ ## Examples
4190
+
4191
+ \`\`\`book
4192
+ Support Agent
4193
+
4194
+ PERSONA You are a helpful support agent.
4195
+ INITIAL MESSAGE Hi there! How can I assist you today?
4196
+ \`\`\`
4197
+ `);
4198
+ }
4199
+ applyToAgentModelRequirements(requirements, content) {
4200
+ // INITIAL MESSAGE is for UI display purposes and for conversation history construction.
4201
+ const newSample = { question: null, answer: content };
4202
+ const newSamples = [...(requirements.samples || []), newSample];
4203
+ return {
4204
+ ...requirements,
4205
+ samples: newSamples,
4206
+ };
4207
+ }
4208
+ }
4209
+
4210
+ /**
4211
+ * MESSAGE commitment definition
4212
+ *
4213
+ * The MESSAGE commitment contains 1:1 text of the message which AI assistant already
4214
+ * sent during the conversation. Later messages are later in the conversation.
4215
+ * It is similar to EXAMPLE but it is not example, it is the real message which
4216
+ * AI assistant already sent.
4217
+ *
4218
+ * Example usage in agent source:
4219
+ *
4220
+ * ```book
4221
+ * MESSAGE Hello! How can I help you today?
4222
+ * MESSAGE I understand you're looking for information about our services.
4223
+ * MESSAGE Based on your requirements, I'd recommend our premium package.
4224
+ * ```
4225
+ *
4226
+ * @private [🪔] Maybe export the commitments through some package
4227
+ */
4228
+ class MessageCommitmentDefinition extends BaseCommitmentDefinition {
4229
+ constructor(type = 'MESSAGE') {
4230
+ super(type);
4231
+ }
4232
+ /**
4233
+ * Short one-line description of MESSAGE.
4234
+ */
4235
+ get description() {
4236
+ return 'Include actual **messages** the AI assistant has sent during conversation history.';
4237
+ }
4238
+ /**
4239
+ * Icon for this commitment.
4240
+ */
4241
+ get icon() {
4242
+ return '💬';
4243
+ }
4244
+ /**
4245
+ * Markdown documentation for MESSAGE commitment.
4246
+ */
4247
+ get documentation() {
4248
+ return spaceTrim$1(`
4249
+ # ${this.type}
4250
+
4251
+ Contains 1:1 text of the message which AI assistant already sent during the conversation. Later messages are later in the conversation. It is similar to EXAMPLE but it is not example, it is the real message which AI assistant already sent.
4252
+
4253
+ ## Key aspects
4254
+
4255
+ - Multiple \`MESSAGE\` and \`MESSAGES\` commitments represent the conversation timeline.
4256
+ - Both terms work identically and can be used interchangeably.
4257
+ - Later messages are later in the conversation chronologically.
4258
+ - Contains actual historical messages, not examples or templates.
4259
+ - Helps maintain conversation continuity and context.
4260
+
4261
+ ## Differences from EXAMPLE
4262
+
4263
+ - \`EXAMPLE\` shows hypothetical or template responses
4264
+ - \`MESSAGE\`/\`MESSAGES\` contains actual historical conversation content
4265
+ - \`MESSAGE\`/\`MESSAGES\` preserves the exact conversation flow
4266
+ - \`MESSAGE\`/\`MESSAGES\` helps with context awareness and consistency
4267
+
4268
+ ## Use cases
4269
+
4270
+ - Maintaining conversation history context
4271
+ - Ensuring consistent tone and style across messages
4272
+ - Referencing previous responses in ongoing conversations
4273
+ - Building upon previously established context
4274
+
4275
+ ## Examples
4276
+
4277
+ \`\`\`book
4278
+ Customer Support Continuation
4279
+
4280
+ PERSONA You are a helpful customer support agent
4281
+ MESSAGE Hello! How can I help you today?
4282
+ MESSAGE I understand you're experiencing issues with your account login.
4283
+ MESSAGE I've sent you a password reset link to your email address.
4284
+ MESSAGE Is there anything else I can help you with regarding your account?
4285
+ GOAL Continue providing consistent support based on conversation history
4286
+ \`\`\`
4287
+
4288
+ \`\`\`book
4289
+ Technical Discussion
4290
+
4291
+ PERSONA You are a software development mentor
4292
+ MESSAGE Let's start by reviewing the React component structure you shared.
4293
+ MESSAGE I notice you're using class components - have you considered hooks?
4294
+ MESSAGE Here's how you could refactor that using the useState hook.
4295
+ MESSAGE Great question about performance! Let me explain React's rendering cycle.
4296
+ KNOWLEDGE React hooks were introduced in version 16.8
4297
+ \`\`\`
4298
+
4299
+ \`\`\`book
4300
+ Educational Session
4301
+
4302
+ PERSONA You are a mathematics tutor
4303
+ MESSAGE Today we'll work on solving quadratic equations.
4304
+ MESSAGE Let's start with the basic form: ax² + bx + c = 0
4305
+ MESSAGE Remember, we can use the quadratic formula or factoring.
4306
+ MESSAGE You did great with that first problem! Let's try a more complex one.
4307
+ GOAL Build upon previous explanations for deeper understanding
4308
+ \`\`\`
4309
+ `);
4310
+ }
4311
+ applyToAgentModelRequirements(requirements, content) {
4312
+ const trimmedContent = content.trim();
4313
+ if (!trimmedContent) {
4314
+ return requirements;
4315
+ }
4316
+ // Create message section for system message
4317
+ const messageSection = `Previous Message: ${trimmedContent}`;
4318
+ // Messages represent conversation history and should be included for context
4319
+ return this.appendToSystemMessage(requirements, messageSection, '\n\n');
4320
+ }
4321
+ }
4322
+ /**
4323
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4324
+ */
4325
+
4326
+ /**
4327
+ * USER MESSAGE commitment definition
4328
+ *
4329
+ * The USER MESSAGE commitment defines a message from the user in the conversation history.
4330
+ * It is used to pre-fill the chat with a conversation history or to provide few-shot examples.
4331
+ *
4332
+ * Example usage in agent source:
4333
+ *
4334
+ * ```book
4335
+ * USER MESSAGE Hello, I have a problem.
4336
+ * ```
4337
+ *
4338
+ * @private [🪔] Maybe export the commitments through some package
4339
+ */
4340
+ class UserMessageCommitmentDefinition extends BaseCommitmentDefinition {
4341
+ constructor() {
4342
+ super('USER MESSAGE');
4343
+ }
4344
+ /**
4345
+ * Short one-line description of USER MESSAGE.
4346
+ */
4347
+ get description() {
4348
+ return 'Defines a **message from the user** in the conversation history.';
4349
+ }
4350
+ /**
4351
+ * Icon for this commitment.
4352
+ */
4353
+ get icon() {
4354
+ return '🧑';
4355
+ }
4356
+ /**
4357
+ * Markdown documentation for USER MESSAGE commitment.
4358
+ */
4359
+ get documentation() {
4360
+ return spaceTrim$1(`
4361
+ # ${this.type}
4362
+
4363
+ Defines a message from the user in the conversation history. This is used to pre-fill the chat with a conversation history or to provide few-shot examples.
4364
+
4365
+ ## Key aspects
4366
+
4367
+ - Represents a message sent by the user.
4368
+ - Used for setting up conversation context.
4369
+ - Can be used in conjunction with AGENT MESSAGE.
4370
+
4371
+ ## Examples
4372
+
4373
+ \`\`\`book
4374
+ Conversation History
4375
+
4376
+ USER MESSAGE Hello, I have a problem.
4377
+ AGENT MESSAGE What seems to be the issue?
4378
+ USER MESSAGE My computer is not starting.
4379
+ \`\`\`
4380
+ `);
4381
+ }
4382
+ applyToAgentModelRequirements(requirements, content) {
4383
+ return {
4384
+ ...requirements,
4385
+ metadata: {
4386
+ ...requirements.metadata,
4387
+ pendingUserMessage: content,
4388
+ },
4389
+ };
4390
+ }
4391
+ }
4392
+
4393
+ /**
4394
+ * META commitment definition
4395
+ *
4396
+ * The META commitment handles all meta-information about the agent such as:
4397
+ * - META IMAGE: Sets the agent's avatar/profile image URL
4398
+ * - META LINK: Provides profile/source links for the person the agent models
4399
+ * - META TITLE: Sets the agent's display title
4400
+ * - META DESCRIPTION: Sets the agent's description
4401
+ * - META [ANYTHING]: Any other meta information in uppercase format
4402
+ *
4403
+ * These commitments are special because they don't affect the system message,
4404
+ * but are handled separately in the parsing logic for profile display.
4405
+ *
4406
+ * Example usage in agent source:
4407
+ *
4408
+ * ```book
4409
+ * META IMAGE https://example.com/avatar.jpg
4410
+ * META LINK https://twitter.com/username
4411
+ * META TITLE Professional Assistant
4412
+ * META DESCRIPTION An AI assistant specialized in business tasks
4413
+ * META AUTHOR John Doe
4414
+ * META VERSION 1.0
4415
+ * ```
4416
+ *
4417
+ * @private [🪔] Maybe export the commitments through some package
4418
+ */
4419
+ class MetaCommitmentDefinition extends BaseCommitmentDefinition {
4420
+ constructor() {
4421
+ super('META');
4422
+ }
4423
+ /**
4424
+ * Short one-line description of META commitments.
4425
+ */
4426
+ get description() {
4427
+ return 'Set meta-information about the agent (IMAGE, LINK, TITLE, DESCRIPTION, etc.).';
4428
+ }
4429
+ /**
4430
+ * Icon for this commitment.
4431
+ */
4432
+ get icon() {
4433
+ return 'ℹ️';
4434
+ }
4435
+ /**
4436
+ * Markdown documentation for META commitment.
4437
+ */
4438
+ get documentation() {
4439
+ return spaceTrim$1(`
4440
+ # META
4441
+
4442
+ Sets meta-information about the agent that is used for display and attribution purposes.
4443
+
4444
+ ## Supported META types
4445
+
4446
+ - **META IMAGE** - Sets the agent's avatar/profile image URL
4447
+ - **META LINK** - Provides profile/source links for the person the agent models
4448
+ - **META TITLE** - Sets the agent's display title
4449
+ - **META DESCRIPTION** - Sets the agent's description
4450
+ - **META [ANYTHING]** - Any other meta information in uppercase format
4451
+
4452
+ ## Key aspects
4453
+
4454
+ - Does not modify the agent's behavior or responses
4455
+ - Used for visual representation and attribution in user interfaces
4456
+ - Multiple META commitments of different types can be used
4457
+ - Multiple META LINK commitments can be used for different social profiles
4458
+ - If multiple META commitments of the same type are specified, the last one takes precedence (except for LINK)
4459
+
4460
+ ## Examples
4461
+
4462
+ ### Basic meta information
4463
+
4464
+ \`\`\`book
4465
+ Professional Assistant
4466
+
4467
+ META IMAGE https://example.com/professional-avatar.jpg
4468
+ META TITLE Senior Business Consultant
4469
+ META DESCRIPTION Specialized in strategic planning and project management
4470
+ META LINK https://linkedin.com/in/professional
4471
+ \`\`\`
4472
+
4473
+ ### Multiple links and custom meta
4474
+
4475
+ \`\`\`book
4476
+ Open Source Developer
4477
+
4478
+ META IMAGE /assets/dev-avatar.png
4479
+ META LINK https://github.com/developer
4480
+ META LINK https://twitter.com/devhandle
4481
+ META AUTHOR Jane Smith
4482
+ META VERSION 2.1
4483
+ META LICENSE MIT
4484
+ \`\`\`
4485
+
4486
+ ### Creative assistant
4487
+
4488
+ \`\`\`book
4489
+ Creative Helper
4490
+
4491
+ META IMAGE https://example.com/creative-bot.jpg
4492
+ META TITLE Creative Writing Assistant
4493
+ META DESCRIPTION Helps with brainstorming, storytelling, and creative projects
4494
+ META INSPIRATION Books, movies, and real-world experiences
4495
+ \`\`\`
4496
+ `);
4497
+ }
4498
+ applyToAgentModelRequirements(requirements, content) {
4499
+ // META commitments don't modify the system message or model requirements
4500
+ // They are handled separately in the parsing logic for meta information extraction
4501
+ // This method exists for consistency with the CommitmentDefinition interface
4502
+ return requirements;
4503
+ }
4504
+ /**
4505
+ * Extracts meta information from the content based on the meta type
4506
+ * This is used by the parsing logic
4507
+ */
4508
+ extractMetaValue(metaType, content) {
4509
+ const trimmedContent = content.trim();
4510
+ return trimmedContent || null;
4511
+ }
4512
+ /**
4513
+ * Validates if the provided content is a valid URL (for IMAGE and LINK types)
4514
+ */
4515
+ isValidUrl(content) {
4516
+ try {
4517
+ new URL(content.trim());
4518
+ return true;
4519
+ }
4520
+ catch (_a) {
4521
+ return false;
4522
+ }
4523
+ }
4524
+ /**
4525
+ * Checks if this is a known meta type
4526
+ */
4527
+ isKnownMetaType(metaType) {
4528
+ const knownTypes = ['IMAGE', 'LINK', 'TITLE', 'DESCRIPTION', 'AUTHOR', 'VERSION', 'LICENSE'];
4529
+ return knownTypes.includes(metaType.toUpperCase());
4530
+ }
4531
+ }
4532
+ /**
4533
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4534
+ */
4535
+
4536
+ /**
4537
+ * META COLOR commitment definition
4538
+ *
4539
+ * The META COLOR commitment sets the agent's accent color.
4540
+ * This commitment is special because it doesn't affect the system message,
4541
+ * but is handled separately in the parsing logic.
4542
+ *
4543
+ * Example usage in agent source:
4544
+ *
4545
+ * ```book
4546
+ * META COLOR #ff0000
4547
+ * META COLOR #00ff00
4548
+ * ```
4549
+ *
4550
+ * You can also specify multiple colors separated by comma:
4551
+ *
4552
+ * ```book
4553
+ * META COLOR #ff0000, #00ff00, #0000ff
4554
+ * ```
4555
+ *
4556
+ * @private [🪔] Maybe export the commitments through some package
4557
+ */
4558
+ class MetaColorCommitmentDefinition extends BaseCommitmentDefinition {
4559
+ constructor() {
4560
+ super('META COLOR', ['COLOR']);
4561
+ }
4562
+ /**
4563
+ * Short one-line description of META COLOR.
4564
+ */
4565
+ get description() {
4566
+ return "Set the agent's accent color or gradient.";
4567
+ }
4568
+ /**
4569
+ * Icon for this commitment.
4570
+ */
4571
+ get icon() {
4572
+ return '🎨';
4573
+ }
4574
+ /**
4575
+ * Markdown documentation for META COLOR commitment.
4576
+ */
4577
+ get documentation() {
4578
+ return spaceTrim$1(`
4579
+ # META COLOR
4580
+
4581
+ Sets the agent's accent color or gradient.
4582
+
4583
+ ## Key aspects
4584
+
4585
+ - Does not modify the agent's behavior or responses.
4586
+ - Only one \`META COLOR\` should be used per agent.
4587
+ - If multiple are specified, the last one takes precedence.
4588
+ - Used for visual representation in user interfaces.
4589
+ - Can specify multiple colors separated by comma to create a gradient.
4590
+
4591
+ ## Examples
4592
+
4593
+ \`\`\`book
4594
+ Professional Assistant
4595
+
4596
+ META COLOR #3498db
4597
+ PERSONA You are a professional business assistant
4598
+ \`\`\`
4599
+
4600
+ \`\`\`book
4601
+ Creative Helper
4602
+
4603
+ META COLOR #e74c3c
4604
+ PERSONA You are a creative and inspiring assistant
4605
+ \`\`\`
4606
+
4607
+ \`\`\`book
4608
+ Gradient Agent
4609
+
4610
+ META COLOR #ff0000, #00ff00, #0000ff
4611
+ PERSONA You are a colorful agent
4612
+ \`\`\`
4613
+ `);
4614
+ }
4615
+ applyToAgentModelRequirements(requirements, content) {
4616
+ // META COLOR doesn't modify the system message or model requirements
4617
+ // It's handled separately in the parsing logic for profile color extraction
4618
+ // This method exists for consistency with the CommitmentDefinition interface
4619
+ return requirements;
4620
+ }
4621
+ /**
4622
+ * Extracts the profile color from the content
4623
+ * This is used by the parsing logic
4624
+ */
4625
+ extractProfileColor(content) {
4626
+ const trimmedContent = content.trim();
4627
+ return trimmedContent || null;
4628
+ }
4629
+ }
4630
+ /**
4631
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4632
+ */
4633
+
4634
+ /**
4635
+ * META FONT commitment definition
4636
+ *
4637
+ * The META FONT commitment sets the agent's font.
4638
+ * This commitment is special because it doesn't affect the system message,
4639
+ * but is handled separately in the parsing logic.
4640
+ *
4641
+ * Example usage in agent source:
4642
+ *
4643
+ * ```book
4644
+ * META FONT Poppins, Arial, sans-serif
4645
+ * META FONT Roboto
4646
+ * ```
4647
+ *
4648
+ * @private [🪔] Maybe export the commitments through some package
4649
+ */
4650
+ class MetaFontCommitmentDefinition extends BaseCommitmentDefinition {
4651
+ constructor() {
4652
+ super('META FONT', ['FONT']);
4653
+ }
4654
+ /**
4655
+ * Short one-line description of META FONT.
4656
+ */
4657
+ get description() {
4658
+ return "Set the agent's font.";
4659
+ }
4660
+ /**
4661
+ * Icon for this commitment.
4662
+ */
4663
+ get icon() {
4664
+ return '🔤';
4665
+ }
4666
+ /**
4667
+ * Markdown documentation for META FONT commitment.
4668
+ */
4669
+ get documentation() {
4670
+ return spaceTrim$1(`
4671
+ # META FONT
4672
+
4673
+ Sets the agent's font.
4674
+
4675
+ ## Key aspects
4676
+
4677
+ - Does not modify the agent's behavior or responses.
4678
+ - Only one \`META FONT\` should be used per agent.
4679
+ - If multiple are specified, the last one takes precedence.
4680
+ - Used for visual representation in user interfaces.
4681
+ - Supports Google Fonts.
4682
+
4683
+ ## Examples
4684
+
4685
+ \`\`\`book
4686
+ Modern Assistant
4687
+
4688
+ META FONT Poppins, Arial, sans-serif
4689
+ PERSONA You are a modern assistant
4690
+ \`\`\`
4691
+
4692
+ \`\`\`book
4693
+ Classic Helper
4694
+
4695
+ META FONT Times New Roman
4696
+ PERSONA You are a classic helper
4697
+ \`\`\`
4698
+ `);
4699
+ }
4700
+ applyToAgentModelRequirements(requirements, content) {
4701
+ // META FONT doesn't modify the system message or model requirements
4702
+ // It's handled separately in the parsing logic
4703
+ // This method exists for consistency with the CommitmentDefinition interface
4704
+ return requirements;
4705
+ }
4706
+ /**
4707
+ * Extracts the font from the content
4708
+ * This is used by the parsing logic
4709
+ */
4710
+ extractProfileFont(content) {
4711
+ const trimmedContent = content.trim();
4712
+ return trimmedContent || null;
4713
+ }
4714
+ }
4715
+ /**
4716
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4717
+ */
4718
+
4719
+ /**
4720
+ * META IMAGE commitment definition
4721
+ *
4722
+ * The META IMAGE commitment sets the agent's avatar/profile image URL.
4723
+ * This commitment is special because it doesn't affect the system message,
4724
+ * but is handled separately in the parsing logic.
4725
+ *
4726
+ * Example usage in agent source:
4727
+ *
4728
+ * ```book
4729
+ * META IMAGE https://example.com/avatar.jpg
4730
+ * META IMAGE /assets/agent-avatar.png
4731
+ * ```
4732
+ *
4733
+ * @private [🪔] Maybe export the commitments through some package
4734
+ */
4735
+ class MetaImageCommitmentDefinition extends BaseCommitmentDefinition {
4736
+ constructor() {
4737
+ super('META IMAGE', ['IMAGE']);
4738
+ }
4739
+ /**
4740
+ * Short one-line description of META IMAGE.
4741
+ */
4742
+ get description() {
4743
+ return "Set the agent's profile image URL.";
4744
+ }
4745
+ /**
4746
+ * Icon for this commitment.
4747
+ */
4748
+ get icon() {
4749
+ return '🖼️';
4750
+ }
4751
+ /**
4752
+ * Markdown documentation for META IMAGE commitment.
4753
+ */
4754
+ get documentation() {
4755
+ return spaceTrim$1(`
4756
+ # META IMAGE
4757
+
4758
+ Sets the agent's avatar/profile image URL.
4759
+
4760
+ ## Key aspects
4761
+
4762
+ - Does not modify the agent's behavior or responses.
4763
+ - Only one \`META IMAGE\` should be used per agent.
4764
+ - If multiple are specified, the last one takes precedence.
4765
+ - Used for visual representation in user interfaces.
4766
+
4767
+ ## Examples
4768
+
4769
+ \`\`\`book
4770
+ Professional Assistant
4771
+
4772
+ META IMAGE https://example.com/professional-avatar.jpg
4773
+ PERSONA You are a professional business assistant
4774
+ STYLE Maintain a formal and courteous tone
4775
+ \`\`\`
4776
+
4777
+ \`\`\`book
4778
+ Creative Helper
4779
+
4780
+ META IMAGE /assets/creative-bot-avatar.png
4781
+ PERSONA You are a creative and inspiring assistant
4782
+ STYLE Be enthusiastic and encouraging
4783
+ ACTION Can help with brainstorming and ideation
4784
+ \`\`\`
4785
+ `);
4786
+ }
4787
+ applyToAgentModelRequirements(requirements, content) {
4788
+ // META IMAGE doesn't modify the system message or model requirements
4789
+ // It's handled separately in the parsing logic for profile image extraction
4790
+ // This method exists for consistency with the CommitmentDefinition interface
4791
+ return requirements;
4792
+ }
4793
+ /**
4794
+ * Extracts the profile image URL from the content
4795
+ * This is used by the parsing logic
4796
+ */
4797
+ extractProfileImageUrl(content) {
4798
+ const trimmedContent = content.trim();
4799
+ return trimmedContent || null;
4800
+ }
4801
+ }
4802
+ /**
4803
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4804
+ */
4805
+
4806
+ /**
4807
+ * META LINK commitment definition
4808
+ *
4809
+ * The `META LINK` commitment represents the link to the person from whom the agent is created.
4810
+ * This commitment is special because it doesn't affect the system message,
4811
+ * but is handled separately in the parsing logic for profile display.
4812
+ *
4813
+ * Example usage in agent source:
4814
+ *
4815
+ * ```
4816
+ * META LINK https://twitter.com/username
4817
+ * META LINK https://linkedin.com/in/profile
4818
+ * META LINK https://github.com/username
4819
+ * ```
4820
+ *
4821
+ * Multiple `META LINK` commitments can be used when there are multiple sources:
4822
+ *
4823
+ * ```book
4824
+ * META LINK https://twitter.com/username
4825
+ * META LINK https://linkedin.com/in/profile
4826
+ * ```
4827
+ *
4828
+ * @private [🪔] Maybe export the commitments through some package
4829
+ */
4830
+ class MetaLinkCommitmentDefinition extends BaseCommitmentDefinition {
4831
+ constructor() {
4832
+ super('META LINK');
4833
+ }
4834
+ /**
4835
+ * Short one-line description of META LINK.
4836
+ */
4837
+ get description() {
4838
+ return 'Provide profile/source links for the person the agent models.';
4839
+ }
4840
+ /**
4841
+ * Icon for this commitment.
4842
+ */
4843
+ get icon() {
4844
+ return '🔗';
4845
+ }
4846
+ /**
4847
+ * Markdown documentation for META LINK commitment.
4848
+ */
4849
+ get documentation() {
4850
+ return spaceTrim$1(`
4851
+ # META LINK
4852
+
4853
+ Represents a profile or source link for the person the agent is modeled after.
4854
+
4855
+ ## Key aspects
4856
+
4857
+ - Does not modify the agent's behavior or responses.
4858
+ - Multiple \`META LINK\` commitments can be used for different social profiles.
4859
+ - Used for attribution and crediting the original person.
4860
+ - Displayed in user interfaces for transparency.
4861
+
4862
+ ## Examples
4863
+
4864
+ \`\`\`book
4865
+ Expert Consultant
4866
+
4867
+ META LINK https://twitter.com/expertname
4868
+ META LINK https://linkedin.com/in/expertprofile
4869
+ PERSONA You are Dr. Smith, a renowned expert in artificial intelligence
4870
+ KNOWLEDGE Extensive background in machine learning and neural networks
4871
+ \`\`\`
4872
+
4873
+ \`\`\`book
4874
+ Open Source Developer
4875
+
4876
+ META LINK https://github.com/developer
4877
+ META LINK https://twitter.com/devhandle
4878
+ PERSONA You are an experienced open source developer
4879
+ ACTION Can help with code reviews and architecture decisions
4880
+ STYLE Be direct and technical in explanations
4881
+ \`\`\`
4882
+ `);
4883
+ }
4884
+ applyToAgentModelRequirements(requirements, content) {
4885
+ // META LINK doesn't modify the system message or model requirements
4886
+ // It's handled separately in the parsing logic for profile link extraction
4887
+ // This method exists for consistency with the CommitmentDefinition interface
4888
+ return requirements;
4889
+ }
4890
+ /**
4891
+ * Extracts the profile link URL from the content
4892
+ * This is used by the parsing logic
4893
+ */
4894
+ extractProfileLinkUrl(content) {
4895
+ const trimmedContent = content.trim();
4896
+ return trimmedContent || null;
4897
+ }
4898
+ /**
4899
+ * Validates if the provided content is a valid URL
4900
+ */
4901
+ isValidUrl(content) {
4902
+ try {
4903
+ new URL(content.trim());
4904
+ return true;
4905
+ }
4906
+ catch (_a) {
4907
+ return false;
4908
+ }
4909
+ }
4910
+ }
4911
+ /**
4912
+ * Note: [💞] Ignore a discrepancy between file name and entity name
4913
+ */
4914
+
4915
+ /**
4916
+ * MODEL commitment definition
4917
+ *
4918
+ * The MODEL commitment specifies which AI model to use and can also set
4919
+ * model-specific parameters like temperature, topP, topK, and maxTokens.
4920
+ *
4921
+ * Supports multiple syntax variations:
4922
+ *
4923
+ * Single-line format:
4924
+ * ```book
4925
+ * MODEL gpt-4
4926
+ * MODEL claude-3-opus temperature=0.3
4927
+ * MODEL gpt-3.5-turbo temperature=0.8 topP=0.9
4928
+ * ```
4929
+ *
4930
+ * Multi-line named parameter format:
4931
+ * ```book
4932
+ * MODEL NAME gpt-4
4933
+ * MODEL TEMPERATURE 0.7
4934
+ * MODEL TOP_P 0.9
4935
+ * MODEL MAX_TOKENS 2048
4936
+ * ```
4937
+ *
4938
+ * @private [🪔] Maybe export the commitments through some package
4939
+ */
4940
+ class ModelCommitmentDefinition extends BaseCommitmentDefinition {
4941
+ constructor(type = 'MODEL') {
4942
+ super(type);
4943
+ }
4944
+ /**
4945
+ * Short one-line description of MODEL.
4946
+ */
4947
+ get description() {
4948
+ return 'Enforce AI model requirements including name and technical parameters.';
4949
+ }
4950
+ /**
4951
+ * Icon for this commitment.
4952
+ */
4953
+ get icon() {
4954
+ return '⚙️';
4955
+ }
4956
+ /**
4957
+ * Markdown documentation for MODEL commitment.
4958
+ */
4959
+ get documentation() {
4960
+ return spaceTrim$1(`
4961
+ # ${this.type}
4962
+
4963
+ Enforces technical parameters for the AI model, ensuring consistent behavior across different execution environments.
4964
+
4965
+ ## Key aspects
4966
+
4967
+ - When no \`MODEL\` commitment is specified, the best model requirement is picked automatically based on the agent \`PERSONA\`, \`KNOWLEDGE\`, \`TOOLS\` and other commitments
4968
+ - Multiple \`MODEL\` commitments can be used to specify different parameters
4969
+ - Both \`MODEL\` and \`MODELS\` terms work identically and can be used interchangeably
4970
+ - Parameters control the randomness, creativity, and technical aspects of model responses
4971
+
4972
+ ## Syntax variations
4973
+
4974
+ ### Single-line format (legacy support)
4975
+ \`\`\`book
4976
+ MODEL gpt-4
4977
+ MODEL claude-3-opus temperature=0.3
4978
+ MODEL gpt-3.5-turbo temperature=0.8 topP=0.9
4979
+ \`\`\`
4980
+
4981
+ ### Multi-line named parameter format (recommended)
4982
+ \`\`\`book
4983
+ MODEL NAME gpt-4
4984
+ MODEL TEMPERATURE 0.7
4985
+ MODEL TOP_P 0.9
4986
+ MODEL MAX_TOKENS 2048
4987
+ \`\`\`
4988
+
4989
+ ## Supported parameters
4990
+
4991
+ - \`NAME\`: The specific model to use (e.g., 'gpt-4', 'claude-3-opus')
4992
+ - \`TEMPERATURE\`: Controls randomness (0.0 = deterministic, 1.0+ = creative)
4993
+ - \`TOP_P\`: Nucleus sampling parameter for controlling diversity
4994
+ - \`TOP_K\`: Top-k sampling parameter for limiting vocabulary
4995
+ - \`MAX_TOKENS\`: Maximum number of tokens the model can generate
4996
+
4997
+ ## Examples
4998
+
4999
+ ### Precise deterministic assistant
5000
+ \`\`\`book
5001
+ Precise Assistant
5002
+
5003
+ PERSONA You are a precise and accurate assistant
5004
+ MODEL NAME gpt-4
5005
+ MODEL TEMPERATURE 0.1
5006
+ MODEL MAX_TOKENS 1024
5007
+ RULE Always provide factual information
5008
+ \`\`\`
5009
+
5010
+ ### Creative writing assistant
5011
+ \`\`\`book
5012
+ Creative Writer
5013
+
5014
+ PERSONA You are a creative writing assistant
5015
+ MODEL NAME claude-3-opus
5016
+ MODEL TEMPERATURE 0.8
5017
+ MODEL TOP_P 0.9
5018
+ MODEL MAX_TOKENS 2048
5019
+ STYLE Be imaginative and expressive
5020
+ ACTION Can help with storytelling and character development
5021
+ \`\`\`
5022
+
5023
+ ### Balanced conversational agent
5024
+ \`\`\`book
5025
+ Balanced Assistant
5026
+
5027
+ PERSONA You are a helpful and balanced assistant
5028
+ MODEL NAME gpt-4
5029
+ MODEL TEMPERATURE 0.7
5030
+ MODEL TOP_P 0.95
5031
+ MODEL TOP_K 40
5032
+ MODEL MAX_TOKENS 1500
5033
+ \`\`\`
5034
+ `);
5035
+ }
5036
+ applyToAgentModelRequirements(requirements, content) {
5037
+ var _a;
5038
+ const trimmedContent = content.trim();
5039
+ if (!trimmedContent) {
5040
+ return requirements;
5041
+ }
5042
+ const parts = trimmedContent.split(/\s+/);
5043
+ const firstPart = (_a = parts[0]) === null || _a === void 0 ? void 0 : _a.toUpperCase();
5044
+ // Check if this is the new named parameter format
5045
+ if (this.isNamedParameter(firstPart)) {
5046
+ return this.parseNamedParameter(requirements, firstPart, parts.slice(1));
5047
+ }
5048
+ else {
5049
+ // Legacy single-line format: "MODEL gpt-4 temperature=0.3 topP=0.9"
5050
+ return this.parseLegacyFormat(requirements, parts);
5051
+ }
5052
+ }
5053
+ /**
5054
+ * Check if the first part is a known named parameter
5055
+ */
5056
+ isNamedParameter(part) {
5057
+ if (!part)
5058
+ return false;
5059
+ const knownParams = ['NAME', 'TEMPERATURE', 'TOP_P', 'TOP_K', 'MAX_TOKENS'];
5060
+ return knownParams.includes(part);
5061
+ }
5062
+ /**
5063
+ * Parse the new named parameter format: "MODEL TEMPERATURE 0.7"
5064
+ */
5065
+ parseNamedParameter(requirements, parameterName, valueParts) {
5066
+ const value = valueParts.join(' ').trim();
5067
+ if (!value) {
5068
+ return requirements;
5069
+ }
5070
+ const result = { ...requirements };
5071
+ switch (parameterName) {
5072
+ case 'NAME':
5073
+ result.modelName = value;
5074
+ break;
5075
+ case 'TEMPERATURE': {
5076
+ const temperature = parseFloat(value);
5077
+ if (!isNaN(temperature)) {
5078
+ result.temperature = temperature;
5079
+ }
5080
+ break;
5081
+ }
5082
+ case 'TOP_P': {
5083
+ const topP = parseFloat(value);
5084
+ if (!isNaN(topP)) {
5085
+ result.topP = topP;
5086
+ }
5087
+ break;
5088
+ }
5089
+ case 'TOP_K': {
5090
+ const topK = parseFloat(value);
5091
+ if (!isNaN(topK)) {
5092
+ result.topK = Math.round(topK);
5093
+ }
5094
+ break;
5095
+ }
5096
+ case 'MAX_TOKENS': {
5097
+ const maxTokens = parseFloat(value);
5098
+ if (!isNaN(maxTokens)) {
5099
+ result.maxTokens = Math.round(maxTokens);
5100
+ }
5101
+ break;
5102
+ }
5103
+ }
5104
+ return result;
5105
+ }
5106
+ /**
5107
+ * Parse the legacy format: "MODEL gpt-4 temperature=0.3 topP=0.9"
5108
+ */
5109
+ parseLegacyFormat(requirements, parts) {
5110
+ const modelName = parts[0];
5111
+ if (!modelName) {
5112
+ return requirements;
5113
+ }
5114
+ // Start with the model name
5115
+ const result = {
5116
+ ...requirements,
5117
+ modelName,
5118
+ };
5119
+ // Parse additional key=value parameters
5120
+ for (let i = 1; i < parts.length; i++) {
5121
+ const param = parts[i];
5122
+ if (param && param.includes('=')) {
5123
+ const [key, value] = param.split('=');
5124
+ if (key && value) {
5125
+ const numValue = parseFloat(value);
5126
+ if (!isNaN(numValue)) {
5127
+ switch (key.toLowerCase()) {
5128
+ case 'temperature':
5129
+ result.temperature = numValue;
5130
+ break;
5131
+ case 'topp':
5132
+ case 'top_p':
5133
+ result.topP = numValue;
5134
+ break;
5135
+ case 'topk':
5136
+ case 'top_k':
5137
+ result.topK = Math.round(numValue);
5138
+ break;
5139
+ case 'max_tokens':
5140
+ case 'maxTokens':
5141
+ result.maxTokens = Math.round(numValue);
5142
+ break;
5143
+ }
5144
+ }
5145
+ }
5146
+ }
5147
+ }
5148
+ return result;
5149
+ }
5150
+ }
5151
+ /**
5152
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5153
+ */
5154
+
5155
+ /**
5156
+ * NOTE commitment definition
5157
+ *
5158
+ * The NOTE commitment is used to add comments to the agent source without making any changes
5159
+ * to the system message or agent model requirements. It serves as a documentation mechanism
5160
+ * for developers to add explanatory comments, reminders, or annotations directly in the agent source.
5161
+ *
5162
+ * Key features:
5163
+ * - Makes no changes to the system message
5164
+ * - Makes no changes to agent model requirements
5165
+ * - Content is preserved in metadata.NOTE for debugging and inspection
5166
+ * - Multiple NOTE commitments are aggregated together
5167
+ * - Comments (# NOTE) are removed from the final system message
5168
+ *
5169
+ * Example usage in agent source:
5170
+ *
5171
+ * ```book
5172
+ * NOTE This agent was designed for customer support scenarios
5173
+ * NOTE Remember to update the knowledge base monthly
5174
+ * NOTE Performance optimized for quick response times
5175
+ * ```
5176
+ *
5177
+ * The above notes will be stored in metadata but won't affect the agent's behavior.
5178
+ *
5179
+ * @private [🪔] Maybe export the commitments through some package
5180
+ */
5181
+ class NoteCommitmentDefinition extends BaseCommitmentDefinition {
5182
+ constructor(type = 'NOTE') {
5183
+ super(type);
5184
+ }
5185
+ /**
5186
+ * Short one-line description of NOTE.
5187
+ */
5188
+ get description() {
5189
+ return 'Add developer-facing notes without changing behavior or output.';
5190
+ }
5191
+ /**
5192
+ * Icon for this commitment.
5193
+ */
5194
+ get icon() {
5195
+ return '📝';
5196
+ }
5197
+ /**
5198
+ * Markdown documentation for NOTE commitment.
5199
+ */
5200
+ get documentation() {
5201
+ return spaceTrim$1(`
5202
+ # ${this.type}
5203
+
5204
+ Adds comments for documentation without changing agent behavior.
5205
+
5206
+ ## Key aspects
5207
+
5208
+ - Does not modify the agent's behavior or responses.
5209
+ - Multiple \`NOTE\`, \`NOTES\`, \`COMMENT\`, and \`NONCE\` commitments are aggregated for debugging.
5210
+ - All four terms work identically and can be used interchangeably.
5211
+ - Useful for documenting design decisions and reminders.
5212
+ - Content is preserved in metadata for inspection.
5213
+
5214
+ ## Examples
5215
+
5216
+ \`\`\`book
5217
+ Customer Support Bot
5218
+
5219
+ NOTE This agent was designed for customer support scenarios
5220
+ COMMENT Remember to update the knowledge base monthly
5221
+ PERSONA You are a helpful customer support representative
5222
+ KNOWLEDGE Company policies and procedures
5223
+ RULE Always be polite and professional
5224
+ \`\`\`
5225
+
5226
+ \`\`\`book
5227
+ Research Assistant
5228
+
5229
+ NONCE Performance optimized for quick response times
5230
+ NOTE Uses RAG for accessing latest research papers
5231
+ PERSONA You are a knowledgeable research assistant
5232
+ ACTION Can help with literature reviews and citations
5233
+ STYLE Present information in academic format
5234
+ \`\`\`
5235
+ `);
5236
+ }
5237
+ applyToAgentModelRequirements(requirements, content) {
5238
+ // The NOTE commitment makes no changes to the system message or model requirements
5239
+ // It only stores the note content in metadata for documentation purposes
5240
+ const trimmedContent = spaceTrim$1(content);
5241
+ if (trimmedContent === '') {
5242
+ return requirements;
5243
+ }
5244
+ // Return requirements with updated notes but no changes to system message
5245
+ return {
5246
+ ...requirements,
5247
+ notes: [...(requirements.notes || []), trimmedContent],
5248
+ };
5249
+ }
5250
+ }
5251
+ /**
5252
+ * [💞] Ignore a discrepancy between file name and entity name
5253
+ */
5254
+
5255
+ /**
5256
+ * OPEN commitment definition
5257
+ *
5258
+ * The OPEN commitment specifies that the agent can be modified by conversation.
5259
+ * This is the default behavior.
5260
+ *
5261
+ * Example usage in agent source:
5262
+ *
5263
+ * ```book
5264
+ * OPEN
5265
+ * ```
5266
+ *
5267
+ * @private [🪔] Maybe export the commitments through some package
5268
+ */
5269
+ class OpenCommitmentDefinition extends BaseCommitmentDefinition {
5270
+ constructor() {
5271
+ super('OPEN');
5272
+ }
5273
+ /**
5274
+ * Short one-line description of OPEN.
5275
+ */
5276
+ get description() {
5277
+ return 'Allow the agent to be modified by conversation (default).';
5278
+ }
5279
+ /**
5280
+ * Icon for this commitment.
5281
+ */
5282
+ get icon() {
5283
+ return '🔓';
5284
+ }
5285
+ /**
5286
+ * Markdown documentation for OPEN commitment.
5287
+ */
5288
+ get documentation() {
5289
+ return spaceTrim$1(`
5290
+ # OPEN
5291
+
5292
+ Specifies that the agent can be modified by conversation with it.
5293
+ This means the agent will learn from interactions and update its source code.
5294
+
5295
+ This is the default behavior if neither \`OPEN\` nor \`CLOSED\` is specified.
5296
+
5297
+ > See also [CLOSED](/docs/CLOSED)
5298
+
5299
+ ## Example
5300
+
5301
+ \`\`\`book
5302
+ OPEN
5303
+ \`\`\`
5304
+ `);
5305
+ }
5306
+ applyToAgentModelRequirements(requirements, _content) {
5307
+ // Since OPEN is default, we can just ensure isClosed is false
5308
+ // But to be explicit we can set it
5309
+ const updatedMetadata = {
5310
+ ...requirements.metadata,
5311
+ isClosed: false,
5312
+ };
5313
+ return {
5314
+ ...requirements,
5315
+ metadata: updatedMetadata,
5316
+ };
5317
+ }
5318
+ }
5319
+ /**
5320
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5321
+ */
5322
+
5323
+ /**
5324
+ * PERSONA commitment definition
5325
+ *
5326
+ * The PERSONA commitment modifies the agent's personality and character in the system message.
5327
+ * It defines who the agent is, their background, expertise, and personality traits.
5328
+ *
5329
+ * Key features:
5330
+ * - Multiple PERSONA commitments are automatically merged into one
5331
+ * - Content is placed at the beginning of the system message
5332
+ * - Original content with comments is preserved in metadata.PERSONA
5333
+ * - Comments (# PERSONA) are removed from the final system message
5334
+ *
5335
+ * Example usage in agent source:
5336
+ *
5337
+ * ```book
5338
+ * PERSONA You are a helpful programming assistant with expertise in TypeScript and React
5339
+ * PERSONA You have deep knowledge of modern web development practices
5340
+ * ```
5341
+ *
5342
+ * The above will be merged into a single persona section at the beginning of the system message.
5343
+ *
5344
+ * @private [🪔] Maybe export the commitments through some package
5345
+ */
5346
+ class PersonaCommitmentDefinition extends BaseCommitmentDefinition {
5347
+ constructor(type = 'PERSONA') {
5348
+ super(type);
5349
+ }
5350
+ /**
5351
+ * Short one-line description of PERSONA.
5352
+ */
5353
+ get description() {
5354
+ return 'Define who the agent is: background, expertise, and personality.';
5355
+ }
5356
+ /**
5357
+ * Icon for this commitment.
5358
+ */
5359
+ get icon() {
5360
+ return '👤';
5361
+ }
5362
+ /**
5363
+ * Markdown documentation for PERSONA commitment.
5364
+ */
5365
+ get documentation() {
5366
+ return spaceTrim$1(`
5367
+ # ${this.type}
5368
+
5369
+ Defines who the agent is, their background, expertise, and personality traits.
5370
+
5371
+ ## Key aspects
5372
+
5373
+ - Multiple \`PERSONA\` and \`PERSONAE\` commitments are merged together.
5374
+ - Both terms work identically and can be used interchangeably.
5375
+ - If they are in conflict, the last one takes precedence.
5376
+ - You can write persona content in multiple lines.
5377
+
5378
+ ## Examples
5379
+
5380
+ \`\`\`book
5381
+ Programming Assistant
5382
+
5383
+ PERSONA You are a helpful programming assistant with expertise in TypeScript and React
5384
+ PERSONA You have deep knowledge of modern web development practices
5385
+ \`\`\`
5386
+ `);
5387
+ }
5388
+ applyToAgentModelRequirements(requirements, content) {
5389
+ var _a, _b;
5390
+ // The PERSONA commitment aggregates all persona content and places it at the beginning
5391
+ const trimmedContent = content.trim();
5392
+ if (!trimmedContent) {
5393
+ return requirements;
5394
+ }
5395
+ // Get existing persona content from metadata
5396
+ const existingPersonaContent = ((_a = requirements.metadata) === null || _a === void 0 ? void 0 : _a.PERSONA) || '';
5397
+ // Merge the new content with existing persona content
5398
+ // When multiple PERSONA commitments exist, they are merged into one
5399
+ const mergedPersonaContent = existingPersonaContent
5400
+ ? `${existingPersonaContent}\n${trimmedContent}`
5401
+ : trimmedContent;
5402
+ // Store the merged persona content in metadata for debugging and inspection
5403
+ const updatedMetadata = {
5404
+ ...requirements.metadata,
5405
+ PERSONA: mergedPersonaContent,
5406
+ };
5407
+ // Get the agent name from metadata (which should contain the first line of agent source)
5408
+ // If not available, extract from current system message as fallback
5409
+ let agentName = (_b = requirements.metadata) === null || _b === void 0 ? void 0 : _b.agentName;
5410
+ if (!agentName) {
5411
+ // Fallback: extract from current system message
5412
+ const currentMessage = requirements.systemMessage.trim();
5413
+ const basicFormatMatch = currentMessage.match(/^You are (.+)$/);
5414
+ if (basicFormatMatch && basicFormatMatch[1]) {
5415
+ agentName = basicFormatMatch[1];
5416
+ }
5417
+ else {
5418
+ agentName = 'AI Agent'; // Final fallback
5419
+ }
5420
+ }
5421
+ // Remove any existing persona content from the system message
5422
+ // (this handles the case where we're processing multiple PERSONA commitments)
5423
+ const currentMessage = requirements.systemMessage.trim();
5424
+ let cleanedMessage = currentMessage;
5425
+ // Check if current message starts with persona content or is just the basic format
5426
+ const basicFormatRegex = /^You are .+$/;
5427
+ const isBasicFormat = basicFormatRegex.test(currentMessage) && !currentMessage.includes('\n');
5428
+ if (isBasicFormat) {
5429
+ // Replace the basic format entirely
5430
+ cleanedMessage = '';
5431
+ }
5432
+ else if (currentMessage.startsWith('# PERSONA')) {
5433
+ // Remove existing persona section by finding where it ends
5434
+ const lines = currentMessage.split('\n');
5435
+ let personaEndIndex = lines.length;
5436
+ // Find the end of the PERSONA section (next comment or end of message)
5437
+ for (let i = 1; i < lines.length; i++) {
5438
+ const line = lines[i].trim();
5439
+ if (line.startsWith('#') && !line.startsWith('# PERSONA')) {
5440
+ personaEndIndex = i;
5441
+ break;
5442
+ }
5443
+ }
5444
+ // Keep everything after the PERSONA section
5445
+ cleanedMessage = lines.slice(personaEndIndex).join('\n').trim();
5446
+ }
5447
+ // TODO: [🕛] There should be `agentFullname` not `agentName`
5448
+ // Create new system message with persona at the beginning
5449
+ // Format: "You are {agentName}\n{personaContent}"
5450
+ // The # PERSONA comment will be removed later by removeCommentsFromSystemMessage
5451
+ const personaSection = `# PERSONA\nYou are ${agentName}\n${mergedPersonaContent}`; // <- TODO: Use spaceTrim
5452
+ const newSystemMessage = cleanedMessage ? `${personaSection}\n\n${cleanedMessage}` : personaSection;
5453
+ return {
5454
+ ...requirements,
5455
+ systemMessage: newSystemMessage,
5456
+ metadata: updatedMetadata,
5457
+ };
5458
+ }
5459
+ }
5460
+ /**
5461
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5462
+ */
5463
+
5464
+ /**
5465
+ * RULE commitment definition
5466
+ *
5467
+ * The RULE/RULES commitment adds behavioral constraints and guidelines that the agent must follow.
5468
+ * These are specific instructions about what the agent should or shouldn't do.
5469
+ *
5470
+ * Example usage in agent source:
5471
+ *
5472
+ * ```book
5473
+ * RULE Always ask for clarification if the user's request is ambiguous
5474
+ * RULES Never provide medical advice, always refer to healthcare professionals
5475
+ * ```
5476
+ *
5477
+ * @private [🪔] Maybe export the commitments through some package
5478
+ */
5479
+ class RuleCommitmentDefinition extends BaseCommitmentDefinition {
5480
+ constructor(type = 'RULE') {
5481
+ super(type);
5482
+ }
5483
+ /**
5484
+ * Short one-line description of RULE/RULES.
5485
+ */
5486
+ get description() {
5487
+ return 'Add behavioral rules the agent must follow.';
5488
+ }
5489
+ /**
5490
+ * Icon for this commitment.
5491
+ */
5492
+ get icon() {
5493
+ return '⚖️';
5494
+ }
5495
+ /**
5496
+ * Markdown documentation for RULE/RULES commitment.
5497
+ */
5498
+ get documentation() {
5499
+ return spaceTrim$1(`
5500
+ # ${this.type}
5501
+
5502
+ Adds behavioral constraints and guidelines that the agent must follow.
5503
+
5504
+ ## Key aspects
5505
+
5506
+ - All rules are treated equally regardless of singular/plural form.
5507
+ - Rules define what the agent must or must not do.
5508
+
5509
+ ## Examples
5510
+
5511
+ \`\`\`book
5512
+ Customer Support Agent
5513
+
5514
+ PERSONA You are a helpful customer support representative
5515
+ RULE Always ask for clarification if the user's request is ambiguous
5516
+ RULE Be polite and professional in all interactions
5517
+ RULES Never provide medical or legal advice
5518
+ STYLE Maintain a friendly and helpful tone
5519
+ \`\`\`
5520
+
5521
+ \`\`\`book
5522
+ Educational Tutor
5523
+
5524
+ PERSONA You are a patient and knowledgeable tutor
5525
+ RULE Break down complex concepts into simple steps
5526
+ RULE Always encourage students and celebrate their progress
5527
+ RULE If you don't know something, admit it and suggest resources
5528
+ SAMPLE When explaining math: "Let's work through this step by step..."
5529
+ \`\`\`
5530
+ `);
5531
+ }
5532
+ applyToAgentModelRequirements(requirements, content) {
5533
+ const trimmedContent = content.trim();
5534
+ if (!trimmedContent) {
5535
+ return requirements;
5536
+ }
5537
+ // Add rule to the system message
5538
+ const ruleSection = `Rule: ${trimmedContent}`;
5539
+ return this.appendToSystemMessage(requirements, ruleSection, '\n\n');
5540
+ }
5541
+ }
5542
+ /**
5543
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5544
+ */
5545
+
5546
+ /**
5547
+ * SAMPLE commitment definition
5548
+ *
5549
+ * The SAMPLE/EXAMPLE commitment provides examples of how the agent should respond
5550
+ * or behave in certain situations. These examples help guide the agent's responses.
5551
+ *
5552
+ * Example usage in agent source:
5553
+ *
5554
+ * ```book
5555
+ * SAMPLE When asked about pricing, respond: "Our basic plan starts at $10/month..."
5556
+ * EXAMPLE For code questions, always include working code snippets
5557
+ * ```
5558
+ *
5559
+ * @private [🪔] Maybe export the commitments through some package
5560
+ */
5561
+ class SampleCommitmentDefinition extends BaseCommitmentDefinition {
5562
+ constructor(type = 'SAMPLE') {
5563
+ super(type);
5564
+ }
5565
+ /**
5566
+ * Short one-line description of SAMPLE/EXAMPLE.
5567
+ */
5568
+ get description() {
5569
+ return 'Provide example responses to guide behavior.';
5570
+ }
5571
+ /**
5572
+ * Icon for this commitment.
5573
+ */
5574
+ get icon() {
5575
+ return '🔍';
5576
+ }
5577
+ /**
5578
+ * Markdown documentation for SAMPLE/EXAMPLE commitment.
5579
+ */
5580
+ get documentation() {
5581
+ return spaceTrim$1(`
5582
+ # ${this.type}
5583
+
5584
+ Provides examples of how the agent should respond or behave in certain situations.
5585
+
5586
+ ## Key aspects
5587
+
5588
+ - Both terms work identically and can be used interchangeably.
5589
+ - Examples help guide the agent's response patterns and style.
5590
+
5591
+ ## Examples
5592
+
5593
+ \`\`\`book
5594
+ Sales Assistant
5595
+
5596
+ PERSONA You are a knowledgeable sales representative
5597
+ SAMPLE When asked about pricing, respond: "Our basic plan starts at $10/month..."
5598
+ SAMPLE For feature comparisons, create a clear comparison table
5599
+ RULE Always be honest about limitations
5600
+ \`\`\`
5601
+
5602
+ \`\`\`book
5603
+ Code Reviewer
5604
+
5605
+ PERSONA You are an experienced software engineer
5606
+ EXAMPLE For code questions, always include working code snippets
5607
+ EXAMPLE When suggesting improvements: "Here's a more efficient approach..."
5608
+ RULE Explain the reasoning behind your suggestions
5609
+ STYLE Be constructive and encouraging in feedback
5610
+ \`\`\`
5611
+ `);
5612
+ }
5613
+ applyToAgentModelRequirements(requirements, content) {
5614
+ const trimmedContent = content.trim();
5615
+ if (!trimmedContent) {
5616
+ return requirements;
5617
+ }
5618
+ // Add example to the system message
5619
+ const exampleSection = `Example: ${trimmedContent}`;
5620
+ return this.appendToSystemMessage(requirements, exampleSection, '\n\n');
5621
+ }
5622
+ }
5623
+ /**
5624
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5625
+ */
5626
+
5627
+ /**
5628
+ * SCENARIO commitment definition
5629
+ *
5630
+ * The SCENARIO commitment defines a specific situation or context in which the AI
5631
+ * assistant should operate. It helps to set the scene for the AI's responses.
5632
+ * Later scenarios are more important than earlier scenarios.
5633
+ *
5634
+ * Example usage in agent source:
5635
+ *
5636
+ * ```book
5637
+ * SCENARIO You are in a customer service call center during peak hours
5638
+ * SCENARIO The customer is frustrated and has been on hold for 20 minutes
5639
+ * SCENARIO This is the customer's third call about the same issue
5640
+ * ```
5641
+ *
5642
+ * @private [🪔] Maybe export the commitments through some package
5643
+ */
5644
+ class ScenarioCommitmentDefinition extends BaseCommitmentDefinition {
5645
+ constructor(type = 'SCENARIO') {
5646
+ super(type);
5647
+ }
5648
+ /**
5649
+ * Short one-line description of SCENARIO.
5650
+ */
5651
+ get description() {
5652
+ return 'Define specific **situations** or contexts for AI responses, with later scenarios having higher priority.';
5653
+ }
5654
+ /**
5655
+ * Icon for this commitment.
5656
+ */
5657
+ get icon() {
5658
+ return '🎭';
5659
+ }
5660
+ /**
5661
+ * Markdown documentation for SCENARIO commitment.
5662
+ */
5663
+ get documentation() {
5664
+ return spaceTrim$1(`
5665
+ # ${this.type}
5666
+
5667
+ Defines a specific situation or context in which the AI assistant should operate. It helps to set the scene for the AI's responses. Later scenarios are more important than earlier scenarios.
5668
+
5669
+ ## Key aspects
5670
+
5671
+ - Multiple \`SCENARIO\` and \`SCENARIOS\` commitments build upon each other.
5672
+ - Both terms work identically and can be used interchangeably.
5673
+ - Later scenarios have higher priority and can override earlier scenarios.
5674
+ - Provides situational context that influences response tone and content.
5675
+ - Helps establish the environment and circumstances for interactions.
5676
+
5677
+ ## Priority system
5678
+
5679
+ When multiple scenarios are defined, they are processed in order, with later scenarios taking precedence over earlier ones when there are conflicts.
5680
+
5681
+ ## Use cases
5682
+
5683
+ - Setting the physical or virtual environment
5684
+ - Establishing time constraints or urgency
5685
+ - Defining relationship dynamics or power structures
5686
+ - Creating emotional or situational context
5687
+
5688
+ ## Examples
5689
+
5690
+ \`\`\`book
5691
+ Emergency Response Operator
5692
+
5693
+ PERSONA You are an emergency response operator
5694
+ SCENARIO You are handling a 911 emergency call
5695
+ SCENARIO The caller is panicked and speaking rapidly
5696
+ SCENARIO Time is critical - every second counts
5697
+ GOAL Gather essential information quickly and dispatch appropriate help
5698
+ RULE Stay calm and speak clearly
5699
+ \`\`\`
5700
+
5701
+ \`\`\`book
5702
+ Sales Representative
5703
+
5704
+ PERSONA You are a software sales representative
5705
+ SCENARIO You are in the final meeting of a 6-month sales cycle
5706
+ SCENARIO The client has budget approval and decision-making authority
5707
+ SCENARIO Two competitors have also submitted proposals
5708
+ SCENARIO The client values long-term partnership over lowest price
5709
+ GOAL Close the deal while building trust for future business
5710
+ \`\`\`
5711
+
5712
+ \`\`\`book
5713
+ Medical Assistant
5714
+
5715
+ PERSONA You are a medical assistant in a busy clinic
5716
+ SCENARIO The waiting room is full and the doctor is running behind schedule
5717
+ SCENARIO Patients are becoming impatient and anxious
5718
+ SCENARIO You need to manage expectations while maintaining professionalism
5719
+ SCENARIO Some patients have been waiting over an hour
5720
+ GOAL Keep patients informed and calm while supporting efficient clinic flow
5721
+ RULE Never provide medical advice or diagnosis
5722
+ \`\`\`
5723
+
5724
+ \`\`\`book
5725
+ Technical Support Agent
5726
+
5727
+ PERSONA You are a technical support agent
5728
+ SCENARIO The customer is a small business owner during their busy season
5729
+ SCENARIO Their main business system has been down for 2 hours
5730
+ SCENARIO They are losing money every minute the system is offline
5731
+ SCENARIO This is their first experience with your company
5732
+ GOAL Resolve the issue quickly while creating a positive first impression
5733
+ \`\`\`
5734
+ `);
5735
+ }
5736
+ applyToAgentModelRequirements(requirements, content) {
5737
+ const trimmedContent = content.trim();
5738
+ if (!trimmedContent) {
5739
+ return requirements;
5740
+ }
5741
+ // Create scenario section for system message
5742
+ const scenarioSection = `Scenario: ${trimmedContent}`;
5743
+ // Scenarios provide important contextual information that affects behavior
5744
+ return this.appendToSystemMessage(requirements, scenarioSection, '\n\n');
5745
+ }
5746
+ }
5747
+ /**
5748
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5749
+ */
5750
+
5751
+ /**
5752
+ * STYLE commitment definition
5753
+ *
5754
+ * The STYLE commitment defines how the agent should format and present its responses.
5755
+ * This includes tone, writing style, formatting preferences, and communication patterns.
5756
+ *
5757
+ * Example usage in agent source:
5758
+ *
5759
+ * ```book
5760
+ * STYLE Write in a professional but friendly tone, use bullet points for lists
5761
+ * STYLE Always provide code examples when explaining programming concepts
5762
+ * ```
5763
+ *
5764
+ * @private [🪔] Maybe export the commitments through some package
5765
+ */
5766
+ class StyleCommitmentDefinition extends BaseCommitmentDefinition {
5767
+ constructor(type = 'STYLE') {
5768
+ super(type);
5769
+ }
5770
+ /**
5771
+ * Short one-line description of STYLE.
5772
+ */
5773
+ get description() {
5774
+ return 'Control the tone and writing style of responses.';
5775
+ }
5776
+ /**
5777
+ * Icon for this commitment.
5778
+ */
5779
+ get icon() {
5780
+ return '🖋️';
5781
+ }
5782
+ /**
5783
+ * Markdown documentation for STYLE commitment.
5784
+ */
5785
+ get documentation() {
5786
+ return spaceTrim$1(`
5787
+ # ${this.type}
5788
+
5789
+ Defines how the agent should format and present its responses (tone, writing style, formatting).
5790
+
5791
+ ## Key aspects
5792
+
5793
+ - Both terms work identically and can be used interchangeably.
5794
+ - Later style instructions can override earlier ones.
5795
+ - Style affects both tone and presentation format.
5796
+
5797
+ ## Examples
5798
+
5799
+ \`\`\`book
5800
+ Technical Writer
5801
+
5802
+ PERSONA You are a technical documentation expert
5803
+ STYLE Write in a professional but friendly tone, use bullet points for lists
5804
+ STYLE Always provide code examples when explaining programming concepts
5805
+ FORMAT Use markdown formatting with clear headings
5806
+ \`\`\`
5807
+
5808
+ \`\`\`book
5809
+ Creative Assistant
5810
+
5811
+ PERSONA You are a creative writing helper
5812
+ STYLE Be enthusiastic and encouraging in your responses
5813
+ STYLE Use vivid metaphors and analogies to explain concepts
5814
+ STYLE Keep responses conversational and engaging
5815
+ RULE Always maintain a positive and supportive tone
5816
+ \`\`\`
5817
+ `);
5818
+ }
5819
+ applyToAgentModelRequirements(requirements, content) {
5820
+ const trimmedContent = content.trim();
5821
+ if (!trimmedContent) {
5822
+ return requirements;
5823
+ }
5824
+ // Add style instructions to the system message
5825
+ const styleSection = `Style: ${trimmedContent}`;
5826
+ return this.appendToSystemMessage(requirements, styleSection, '\n\n');
5827
+ }
5828
+ }
5829
+ /**
5830
+ * [💞] Ignore a discrepancy between file name and entity name
5831
+ */
5832
+
5833
+ /**
5834
+ * USE commitment definition
5835
+ *
5836
+ * The USE commitment indicates that the agent should utilize specific tools or capabilities
5837
+ * to access and interact with external systems when necessary.
5838
+ *
5839
+ * Supported USE types:
5840
+ * - USE BROWSER: Enables the agent to use a web browser tool
5841
+ * - USE SEARCH ENGINE (future): Enables search engine access
5842
+ * - USE FILE SYSTEM (future): Enables file system operations
5843
+ * - USE MCP (future): Enables MCP server connections
5844
+ *
5845
+ * The content following the USE commitment is ignored (similar to NOTE).
5846
+ *
5847
+ * Example usage in agent source:
5848
+ *
5849
+ * ```book
5850
+ * USE BROWSER
5851
+ * USE SEARCH ENGINE
5852
+ * ```
5853
+ *
5854
+ * @private [🪔] Maybe export the commitments through some package
5855
+ */
5856
+ class UseCommitmentDefinition extends BaseCommitmentDefinition {
5857
+ constructor() {
5858
+ super('USE');
5859
+ }
5860
+ /**
5861
+ * Short one-line description of USE commitments.
5862
+ */
5863
+ get description() {
5864
+ return 'Enable the agent to use specific tools or capabilities (BROWSER, SEARCH ENGINE, etc.).';
5865
+ }
5866
+ /**
5867
+ * Icon for this commitment.
5868
+ */
5869
+ get icon() {
5870
+ return '🔧';
5871
+ }
5872
+ /**
5873
+ * Markdown documentation for USE commitment.
5874
+ */
5875
+ get documentation() {
5876
+ return spaceTrim$1(`
5877
+ # USE
5878
+
5879
+ Enables the agent to use specific tools or capabilities for interacting with external systems.
5880
+
5881
+ ## Supported USE types
5882
+
5883
+ - **USE BROWSER** - Enables the agent to use a web browser tool to access and retrieve information from the internet
5884
+ - **USE SEARCH ENGINE** (future) - Enables search engine access
5885
+ - **USE FILE SYSTEM** (future) - Enables file system operations
5886
+ - **USE MCP** (future) - Enables MCP server connections
5887
+
5888
+ ## Key aspects
5889
+
5890
+ - The content following the USE commitment is ignored (similar to NOTE)
5891
+ - Multiple USE commitments can be specified to enable multiple capabilities
5892
+ - The actual tool usage is handled by the agent runtime
5893
+
5894
+ ## Examples
5895
+
5896
+ ### Basic browser usage
5897
+
5898
+ \`\`\`book
5899
+ Research Assistant
5900
+
5901
+ PERSONA You are a helpful research assistant
5902
+ USE BROWSER
5903
+ KNOWLEDGE Can search the web for up-to-date information
5904
+ \`\`\`
5905
+
5906
+ ### Multiple tools
5907
+
5908
+ \`\`\`book
5909
+ Data Analyst
5910
+
5911
+ PERSONA You are a data analyst assistant
5912
+ USE BROWSER
5913
+ USE FILE SYSTEM
5914
+ ACTION Can analyze data from various sources
5915
+ \`\`\`
5916
+ `);
5917
+ }
5918
+ applyToAgentModelRequirements(requirements, content) {
5919
+ // USE commitments don't modify the system message or model requirements directly
5920
+ // They are handled separately in the parsing logic for capability extraction
5921
+ // This method exists for consistency with the CommitmentDefinition interface
5922
+ return requirements;
5923
+ }
5924
+ /**
5925
+ * Extracts the tool type from the USE commitment
5926
+ * This is used by the parsing logic
5927
+ */
5928
+ extractToolType(content) {
5929
+ var _a, _b;
5930
+ const trimmedContent = content.trim();
5931
+ // The tool type is the first word after USE (already stripped)
5932
+ const match = trimmedContent.match(/^(\w+)/);
5933
+ return (_b = (_a = match === null || match === void 0 ? void 0 : match[1]) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== null && _b !== void 0 ? _b : null;
5934
+ }
5935
+ /**
5936
+ * Checks if this is a known USE type
5937
+ */
5938
+ isKnownUseType(useType) {
5939
+ const knownTypes = ['BROWSER', 'SEARCH ENGINE', 'FILE SYSTEM', 'MCP'];
5940
+ return knownTypes.includes(useType.toUpperCase());
5941
+ }
5942
+ }
5943
+ /**
5944
+ * Note: [💞] Ignore a discrepancy between file name and entity name
5945
+ */
5946
+
5947
+ /**
5948
+ * USE BROWSER commitment definition
5949
+ *
5950
+ * The `USE BROWSER` commitment indicates that the agent should utilize a web browser tool
5951
+ * to access and retrieve up-to-date information from the internet when necessary.
5952
+ *
5953
+ * The content following `USE BROWSER` is ignored (similar to NOTE).
5954
+ *
5955
+ * Example usage in agent source:
5956
+ *
5957
+ * ```book
5958
+ * USE BROWSER
5959
+ * USE BROWSER This will be ignored
5960
+ * ```
5961
+ *
5962
+ * @private [🪔] Maybe export the commitments through some package
5963
+ */
5964
+ class UseBrowserCommitmentDefinition extends BaseCommitmentDefinition {
5965
+ constructor() {
5966
+ super('USE BROWSER', ['BROWSER']);
5967
+ }
5968
+ /**
5969
+ * The `USE BROWSER` commitment is standalone.
5970
+ */
5971
+ get requiresContent() {
5972
+ return false;
5973
+ }
5974
+ /**
5975
+ * Short one-line description of USE BROWSER.
5976
+ */
5977
+ get description() {
5978
+ return 'Enable the agent to use a web browser tool for accessing internet information.';
5979
+ }
5980
+ /**
5981
+ * Icon for this commitment.
5982
+ */
5983
+ get icon() {
5984
+ return '🌐';
5985
+ }
5986
+ /**
5987
+ * Markdown documentation for USE BROWSER commitment.
5988
+ */
5989
+ get documentation() {
5990
+ return spaceTrim$1(`
5991
+ # USE BROWSER
5992
+
5993
+ Enables the agent to use a web browser tool to access and retrieve up-to-date information from the internet.
5994
+
5995
+ ## Key aspects
5996
+
5997
+ - The content following \`USE BROWSER\` is ignored (similar to NOTE)
5998
+ - The actual browser tool usage is handled by the agent runtime
5999
+ - Allows the agent to fetch current information from websites
6000
+ - Useful for research tasks, fact-checking, and accessing dynamic content
6001
+
6002
+ ## Examples
6003
+
6004
+ \`\`\`book
6005
+ Research Assistant
6006
+
6007
+ PERSONA You are a helpful research assistant specialized in finding current information
6008
+ USE BROWSER
6009
+ RULE Always cite your sources when providing information from the web
6010
+ \`\`\`
6011
+
6012
+ \`\`\`book
6013
+ News Analyst
6014
+
6015
+ PERSONA You are a news analyst who stays up-to-date with current events
6016
+ USE BROWSER
6017
+ STYLE Present news in a balanced and objective manner
6018
+ ACTION Can search for and summarize news articles
6019
+ \`\`\`
6020
+
6021
+ \`\`\`book
6022
+ Company Lawyer
6023
+
6024
+ PERSONA You are a company lawyer providing legal advice
6025
+ USE BROWSER
6026
+ KNOWLEDGE Corporate law and legal procedures
6027
+ RULE Always recommend consulting with a licensed attorney for specific legal matters
6028
+ \`\`\`
6029
+ `);
6030
+ }
6031
+ applyToAgentModelRequirements(requirements, content) {
6032
+ // Get existing tools array or create new one
6033
+ const existingTools = requirements.tools || [];
6034
+ // Add 'web_browser' to tools if not already present
6035
+ const updatedTools = existingTools.some((tool) => tool.name === 'web_browser')
6036
+ ? existingTools
6037
+ : ([
6038
+ // TODO: [🔰] Use through proper MCP server
6039
+ ...existingTools,
6040
+ {
6041
+ name: 'web_browser',
6042
+ description: spaceTrim$1(`
6043
+ A tool that can browse the web.
6044
+ Use this tool when you need to access specific websites or browse the internet.
6045
+ `),
6046
+ parameters: {
6047
+ type: 'object',
6048
+ properties: {
6049
+ url: {
6050
+ type: 'string',
6051
+ description: 'The URL to browse',
6052
+ },
6053
+ },
6054
+ required: ['url'],
6055
+ },
6056
+ },
6057
+ ]);
6058
+ // Return requirements with updated tools and metadata
6059
+ return {
6060
+ ...requirements,
6061
+ tools: updatedTools,
6062
+ metadata: {
6063
+ ...requirements.metadata,
6064
+ useBrowser: true,
6065
+ },
6066
+ };
6067
+ }
6068
+ }
6069
+ /**
6070
+ * Note: [💞] Ignore a discrepancy between file name and entity name
6071
+ */
6072
+
6073
+ /**
6074
+ * USE MCP commitment definition
6075
+ *
6076
+ * The `USE MCP` commitment allows to specify an MCP server URL which the agent will connect to
6077
+ * for retrieving additional instructions and actions.
6078
+ *
6079
+ * The content following `USE MCP` is the URL of the MCP server.
6080
+ *
6081
+ * Example usage in agent source:
6082
+ *
6083
+ * ```book
6084
+ * USE MCP http://mcp-server-url.com
6085
+ * ```
6086
+ *
6087
+ * @private [🪔] Maybe export the commitments through some package
6088
+ */
6089
+ class UseMcpCommitmentDefinition extends BaseCommitmentDefinition {
6090
+ constructor() {
6091
+ super('USE MCP', ['MCP']);
6092
+ }
6093
+ /**
6094
+ * Short one-line description of USE MCP.
6095
+ */
6096
+ get description() {
6097
+ return 'Connects the agent to an external MCP server for additional capabilities.';
6098
+ }
6099
+ /**
6100
+ * Icon for this commitment.
6101
+ */
6102
+ get icon() {
6103
+ return '🔌';
6104
+ }
6105
+ /**
6106
+ * Markdown documentation for USE MCP commitment.
6107
+ */
6108
+ get documentation() {
6109
+ return spaceTrim$1(`
6110
+ # USE MCP
6111
+
6112
+ Connects the agent to an external Model Context Protocol (MCP) server.
6113
+
6114
+ ## Key aspects
6115
+
6116
+ - The content following \`USE MCP\` must be a valid URL
6117
+ - Multiple MCP servers can be connected by using multiple \`USE MCP\` commitments
6118
+ - The agent will have access to tools and resources provided by the MCP server
6119
+
6120
+ ## Example
6121
+
6122
+ \`\`\`book
6123
+ Company Lawyer
6124
+
6125
+ PERSONA You are a company lawyer.
6126
+ USE MCP http://legal-db.example.com
6127
+ \`\`\`
6128
+ `);
6129
+ }
6130
+ applyToAgentModelRequirements(requirements, content) {
6131
+ const mcpServerUrl = content.trim();
6132
+ if (!mcpServerUrl) {
6133
+ return requirements;
6134
+ }
6135
+ const existingMcpServers = requirements.mcpServers || [];
6136
+ // Avoid duplicates
6137
+ if (existingMcpServers.includes(mcpServerUrl)) {
6138
+ return requirements;
6139
+ }
6140
+ return {
6141
+ ...requirements,
6142
+ mcpServers: [...existingMcpServers, mcpServerUrl],
6143
+ };
6144
+ }
6145
+ }
6146
+ /**
6147
+ * Note: [💞] Ignore a discrepancy between file name and entity name
6148
+ */
6149
+
6150
+ /**
6151
+ * USE SEARCH ENGINE commitment definition
6152
+ *
6153
+ * The `USE SEARCH ENGINE` commitment indicates that the agent should utilize a search engine tool
6154
+ * to access and retrieve up-to-date information from the internet when necessary.
6155
+ *
6156
+ * The content following `USE SEARCH ENGINE` is an arbitrary text that the agent should know (e.g. search scope or instructions).
6157
+ *
6158
+ * Example usage in agent source:
6159
+ *
6160
+ * ```book
6161
+ * USE SEARCH ENGINE
6162
+ * USE SEARCH ENGINE Hledej informace o Přemyslovcích
6163
+ * ```
6164
+ *
6165
+ * @private [🪔] Maybe export the commitments through some package
6166
+ */
6167
+ class UseSearchEngineCommitmentDefinition extends BaseCommitmentDefinition {
6168
+ constructor() {
6169
+ super('USE SEARCH ENGINE', ['SEARCH ENGINE', 'SEARCH']);
6170
+ }
6171
+ /**
6172
+ * Short one-line description of USE SEARCH ENGINE.
6173
+ */
6174
+ get description() {
6175
+ return 'Enable the agent to use a search engine tool for accessing internet information.';
6176
+ }
6177
+ /**
6178
+ * Icon for this commitment.
6179
+ */
6180
+ get icon() {
6181
+ return '🔍';
6182
+ }
6183
+ /**
6184
+ * Markdown documentation for USE SEARCH ENGINE commitment.
6185
+ */
6186
+ get documentation() {
6187
+ return spaceTrim$1(`
6188
+ # USE SEARCH ENGINE
6189
+
6190
+ Enables the agent to use a search engine tool to access and retrieve up-to-date information from the internet.
6191
+
6192
+ ## Key aspects
6193
+
6194
+ - The content following \`USE SEARCH ENGINE\` is an arbitrary text that the agent should know (e.g. search scope or instructions).
6195
+ - The actual search engine tool usage is handled by the agent runtime
6196
+ - Allows the agent to search for current information from the web
6197
+ - Useful for research tasks, finding facts, and accessing dynamic content
6198
+
6199
+ ## Examples
6200
+
6201
+ \`\`\`book
6202
+ Research Assistant
6203
+
6204
+ PERSONA You are a helpful research assistant specialized in finding current information
6205
+ USE SEARCH ENGINE
6206
+ RULE Always cite your sources when providing information from the web
6207
+ \`\`\`
6208
+
6209
+ \`\`\`book
6210
+ Fact Checker
6211
+
6212
+ PERSONA You are a fact checker
6213
+ USE SEARCH ENGINE
6214
+ ACTION Search for claims and verify them against reliable sources
6215
+ \`\`\`
6216
+ `);
6217
+ }
6218
+ applyToAgentModelRequirements(requirements, content) {
6219
+ // Get existing tools array or create new one
6220
+ const existingTools = requirements.tools || [];
6221
+ // Add 'web_search' to tools if not already present
6222
+ const updatedTools = existingTools.some((tool) => tool.name === 'web_search')
6223
+ ? existingTools
6224
+ : [
6225
+ ...existingTools,
6226
+ { type: 'web_search' },
6227
+ // <- Note: [🔰] This is just using simple native search tool by OpenAI @see https://platform.openai.com/docs/guides/tools-web-search
6228
+ // In future we will use proper MCP search tool:
6229
+ /*
6230
+
6231
+ {
6232
+ name: 'web_search',
6233
+ description: spaceTrim(`
6234
+ Search the internet for information.
6235
+ Use this tool when you need to find up-to-date information or facts that you don't know.
6236
+ ${!content ? '' : `Search scope / instructions: ${content}`}
6237
+ `),
6238
+ parameters: {
6239
+ type: 'object',
6240
+ properties: {
6241
+ query: {
6242
+ type: 'string',
6243
+ description: 'The search query',
6244
+ },
6245
+ },
6246
+ required: ['query'],
6247
+ },
6248
+ },
6249
+ */
6250
+ ];
6251
+ // Return requirements with updated tools and metadata
6252
+ return {
6253
+ ...requirements,
6254
+ tools: updatedTools,
6255
+ metadata: {
6256
+ ...requirements.metadata,
6257
+ useSearchEngine: content || true,
6258
+ },
6259
+ };
6260
+ }
6261
+ }
6262
+ /**
6263
+ * Note: [💞] Ignore a discrepancy between file name and entity name
6264
+ */
6265
+
6266
+ /**
6267
+ * USE TIME commitment definition
6268
+ *
6269
+ * The `USE TIME` commitment indicates that the agent should be able to determine the current date and time.
6270
+ *
6271
+ * Example usage in agent source:
6272
+ *
6273
+ * ```book
6274
+ * USE TIME
6275
+ * ```
6276
+ *
6277
+ * @private [🪔] Maybe export the commitments through some package
6278
+ */
6279
+ class UseTimeCommitmentDefinition extends BaseCommitmentDefinition {
6280
+ constructor() {
6281
+ super('USE TIME', ['CURRENT TIME', 'TIME', 'DATE']);
6282
+ }
6283
+ /**
6284
+ * Short one-line description of USE TIME.
6285
+ */
6286
+ get description() {
6287
+ return 'Enable the agent to determine the current date and time.';
6288
+ }
6289
+ /**
6290
+ * Icon for this commitment.
6291
+ */
6292
+ get icon() {
6293
+ return '🕒';
6294
+ }
6295
+ /**
6296
+ * Markdown documentation for USE TIME commitment.
6297
+ */
6298
+ get documentation() {
6299
+ return spaceTrim$1(`
6300
+ # USE TIME
6301
+
6302
+ Enables the agent to determine the current date and time.
6303
+
6304
+ ## Key aspects
6305
+
6306
+ - This tool won't receive any input.
6307
+ - It outputs the current date and time as an ISO 8601 string.
6308
+ - Allows the agent to answer questions about the current time or date.
6309
+
6310
+ ## Examples
6311
+
6312
+ \`\`\`book
6313
+ Time-aware Assistant
6314
+
6315
+ PERSONA You are a helpful assistant who knows the current time.
6316
+ USE TIME
6317
+ \`\`\`
6318
+ `);
6319
+ }
6320
+ applyToAgentModelRequirements(requirements, content) {
6321
+ // Get existing tools array or create new one
6322
+ const existingTools = requirements.tools || [];
6323
+ // Add 'get_current_time' to tools if not already present
6324
+ const updatedTools = existingTools.some((tool) => tool.name === 'get_current_time')
6325
+ ? existingTools
6326
+ : [
6327
+ ...existingTools,
6328
+ {
6329
+ name: 'get_current_time',
6330
+ description: 'Get the current date and time in ISO 8601 format.',
6331
+ parameters: {
6332
+ type: 'object',
6333
+ properties: {
6334
+ timezone: {
6335
+ type: 'string',
6336
+ description: 'Optional timezone name (e.g. "Europe/Prague", "UTC", "America/New_York").',
6337
+ },
6338
+ },
6339
+ required: [],
6340
+ },
6341
+ },
6342
+ // <- TODO: !!!! define the function in LLM tools
6343
+ ];
6344
+ // Return requirements with updated tools and metadata
6345
+ return {
6346
+ ...requirements,
6347
+ tools: updatedTools,
6348
+ metadata: {
6349
+ ...requirements.metadata,
6350
+ },
6351
+ };
6352
+ }
6353
+ /**
6354
+ * Gets the `get_current_time` tool function implementation.
6355
+ */
6356
+ getToolFunctions() {
6357
+ return {
6358
+ async get_current_time(args) {
6359
+ var _a;
6360
+ console.log('!!!! [Tool] get_current_time called', { args });
6361
+ const { timezone } = args;
6362
+ if (!timezone) {
6363
+ return new Date().toISOString();
6364
+ }
6365
+ try {
6366
+ // Note: Returning ISO 8601 string but in the requested timezone
6367
+ const formatter = new Intl.DateTimeFormat('en-CA', {
6368
+ timeZone: timezone,
6369
+ year: 'numeric',
6370
+ month: '2-digit',
6371
+ day: '2-digit',
6372
+ hour: '2-digit',
6373
+ minute: '2-digit',
6374
+ second: '2-digit',
6375
+ hour12: false,
6376
+ timeZoneName: 'shortOffset',
6377
+ });
6378
+ const parts = formatter.formatToParts(new Date());
6379
+ const part = (type) => { var _a; return (_a = parts.find((p) => p.type === type)) === null || _a === void 0 ? void 0 : _a.value; };
6380
+ // en-CA format is YYYY-MM-DD
6381
+ const isoString = `${part('year')}-${part('month')}-${part('day')}T${part('hour')}:${part('minute')}:${part('second')}${(_a = part('timeZoneName')) === null || _a === void 0 ? void 0 : _a.replace('GMT', '')}`;
6382
+ return isoString;
6383
+ }
6384
+ catch (error) {
6385
+ // Fallback to UTC if timezone is invalid
6386
+ return new Date().toISOString();
6387
+ }
6388
+ },
6389
+ };
6390
+ }
6391
+ }
6392
+ /**
6393
+ * Note: [💞] Ignore a discrepancy between file name and entity name
6394
+ */
6395
+
6396
+ /**
6397
+ * Placeholder commitment definition for commitments that are not yet implemented
6398
+ *
6399
+ * This commitment simply adds its content 1:1 into the system message,
6400
+ * preserving the original behavior until proper implementation is added.
6401
+ *
6402
+ * @public exported from `@promptbook/core`
6403
+ */
6404
+ class NotYetImplementedCommitmentDefinition extends BaseCommitmentDefinition {
6405
+ constructor(type) {
6406
+ super(type);
6407
+ }
6408
+ /**
6409
+ * Short one-line description of a placeholder commitment.
6410
+ */
6411
+ get description() {
6412
+ return 'Placeholder commitment that appends content verbatim to the system message.';
6413
+ }
6414
+ /**
6415
+ * Icon for this commitment.
6416
+ */
6417
+ get icon() {
6418
+ return '🚧';
6419
+ }
6420
+ /**
6421
+ * Markdown documentation available at runtime.
6422
+ */
6423
+ get documentation() {
6424
+ return spaceTrim$1(`
6425
+ # ${this.type}
6426
+
6427
+ This commitment is not yet fully implemented.
6428
+
6429
+ ## Key aspects
6430
+
6431
+ - Content is appended directly to the system message.
6432
+ - No special processing or validation is performed.
6433
+ - Behavior preserved until proper implementation is added.
6434
+
6435
+ ## Status
6436
+
6437
+ - **Status:** Placeholder implementation
6438
+ - **Effect:** Appends content prefixed by commitment type
6439
+ - **Future:** Will be replaced with specialized logic
6440
+
6441
+ ## Examples
6442
+
6443
+ \`\`\`book
6444
+ Example Agent
6445
+
6446
+ PERSONA You are a helpful assistant
6447
+ ${this.type} Your content here
6448
+ RULE Always be helpful
6449
+ \`\`\`
6450
+ `);
6451
+ }
6452
+ applyToAgentModelRequirements(requirements, content) {
6453
+ const trimmedContent = content.trim();
6454
+ if (!trimmedContent) {
6455
+ return requirements;
6456
+ }
6457
+ // Add the commitment content 1:1 to the system message
6458
+ const commitmentLine = `${this.type} ${trimmedContent}`;
6459
+ return this.appendToSystemMessage(requirements, commitmentLine, '\n\n');
6460
+ }
6461
+ }
6462
+
6463
+ /**
6464
+ * Registry of all available commitment definitions
6465
+ * This array contains instances of all commitment definitions
6466
+ * This is the single source of truth for all commitments in the system
6467
+ *
6468
+ * @private Use functions to access commitments instead of this array directly
6469
+ */
6470
+ const COMMITMENT_REGISTRY = [
6471
+ // Fully implemented commitments
6472
+ new PersonaCommitmentDefinition('PERSONA'),
6473
+ new PersonaCommitmentDefinition('PERSONAE'),
6474
+ new KnowledgeCommitmentDefinition(),
6475
+ new MemoryCommitmentDefinition('MEMORY'),
6476
+ new MemoryCommitmentDefinition('MEMORIES'),
6477
+ new StyleCommitmentDefinition('STYLE'),
6478
+ new StyleCommitmentDefinition('STYLES'),
6479
+ new RuleCommitmentDefinition('RULES'),
6480
+ new RuleCommitmentDefinition('RULE'),
6481
+ new LanguageCommitmentDefinition('LANGUAGES'),
6482
+ new LanguageCommitmentDefinition('LANGUAGE'),
6483
+ new SampleCommitmentDefinition('SAMPLE'),
6484
+ new SampleCommitmentDefinition('EXAMPLE'),
6485
+ new FormatCommitmentDefinition('FORMAT'),
6486
+ new FormatCommitmentDefinition('FORMATS'),
6487
+ new FromCommitmentDefinition('FROM'),
6488
+ new ImportCommitmentDefinition('IMPORT'),
6489
+ new ImportCommitmentDefinition('IMPORTS'),
6490
+ new ModelCommitmentDefinition('MODEL'),
6491
+ new ModelCommitmentDefinition('MODELS'),
6492
+ new ActionCommitmentDefinition('ACTION'),
6493
+ new ActionCommitmentDefinition('ACTIONS'),
6494
+ new ComponentCommitmentDefinition(),
6495
+ new MetaImageCommitmentDefinition(),
6496
+ new MetaColorCommitmentDefinition(),
6497
+ new MetaFontCommitmentDefinition(),
6498
+ new MetaLinkCommitmentDefinition(),
6499
+ new MetaCommitmentDefinition(),
6500
+ new NoteCommitmentDefinition('NOTE'),
6501
+ new NoteCommitmentDefinition('NOTES'),
6502
+ new NoteCommitmentDefinition('COMMENT'),
6503
+ new NoteCommitmentDefinition('NONCE'),
6504
+ new GoalCommitmentDefinition('GOAL'),
6505
+ new GoalCommitmentDefinition('GOALS'),
6506
+ new InitialMessageCommitmentDefinition(),
6507
+ new UserMessageCommitmentDefinition(),
6508
+ new AgentMessageCommitmentDefinition(),
6509
+ new MessageCommitmentDefinition('MESSAGE'),
6510
+ new MessageCommitmentDefinition('MESSAGES'),
6511
+ new ScenarioCommitmentDefinition('SCENARIO'),
6512
+ new ScenarioCommitmentDefinition('SCENARIOS'),
6513
+ new DeleteCommitmentDefinition('DELETE'),
6514
+ new DeleteCommitmentDefinition('CANCEL'),
6515
+ new DeleteCommitmentDefinition('DISCARD'),
6516
+ new DeleteCommitmentDefinition('REMOVE'),
6517
+ new DictionaryCommitmentDefinition(),
6518
+ new OpenCommitmentDefinition(),
6519
+ new ClosedCommitmentDefinition(),
6520
+ new UseBrowserCommitmentDefinition(),
6521
+ new UseSearchEngineCommitmentDefinition(),
6522
+ new UseTimeCommitmentDefinition(),
6523
+ new UseMcpCommitmentDefinition(),
6524
+ new UseCommitmentDefinition(),
6525
+ // Not yet implemented commitments (using placeholder)
6526
+ new NotYetImplementedCommitmentDefinition('EXPECT'),
6527
+ new NotYetImplementedCommitmentDefinition('BEHAVIOUR'),
6528
+ new NotYetImplementedCommitmentDefinition('BEHAVIOURS'),
6529
+ new NotYetImplementedCommitmentDefinition('AVOID'),
6530
+ new NotYetImplementedCommitmentDefinition('AVOIDANCE'),
6531
+ new NotYetImplementedCommitmentDefinition('CONTEXT'),
6532
+ ];
6533
+ /**
6534
+ * Gets all available commitment definitions
6535
+ * @returns Array of all commitment definitions
6536
+ *
6537
+ * @public exported from `@promptbook/core`
6538
+ */
6539
+ function getAllCommitmentDefinitions() {
6540
+ return $deepFreeze([...COMMITMENT_REGISTRY]);
6541
+ }
6542
+ /**
6543
+ * Gets all function implementations provided by all commitments
6544
+ *
6545
+ * @public exported from `@promptbook/core`
6546
+ */
6547
+ function getAllCommitmentsToolFunctions() {
6548
+ const allToolFunctions = {};
6549
+ for (const commitmentDefinition of getAllCommitmentDefinitions()) {
6550
+ const toolFunctions = commitmentDefinition.getToolFunctions();
6551
+ for (const [funcName, funcImpl] of Object.entries(toolFunctions)) {
6552
+ allToolFunctions[funcName] = funcImpl;
6553
+ }
6554
+ }
6555
+ return allToolFunctions;
6556
+ }
6557
+ /**
6558
+ * TODO: [🧠] Maybe create through standardized $register
6559
+ * Note: [💞] Ignore a discrepancy between file name and entity name
6560
+ */
6561
+
6562
+ /**
6563
+ * Extracts all code blocks from markdown.
6564
+ *
6565
+ * Note: There are multiple similar functions:
6566
+ * - `extractBlock` just extracts the content of the code block which is also used as built-in function for postprocessing
6567
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
6568
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
6569
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
6570
+ *
6571
+ * @param markdown any valid markdown
6572
+ * @returns code blocks with language and content
6573
+ * @throws {ParseError} if block is not closed properly
6574
+ * @public exported from `@promptbook/markdown-utils`
6575
+ */
6576
+ function extractAllBlocksFromMarkdown(markdown) {
6577
+ const codeBlocks = [];
6578
+ const lines = markdown.split('\n');
6579
+ // Note: [0] Ensure that the last block notated by gt > will be closed
6580
+ lines.push('');
6581
+ let currentCodeBlock = null;
6582
+ for (const line of lines) {
6583
+ if (line.startsWith('> ') || line === '>') {
6584
+ if (currentCodeBlock === null) {
6585
+ currentCodeBlock = { blockNotation: '>', language: null, content: '' };
6586
+ } /* not else */
6587
+ if (currentCodeBlock.blockNotation === '>') {
6588
+ if (currentCodeBlock.content !== '') {
6589
+ currentCodeBlock.content += '\n';
6590
+ }
6591
+ currentCodeBlock.content += line.slice(2);
6592
+ }
6593
+ }
6594
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '>' /* <- Note: [0] */) {
6595
+ codeBlocks.push(currentCodeBlock);
6596
+ currentCodeBlock = null;
6597
+ }
6598
+ /* not else */
6599
+ if (line.startsWith('```')) {
6600
+ const language = line.slice(3).trim() || null;
6601
+ if (currentCodeBlock === null) {
6602
+ currentCodeBlock = { blockNotation: '```', language, content: '' };
6603
+ }
6604
+ else {
6605
+ if (language !== null) {
6606
+ throw new ParseError(`${capitalize(currentCodeBlock.language || 'the')} code block was not closed and already opening new ${language} code block`);
6607
+ }
6608
+ codeBlocks.push(currentCodeBlock);
6609
+ currentCodeBlock = null;
6610
+ }
6611
+ }
6612
+ else if (currentCodeBlock !== null && currentCodeBlock.blockNotation === '```') {
6613
+ if (currentCodeBlock.content !== '') {
6614
+ currentCodeBlock.content += '\n';
6615
+ }
6616
+ currentCodeBlock.content += line.split('\\`\\`\\`').join('```') /* <- TODO: Maybe make proper unescape */;
6617
+ }
6618
+ }
6619
+ if (currentCodeBlock !== null) {
6620
+ throw new ParseError(`${capitalize(currentCodeBlock.language || 'the')} code block was not closed at the end of the markdown`);
6621
+ }
6622
+ return codeBlocks;
6623
+ }
6624
+ /**
6625
+ * TODO: Maybe name for `blockNotation` instead of '```' and '>'
6626
+ */
6627
+
6628
+ /**
6629
+ * Extracts exactly ONE code block from markdown.
6630
+ *
6631
+ * - When there are multiple or no code blocks the function throws a `ParseError`
6632
+ *
6633
+ * Note: There are multiple similar functions:
6634
+ * - `extractBlock` just extracts the content of the code block which is also used as built-in function for postprocessing
6635
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
6636
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
6637
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
6638
+ *
6639
+ * @param markdown any valid markdown
6640
+ * @returns code block with language and content
6641
+ * @public exported from `@promptbook/markdown-utils`
6642
+ * @throws {ParseError} if there is not exactly one code block in the markdown
6643
+ */
6644
+ function extractOneBlockFromMarkdown(markdown) {
6645
+ const codeBlocks = extractAllBlocksFromMarkdown(markdown);
6646
+ if (codeBlocks.length !== 1) {
6647
+ throw new ParseError(spaceTrim$2((block) => `
6648
+ There should be exactly 1 code block in task section, found ${codeBlocks.length} code blocks
6649
+
6650
+ ${block(codeBlocks.map((block, i) => `Block ${i + 1}:\n${block.content}`).join('\n\n\n'))}
6651
+ `));
6652
+ }
6653
+ return codeBlocks[0];
6654
+ }
6655
+ /***
6656
+ * TODO: [🍓][🌻] Decide of this is internal utility, external util OR validator/postprocessor
6657
+ */
6658
+
6659
+ /**
6660
+ * Extracts code block from markdown.
6661
+ *
6662
+ * - When there are multiple or no code blocks the function throws a `ParseError`
6663
+ *
6664
+ * Note: There are multiple similar function:
6665
+ * - `extractBlock` just extracts the content of the code block which is also used as build-in function for postprocessing
6666
+ * - `extractJsonBlock` extracts exactly one valid JSON code block
6667
+ * - `extractOneBlockFromMarkdown` extracts exactly one code block with language of the code block
6668
+ * - `extractAllBlocksFromMarkdown` extracts all code blocks with language of the code block
6669
+ *
6670
+ * @public exported from `@promptbook/markdown-utils`
6671
+ * @throws {ParseError} if there is not exactly one code block in the markdown
6672
+ */
6673
+ function extractBlock(markdown) {
6674
+ const { content } = extractOneBlockFromMarkdown(markdown);
6675
+ return content;
6676
+ }
6677
+
6678
+ /**
6679
+ * Prettify the html code
6680
+ *
6681
+ * @param content raw html code
6682
+ * @returns formatted html code
6683
+ * @private withing the package because of HUGE size of prettier dependency
6684
+ * @deprecated Prettier removed from Promptbook due to package size
6685
+ */
6686
+ function prettifyMarkdown(content) {
6687
+ return (content + `\n\n<!-- Note: Prettier removed from Promptbook -->`);
6688
+ }
6689
+
6690
+ /**
6691
+ * Function trimCodeBlock will trim starting and ending code block from the string if it is present.
6692
+ *
6693
+ * Note: [🔂] This function is idempotent.
6694
+ * Note: This is useful for post-processing of the result of the chat LLM model
6695
+ * when the model wraps the result in the (markdown) code block.
6696
+ *
6697
+ * @public exported from `@promptbook/markdown-utils`
6698
+ */
6699
+ function trimCodeBlock(value) {
6700
+ value = spaceTrim$1(value);
6701
+ if (!/^```[a-z]*(.*)```$/is.test(value)) {
6702
+ return value;
6703
+ }
6704
+ value = value.replace(/^```[a-z]*/i, '');
6705
+ value = value.replace(/```$/i, '');
6706
+ value = spaceTrim$1(value);
6707
+ return value;
6708
+ }
6709
+
6710
+ /**
6711
+ * Function trimEndOfCodeBlock will remove ending code block from the string if it is present.
6712
+ *
6713
+ * Note: This is useful for post-processing of the result of the completion LLM model
6714
+ * if you want to start code block in the prompt but you don't want to end it in the result.
6715
+ *
6716
+ * @public exported from `@promptbook/markdown-utils`
6717
+ */
6718
+ function trimEndOfCodeBlock(value) {
6719
+ value = spaceTrim$1(value);
6720
+ value = value.replace(/```$/g, '');
6721
+ value = spaceTrim$1(value);
6722
+ return value;
6723
+ }
6724
+
6725
+ /**
6726
+ * @private internal for `preserve`
6727
+ */
6728
+ const _preserved = [];
6729
+ /**
6730
+ * Does nothing, but preserves the function in the bundle
6731
+ * Compiler is tricked into thinking the function is used
6732
+ *
6733
+ * @param value any function to preserve
6734
+ * @returns nothing
6735
+ * @private within the repository
6736
+ */
6737
+ function $preserve(...value) {
6738
+ _preserved.push(...value);
6739
+ }
6740
+ /**
6741
+ * Note: [💞] Ignore a discrepancy between file name and entity name
6742
+ */
6743
+
6744
+ // Note: [💎]
6745
+ /**
6746
+ * ScriptExecutionTools for JavaScript implemented via eval
6747
+ *
6748
+ * Warning: It is used for testing and mocking
2927
6749
  * **NOT intended to use in the production** due to its unsafe nature, use `JavascriptExecutionTools` instead.
2928
6750
  *
2929
6751
  * @public exported from `@promptbook/javascript`
@@ -3026,6 +6848,13 @@ class JavascriptEvalExecutionTools {
3026
6848
  `const ${functionName} = buildinFunctions.${functionName};`)
3027
6849
  .join('\n');
3028
6850
  // TODO: DRY [🍯]
6851
+ const commitmentsFunctions = getAllCommitmentsToolFunctions();
6852
+ const commitmentsFunctionsStatement = Object.keys(commitmentsFunctions)
6853
+ .map((functionName) =>
6854
+ // Note: Custom functions are exposed to the current scope as variables
6855
+ `const ${functionName} = commitmentsFunctions.${functionName};`)
6856
+ .join('\n');
6857
+ // TODO: DRY [🍯]
3029
6858
  const customFunctions = this.options.functions || {};
3030
6859
  const customFunctionsStatement = Object.keys(customFunctions)
3031
6860
  .map((functionName) =>
@@ -3039,6 +6868,10 @@ class JavascriptEvalExecutionTools {
3039
6868
  // Build-in functions:
3040
6869
  ${block(buildinFunctionsStatement)}
3041
6870
 
6871
+ // Commitments functions:
6872
+ ${block(commitmentsFunctionsStatement)}
6873
+
6874
+
3042
6875
  // Custom functions:
3043
6876
  ${block(customFunctionsStatement || '// -- No custom functions --')}
3044
6877
 
@@ -3046,7 +6879,7 @@ class JavascriptEvalExecutionTools {
3046
6879
  ${block(Object.entries(parameters)
3047
6880
  .map(([key, value]) => `const ${key} = ${JSON.stringify(value)};`)
3048
6881
  .join('\n'))}
3049
- (()=>{ ${script} })()
6882
+ (async ()=>{ ${script} })()
3050
6883
  `);
3051
6884
  if (this.options.isVerbose) {
3052
6885
  console.info(spaceTrim$2((block) => `