@ax-llm/ax 16.0.7 → 16.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.d.cts CHANGED
@@ -823,14 +823,14 @@ declare class AxSignatureBuilder<_TInput extends Record<string, any> = {}, _TOut
823
823
  * @param fieldInfo - Field type created with f.string(), f.number(), etc.
824
824
  * @param prepend - If true, adds field to the beginning of input fields
825
825
  */
826
- input<K extends string, T extends AxFluentFieldInfo<any, any, any, any, any, any> | AxFluentFieldType<any, any, any, any, any, any>>(name: K, fieldInfo: T, prepend?: boolean): AxSignatureBuilder<AddFieldToShape<_TInput, K, T>, _TOutput>;
826
+ input<K extends string, T extends AxFluentFieldInfo<any, any, any, any, any, any, any> | AxFluentFieldType<any, any, any, any, any, any, any>>(name: K, fieldInfo: T, prepend?: boolean): AxSignatureBuilder<AddFieldToShape<_TInput, K, T>, _TOutput>;
827
827
  /**
828
828
  * Add an output field to the signature
829
829
  * @param name - Field name
830
830
  * @param fieldInfo - Field type created with f.string(), f.number(), etc.
831
831
  * @param prepend - If true, adds field to the beginning of output fields
832
832
  */
833
- output<K extends string, T extends AxFluentFieldInfo<any, any, any, any, any, any> | AxFluentFieldType<any, any, any, any, any, any>>(name: K, fieldInfo: T, prepend?: boolean): AxSignatureBuilder<_TInput, AddFieldToShape<_TOutput, K, T>>;
833
+ output<K extends string, T extends AxFluentFieldInfo<any, any, any, any, any, any, any> | AxFluentFieldType<any, any, any, any, any, any, any>>(name: K, fieldInfo: T, prepend?: boolean): AxSignatureBuilder<_TInput, AddFieldToShape<_TOutput, K, T>>;
834
834
  /**
835
835
  * Set the description for the signature
836
836
  * @param description - Description text
@@ -845,13 +845,14 @@ declare class AxSignatureBuilder<_TInput extends Record<string, any> = {}, _TOut
845
845
  */
846
846
  build(): AxSignature<_TInput, _TOutput>;
847
847
  }
848
- declare class AxFluentFieldType<TType extends AxFieldType['type'] = AxFieldType['type'], TIsArray extends boolean = false, TOptions extends readonly string[] | undefined = undefined, TIsOptional extends boolean = false, TIsInternal extends boolean = false, TFields extends Record<string, AxFluentFieldInfo | AxFluentFieldType> | undefined = undefined> implements AxFieldType {
848
+ declare class AxFluentFieldType<TType extends AxFieldType['type'] = AxFieldType['type'], TIsArray extends boolean = false, TOptions extends readonly string[] | undefined = undefined, TIsOptional extends boolean = false, TIsInternal extends boolean = false, TFields extends Record<string, AxFluentFieldInfo | AxFluentFieldType> | undefined = undefined, TIsCached extends boolean = false> implements AxFieldType {
849
849
  readonly type: TType;
850
850
  readonly isArray: TIsArray;
851
851
  readonly options?: TOptions;
852
852
  readonly description?: string;
853
853
  readonly isOptional: TIsOptional;
854
854
  readonly isInternal: TIsInternal;
855
+ readonly isCached: TIsCached;
855
856
  readonly fields?: any;
856
857
  readonly minLength?: number;
857
858
  readonly maxLength?: number;
@@ -869,6 +870,7 @@ declare class AxFluentFieldType<TType extends AxFieldType['type'] = AxFieldType[
869
870
  itemDescription?: string;
870
871
  isOptional: TIsOptional;
871
872
  isInternal: TIsInternal;
873
+ isCached: TIsCached;
872
874
  fields?: TFields;
873
875
  minLength?: number;
874
876
  maxLength?: number;
@@ -878,39 +880,45 @@ declare class AxFluentFieldType<TType extends AxFieldType['type'] = AxFieldType[
878
880
  patternDescription?: string;
879
881
  format?: string;
880
882
  });
881
- optional(): AxFluentFieldType<TType, TIsArray, TOptions, true, TIsInternal, TFields>;
882
- array(desc?: string): AxFluentFieldType<TType, true, TOptions, TIsOptional, TIsInternal, TFields>;
883
- internal(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, true, TFields>;
883
+ optional(): AxFluentFieldType<TType, TIsArray, TOptions, true, TIsInternal, TFields, TIsCached>;
884
+ array(desc?: string): AxFluentFieldType<TType, true, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
885
+ internal(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, true, TFields, TIsCached>;
886
+ /**
887
+ * Mark this input field for caching. When contextCache is enabled,
888
+ * cached fields are rendered in a separate user message with cache: true,
889
+ * allowing them to be cached by the LLM provider.
890
+ */
891
+ cache(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, true>;
884
892
  /**
885
893
  * Set minimum value for numbers or minimum length for strings
886
894
  */
887
- min(value: number): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields>;
895
+ min(value: number): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
888
896
  /**
889
897
  * Set maximum value for numbers or maximum length for strings
890
898
  */
891
- max(value: number): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields>;
899
+ max(value: number): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
892
900
  /**
893
901
  * Set email format validation for strings
894
902
  */
895
- email(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields>;
903
+ email(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
896
904
  /**
897
905
  * Set URL/URI format validation for strings
898
906
  */
899
- url(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields>;
907
+ url(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
900
908
  /**
901
909
  * Set regex pattern validation for strings
902
910
  * @param pattern - Regular expression pattern to match
903
911
  * @param description - Human-readable description of what the pattern validates (e.g., "Must be a valid username with only lowercase letters, numbers, and underscores")
904
912
  */
905
- regex(pattern: string, description: string): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields>;
913
+ regex(pattern: string, description: string): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
906
914
  /**
907
915
  * Set date format validation for strings
908
916
  */
909
- date(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields>;
917
+ date(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
910
918
  /**
911
919
  * Set datetime format validation for strings
912
920
  */
913
- datetime(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields>;
921
+ datetime(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
914
922
  }
915
923
  type ValidateNoMediaTypes<TFields> = {
916
924
  [K in keyof TFields]: TFields[K] extends {
@@ -925,20 +933,20 @@ type ValidateNoMediaTypes<TFields> = {
925
933
  } : TFields[K] : TFields[K] : TFields[K];
926
934
  };
927
935
  declare const f: (() => AxSignatureBuilder) & {
928
- string: (desc?: string) => AxFluentFieldType<"string", false, undefined, false, false, undefined>;
929
- number: (desc?: string) => AxFluentFieldType<"number", false, undefined, false, false, undefined>;
930
- boolean: (desc?: string) => AxFluentFieldType<"boolean", false, undefined, false, false, undefined>;
931
- json: (desc?: string) => AxFluentFieldType<"json", false, undefined, false, false, undefined>;
932
- datetime: (desc?: string) => AxFluentFieldType<"datetime", false, undefined, false, false, undefined>;
933
- date: (desc?: string) => AxFluentFieldType<"date", false, undefined, false, false, undefined>;
934
- class: <const TOptions extends readonly string[]>(options: TOptions, desc?: string) => AxFluentFieldType<"class", false, TOptions, false, false, undefined>;
935
- image: (desc?: string) => AxFluentFieldType<"image", false, undefined, false, false, undefined>;
936
- audio: (desc?: string) => AxFluentFieldType<"audio", false, undefined, false, false, undefined>;
937
- file: (desc?: string) => AxFluentFieldType<"file", false, undefined, false, false, undefined>;
938
- url: (desc?: string) => AxFluentFieldType<"url", false, undefined, false, false, undefined>;
939
- email: (desc?: string) => AxFluentFieldType<"string", false, undefined, false, false, undefined>;
940
- code: (language?: string, desc?: string) => AxFluentFieldType<"code", false, undefined, false, false, undefined>;
941
- object: <TFields extends Record<string, AxFluentFieldInfo<any, any, any, any, any, any> | AxFluentFieldType<any, any, any, any, any, any>>>(fields: TFields & ValidateNoMediaTypes<TFields>, desc?: string) => AxFluentFieldType<"object", false, undefined, false, false, TFields>;
936
+ string: (desc?: string) => AxFluentFieldType<"string", false, undefined, false, false, undefined, false>;
937
+ number: (desc?: string) => AxFluentFieldType<"number", false, undefined, false, false, undefined, false>;
938
+ boolean: (desc?: string) => AxFluentFieldType<"boolean", false, undefined, false, false, undefined, false>;
939
+ json: (desc?: string) => AxFluentFieldType<"json", false, undefined, false, false, undefined, false>;
940
+ datetime: (desc?: string) => AxFluentFieldType<"datetime", false, undefined, false, false, undefined, false>;
941
+ date: (desc?: string) => AxFluentFieldType<"date", false, undefined, false, false, undefined, false>;
942
+ class: <const TOptions extends readonly string[]>(options: TOptions, desc?: string) => AxFluentFieldType<"class", false, TOptions, false, false, undefined, false>;
943
+ image: (desc?: string) => AxFluentFieldType<"image", false, undefined, false, false, undefined, false>;
944
+ audio: (desc?: string) => AxFluentFieldType<"audio", false, undefined, false, false, undefined, false>;
945
+ file: (desc?: string) => AxFluentFieldType<"file", false, undefined, false, false, undefined, false>;
946
+ url: (desc?: string) => AxFluentFieldType<"url", false, undefined, false, false, undefined, false>;
947
+ email: (desc?: string) => AxFluentFieldType<"string", false, undefined, false, false, undefined, false>;
948
+ code: (language?: string, desc?: string) => AxFluentFieldType<"code", false, undefined, false, false, undefined, false>;
949
+ object: <TFields extends Record<string, AxFluentFieldInfo<any, any, any, any, any, any, any> | AxFluentFieldType<any, any, any, any, any, any, any>>>(fields: TFields & ValidateNoMediaTypes<TFields>, desc?: string) => AxFluentFieldType<"object", false, undefined, false, false, TFields, false>;
942
950
  };
943
951
  interface AxField {
944
952
  name: string;
@@ -960,6 +968,7 @@ interface AxField {
960
968
  };
961
969
  isOptional?: boolean;
962
970
  isInternal?: boolean;
971
+ isCached?: boolean;
963
972
  }
964
973
  type AxIField = Omit<AxField, 'title'> & {
965
974
  title: string;
@@ -995,7 +1004,7 @@ type InferFieldValueType<T> = T extends AxFieldType | AxFluentFieldType ? T['typ
995
1004
  }[] : {
996
1005
  [K in keyof F]: InferFluentType<F[K]>;
997
1006
  } : any : any : any : any;
998
- interface AxFluentFieldInfo<TType extends AxFieldType['type'] = AxFieldType['type'], TIsArray extends boolean = false, TOptions extends readonly string[] = readonly string[], TIsOptional extends boolean = false, _TIsInternal extends boolean = false, TFields extends Record<string, AxFluentFieldInfo | AxFluentFieldType> | undefined = undefined> {
1007
+ interface AxFluentFieldInfo<TType extends AxFieldType['type'] = AxFieldType['type'], TIsArray extends boolean = false, TOptions extends readonly string[] = readonly string[], TIsOptional extends boolean = false, _TIsInternal extends boolean = false, TFields extends Record<string, AxFluentFieldInfo | AxFluentFieldType> | undefined = undefined, _TIsCached extends boolean = false> {
999
1008
  readonly type: TType;
1000
1009
  readonly isArray?: TIsArray;
1001
1010
  readonly options?: TOptions;
@@ -1004,6 +1013,7 @@ interface AxFluentFieldInfo<TType extends AxFieldType['type'] = AxFieldType['typ
1004
1013
  readonly itemDescription?: string;
1005
1014
  readonly isOptional?: TIsOptional;
1006
1015
  readonly isInternal?: boolean;
1016
+ readonly isCached?: boolean;
1007
1017
  readonly minLength?: number;
1008
1018
  readonly maxLength?: number;
1009
1019
  readonly minimum?: number;
@@ -1519,6 +1529,11 @@ interface AxCompileOptions {
1519
1529
  skipPerfectScore?: boolean;
1520
1530
  perfectScore?: number;
1521
1531
  maxMetricCalls?: number;
1532
+ /**
1533
+ * Custom labels to include in OpenTelemetry metrics.
1534
+ * These labels are merged with axGlobals.customLabels and AI service customLabels.
1535
+ */
1536
+ customLabels?: Record<string, string>;
1522
1537
  }
1523
1538
 
1524
1539
  interface AxOptimizerMetricsConfig {
@@ -1790,6 +1805,11 @@ declare abstract class AxBaseOptimizer implements AxOptimizer {
1790
1805
  protected readonly metricsInstruments?: AxOptimizerMetricsInstruments;
1791
1806
  private resultExplainer?;
1792
1807
  constructor(args: Readonly<AxOptimizerArgs>);
1808
+ /**
1809
+ * Get merged custom labels from globals, AI services, and compile options.
1810
+ * Labels are merged with later sources overriding earlier ones.
1811
+ */
1812
+ protected getMergedCustomLabels(options?: AxCompileOptions): Record<string, string>;
1793
1813
  /**
1794
1814
  * Initialize the result explanation generator
1795
1815
  * FIXME: Disabled due to circular dependency with ax() function
@@ -1818,7 +1838,7 @@ declare abstract class AxBaseOptimizer implements AxOptimizer {
1818
1838
  /**
1819
1839
  * Trigger early stopping with appropriate callbacks
1820
1840
  */
1821
- protected triggerEarlyStopping(reason: string, bestScoreRound: number): void;
1841
+ protected triggerEarlyStopping(reason: string, bestScoreRound: number, options?: AxCompileOptions): void;
1822
1842
  /**
1823
1843
  * Validate that examples meet minimum requirements for optimization
1824
1844
  * @param examples Examples to validate
@@ -1944,35 +1964,35 @@ declare abstract class AxBaseOptimizer implements AxOptimizer {
1944
1964
  /**
1945
1965
  * Record optimization start metrics
1946
1966
  */
1947
- protected recordOptimizationStart(optimizerType: string, programSignature?: string): void;
1967
+ protected recordOptimizationStart(optimizerType: string, programSignature?: string, options?: AxCompileOptions): void;
1948
1968
  /**
1949
1969
  * Record optimization completion metrics
1950
1970
  */
1951
- protected recordOptimizationComplete(duration: number, success: boolean, optimizerType: string, programSignature?: string): void;
1971
+ protected recordOptimizationComplete(duration: number, success: boolean, optimizerType: string, programSignature?: string, options?: AxCompileOptions): void;
1952
1972
  /**
1953
1973
  * Record convergence metrics
1954
1974
  */
1955
- protected recordConvergenceMetrics(rounds: number, currentScore: number, improvement: number, stagnationRounds: number, optimizerType: string): void;
1975
+ protected recordConvergenceMetrics(rounds: number, currentScore: number, improvement: number, stagnationRounds: number, optimizerType: string, options?: AxCompileOptions): void;
1956
1976
  /**
1957
1977
  * Record early stopping metrics
1958
1978
  */
1959
- protected recordEarlyStoppingMetrics(reason: string, optimizerType: string): void;
1979
+ protected recordEarlyStoppingMetrics(reason: string, optimizerType: string, options?: AxCompileOptions): void;
1960
1980
  /**
1961
1981
  * Record teacher-student interaction metrics
1962
1982
  */
1963
- protected recordTeacherStudentMetrics(latency: number, scoreImprovement: number, optimizerType: string): void;
1983
+ protected recordTeacherStudentMetrics(latency: number, scoreImprovement: number, optimizerType: string, options?: AxCompileOptions): void;
1964
1984
  /**
1965
1985
  * Record checkpoint metrics
1966
1986
  */
1967
- protected recordCheckpointMetrics(operation: 'save' | 'load', latency: number, success: boolean, optimizerType: string): void;
1987
+ protected recordCheckpointMetrics(operation: 'save' | 'load', latency: number, success: boolean, optimizerType: string, options?: AxCompileOptions): void;
1968
1988
  /**
1969
1989
  * Record Pareto optimization metrics
1970
1990
  */
1971
- protected recordParetoMetrics(frontSize: number, solutionsGenerated: number, optimizerType: string, hypervolume?: number): void;
1991
+ protected recordParetoMetrics(frontSize: number, solutionsGenerated: number, optimizerType: string, hypervolume?: number, options?: AxCompileOptions): void;
1972
1992
  /**
1973
1993
  * Record performance metrics
1974
1994
  */
1975
- protected recordPerformanceMetrics(metricType: 'evaluation' | 'demo_generation' | 'metric_computation', duration: number, optimizerType: string): void;
1995
+ protected recordPerformanceMetrics(metricType: 'evaluation' | 'demo_generation' | 'metric_computation', duration: number, optimizerType: string, options?: AxCompileOptions): void;
1976
1996
  protected isOptimizerLoggingEnabled(options?: AxCompileOptions): boolean;
1977
1997
  protected getOptimizerLogger(options?: AxCompileOptions): AxOptimizerLoggerFunction | undefined;
1978
1998
  getStats(): AxOptimizationStats;
@@ -2129,6 +2149,8 @@ interface AxPromptTemplateOptions {
2129
2149
  contextCache?: AxContextCacheOptions;
2130
2150
  /** When true, examples/demos are embedded in system prompt (legacy). When false (default), they are rendered as alternating user/assistant message pairs. */
2131
2151
  examplesInSystem?: boolean;
2152
+ /** When true, cacheBreakpoint is ignored and cache is applied to all positions (for providers with auto-lookback like Anthropic) */
2153
+ ignoreBreakpoints?: boolean;
2132
2154
  }
2133
2155
  type AxChatRequestChatPrompt = Writeable<AxChatRequest['chatPrompt'][0]>;
2134
2156
  type ChatRequestUserMessage = Exclude<Extract<AxChatRequestChatPrompt, {
@@ -2146,7 +2168,13 @@ declare class AxPromptTemplate {
2146
2168
  private readonly functions?;
2147
2169
  private readonly contextCache?;
2148
2170
  private readonly examplesInSystem;
2171
+ private readonly ignoreBreakpoints;
2149
2172
  constructor(sig: Readonly<AxSignature>, options?: Readonly<AxPromptTemplateOptions>, fieldTemplates?: Record<string, AxFieldTemplateFn>);
2173
+ /**
2174
+ * Sort fields so that cached fields come first.
2175
+ * Uses stable sort to preserve relative order among cached and non-cached fields.
2176
+ */
2177
+ private sortFieldsCachedFirst;
2150
2178
  /**
2151
2179
  * Build legacy prompt format (backward compatible)
2152
2180
  */
@@ -2638,6 +2666,8 @@ interface AxAIFeatures {
2638
2666
  supported: boolean;
2639
2667
  /** Types of caching available */
2640
2668
  types: ('ephemeral' | 'persistent')[];
2669
+ /** Whether explicit cache breakpoints are needed. If false, provider has automatic lookback and cache_control is always applied to system and last tool when caching is detected. Defaults to true. */
2670
+ cacheBreakpoints?: boolean;
2641
2671
  };
2642
2672
  /** Whether the provider supports thinking/reasoning modes */
2643
2673
  thinking: boolean;
package/index.d.ts CHANGED
@@ -823,14 +823,14 @@ declare class AxSignatureBuilder<_TInput extends Record<string, any> = {}, _TOut
823
823
  * @param fieldInfo - Field type created with f.string(), f.number(), etc.
824
824
  * @param prepend - If true, adds field to the beginning of input fields
825
825
  */
826
- input<K extends string, T extends AxFluentFieldInfo<any, any, any, any, any, any> | AxFluentFieldType<any, any, any, any, any, any>>(name: K, fieldInfo: T, prepend?: boolean): AxSignatureBuilder<AddFieldToShape<_TInput, K, T>, _TOutput>;
826
+ input<K extends string, T extends AxFluentFieldInfo<any, any, any, any, any, any, any> | AxFluentFieldType<any, any, any, any, any, any, any>>(name: K, fieldInfo: T, prepend?: boolean): AxSignatureBuilder<AddFieldToShape<_TInput, K, T>, _TOutput>;
827
827
  /**
828
828
  * Add an output field to the signature
829
829
  * @param name - Field name
830
830
  * @param fieldInfo - Field type created with f.string(), f.number(), etc.
831
831
  * @param prepend - If true, adds field to the beginning of output fields
832
832
  */
833
- output<K extends string, T extends AxFluentFieldInfo<any, any, any, any, any, any> | AxFluentFieldType<any, any, any, any, any, any>>(name: K, fieldInfo: T, prepend?: boolean): AxSignatureBuilder<_TInput, AddFieldToShape<_TOutput, K, T>>;
833
+ output<K extends string, T extends AxFluentFieldInfo<any, any, any, any, any, any, any> | AxFluentFieldType<any, any, any, any, any, any, any>>(name: K, fieldInfo: T, prepend?: boolean): AxSignatureBuilder<_TInput, AddFieldToShape<_TOutput, K, T>>;
834
834
  /**
835
835
  * Set the description for the signature
836
836
  * @param description - Description text
@@ -845,13 +845,14 @@ declare class AxSignatureBuilder<_TInput extends Record<string, any> = {}, _TOut
845
845
  */
846
846
  build(): AxSignature<_TInput, _TOutput>;
847
847
  }
848
- declare class AxFluentFieldType<TType extends AxFieldType['type'] = AxFieldType['type'], TIsArray extends boolean = false, TOptions extends readonly string[] | undefined = undefined, TIsOptional extends boolean = false, TIsInternal extends boolean = false, TFields extends Record<string, AxFluentFieldInfo | AxFluentFieldType> | undefined = undefined> implements AxFieldType {
848
+ declare class AxFluentFieldType<TType extends AxFieldType['type'] = AxFieldType['type'], TIsArray extends boolean = false, TOptions extends readonly string[] | undefined = undefined, TIsOptional extends boolean = false, TIsInternal extends boolean = false, TFields extends Record<string, AxFluentFieldInfo | AxFluentFieldType> | undefined = undefined, TIsCached extends boolean = false> implements AxFieldType {
849
849
  readonly type: TType;
850
850
  readonly isArray: TIsArray;
851
851
  readonly options?: TOptions;
852
852
  readonly description?: string;
853
853
  readonly isOptional: TIsOptional;
854
854
  readonly isInternal: TIsInternal;
855
+ readonly isCached: TIsCached;
855
856
  readonly fields?: any;
856
857
  readonly minLength?: number;
857
858
  readonly maxLength?: number;
@@ -869,6 +870,7 @@ declare class AxFluentFieldType<TType extends AxFieldType['type'] = AxFieldType[
869
870
  itemDescription?: string;
870
871
  isOptional: TIsOptional;
871
872
  isInternal: TIsInternal;
873
+ isCached: TIsCached;
872
874
  fields?: TFields;
873
875
  minLength?: number;
874
876
  maxLength?: number;
@@ -878,39 +880,45 @@ declare class AxFluentFieldType<TType extends AxFieldType['type'] = AxFieldType[
878
880
  patternDescription?: string;
879
881
  format?: string;
880
882
  });
881
- optional(): AxFluentFieldType<TType, TIsArray, TOptions, true, TIsInternal, TFields>;
882
- array(desc?: string): AxFluentFieldType<TType, true, TOptions, TIsOptional, TIsInternal, TFields>;
883
- internal(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, true, TFields>;
883
+ optional(): AxFluentFieldType<TType, TIsArray, TOptions, true, TIsInternal, TFields, TIsCached>;
884
+ array(desc?: string): AxFluentFieldType<TType, true, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
885
+ internal(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, true, TFields, TIsCached>;
886
+ /**
887
+ * Mark this input field for caching. When contextCache is enabled,
888
+ * cached fields are rendered in a separate user message with cache: true,
889
+ * allowing them to be cached by the LLM provider.
890
+ */
891
+ cache(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, true>;
884
892
  /**
885
893
  * Set minimum value for numbers or minimum length for strings
886
894
  */
887
- min(value: number): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields>;
895
+ min(value: number): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
888
896
  /**
889
897
  * Set maximum value for numbers or maximum length for strings
890
898
  */
891
- max(value: number): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields>;
899
+ max(value: number): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
892
900
  /**
893
901
  * Set email format validation for strings
894
902
  */
895
- email(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields>;
903
+ email(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
896
904
  /**
897
905
  * Set URL/URI format validation for strings
898
906
  */
899
- url(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields>;
907
+ url(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
900
908
  /**
901
909
  * Set regex pattern validation for strings
902
910
  * @param pattern - Regular expression pattern to match
903
911
  * @param description - Human-readable description of what the pattern validates (e.g., "Must be a valid username with only lowercase letters, numbers, and underscores")
904
912
  */
905
- regex(pattern: string, description: string): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields>;
913
+ regex(pattern: string, description: string): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
906
914
  /**
907
915
  * Set date format validation for strings
908
916
  */
909
- date(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields>;
917
+ date(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
910
918
  /**
911
919
  * Set datetime format validation for strings
912
920
  */
913
- datetime(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields>;
921
+ datetime(): AxFluentFieldType<TType, TIsArray, TOptions, TIsOptional, TIsInternal, TFields, TIsCached>;
914
922
  }
915
923
  type ValidateNoMediaTypes<TFields> = {
916
924
  [K in keyof TFields]: TFields[K] extends {
@@ -925,20 +933,20 @@ type ValidateNoMediaTypes<TFields> = {
925
933
  } : TFields[K] : TFields[K] : TFields[K];
926
934
  };
927
935
  declare const f: (() => AxSignatureBuilder) & {
928
- string: (desc?: string) => AxFluentFieldType<"string", false, undefined, false, false, undefined>;
929
- number: (desc?: string) => AxFluentFieldType<"number", false, undefined, false, false, undefined>;
930
- boolean: (desc?: string) => AxFluentFieldType<"boolean", false, undefined, false, false, undefined>;
931
- json: (desc?: string) => AxFluentFieldType<"json", false, undefined, false, false, undefined>;
932
- datetime: (desc?: string) => AxFluentFieldType<"datetime", false, undefined, false, false, undefined>;
933
- date: (desc?: string) => AxFluentFieldType<"date", false, undefined, false, false, undefined>;
934
- class: <const TOptions extends readonly string[]>(options: TOptions, desc?: string) => AxFluentFieldType<"class", false, TOptions, false, false, undefined>;
935
- image: (desc?: string) => AxFluentFieldType<"image", false, undefined, false, false, undefined>;
936
- audio: (desc?: string) => AxFluentFieldType<"audio", false, undefined, false, false, undefined>;
937
- file: (desc?: string) => AxFluentFieldType<"file", false, undefined, false, false, undefined>;
938
- url: (desc?: string) => AxFluentFieldType<"url", false, undefined, false, false, undefined>;
939
- email: (desc?: string) => AxFluentFieldType<"string", false, undefined, false, false, undefined>;
940
- code: (language?: string, desc?: string) => AxFluentFieldType<"code", false, undefined, false, false, undefined>;
941
- object: <TFields extends Record<string, AxFluentFieldInfo<any, any, any, any, any, any> | AxFluentFieldType<any, any, any, any, any, any>>>(fields: TFields & ValidateNoMediaTypes<TFields>, desc?: string) => AxFluentFieldType<"object", false, undefined, false, false, TFields>;
936
+ string: (desc?: string) => AxFluentFieldType<"string", false, undefined, false, false, undefined, false>;
937
+ number: (desc?: string) => AxFluentFieldType<"number", false, undefined, false, false, undefined, false>;
938
+ boolean: (desc?: string) => AxFluentFieldType<"boolean", false, undefined, false, false, undefined, false>;
939
+ json: (desc?: string) => AxFluentFieldType<"json", false, undefined, false, false, undefined, false>;
940
+ datetime: (desc?: string) => AxFluentFieldType<"datetime", false, undefined, false, false, undefined, false>;
941
+ date: (desc?: string) => AxFluentFieldType<"date", false, undefined, false, false, undefined, false>;
942
+ class: <const TOptions extends readonly string[]>(options: TOptions, desc?: string) => AxFluentFieldType<"class", false, TOptions, false, false, undefined, false>;
943
+ image: (desc?: string) => AxFluentFieldType<"image", false, undefined, false, false, undefined, false>;
944
+ audio: (desc?: string) => AxFluentFieldType<"audio", false, undefined, false, false, undefined, false>;
945
+ file: (desc?: string) => AxFluentFieldType<"file", false, undefined, false, false, undefined, false>;
946
+ url: (desc?: string) => AxFluentFieldType<"url", false, undefined, false, false, undefined, false>;
947
+ email: (desc?: string) => AxFluentFieldType<"string", false, undefined, false, false, undefined, false>;
948
+ code: (language?: string, desc?: string) => AxFluentFieldType<"code", false, undefined, false, false, undefined, false>;
949
+ object: <TFields extends Record<string, AxFluentFieldInfo<any, any, any, any, any, any, any> | AxFluentFieldType<any, any, any, any, any, any, any>>>(fields: TFields & ValidateNoMediaTypes<TFields>, desc?: string) => AxFluentFieldType<"object", false, undefined, false, false, TFields, false>;
942
950
  };
943
951
  interface AxField {
944
952
  name: string;
@@ -960,6 +968,7 @@ interface AxField {
960
968
  };
961
969
  isOptional?: boolean;
962
970
  isInternal?: boolean;
971
+ isCached?: boolean;
963
972
  }
964
973
  type AxIField = Omit<AxField, 'title'> & {
965
974
  title: string;
@@ -995,7 +1004,7 @@ type InferFieldValueType<T> = T extends AxFieldType | AxFluentFieldType ? T['typ
995
1004
  }[] : {
996
1005
  [K in keyof F]: InferFluentType<F[K]>;
997
1006
  } : any : any : any : any;
998
- interface AxFluentFieldInfo<TType extends AxFieldType['type'] = AxFieldType['type'], TIsArray extends boolean = false, TOptions extends readonly string[] = readonly string[], TIsOptional extends boolean = false, _TIsInternal extends boolean = false, TFields extends Record<string, AxFluentFieldInfo | AxFluentFieldType> | undefined = undefined> {
1007
+ interface AxFluentFieldInfo<TType extends AxFieldType['type'] = AxFieldType['type'], TIsArray extends boolean = false, TOptions extends readonly string[] = readonly string[], TIsOptional extends boolean = false, _TIsInternal extends boolean = false, TFields extends Record<string, AxFluentFieldInfo | AxFluentFieldType> | undefined = undefined, _TIsCached extends boolean = false> {
999
1008
  readonly type: TType;
1000
1009
  readonly isArray?: TIsArray;
1001
1010
  readonly options?: TOptions;
@@ -1004,6 +1013,7 @@ interface AxFluentFieldInfo<TType extends AxFieldType['type'] = AxFieldType['typ
1004
1013
  readonly itemDescription?: string;
1005
1014
  readonly isOptional?: TIsOptional;
1006
1015
  readonly isInternal?: boolean;
1016
+ readonly isCached?: boolean;
1007
1017
  readonly minLength?: number;
1008
1018
  readonly maxLength?: number;
1009
1019
  readonly minimum?: number;
@@ -1519,6 +1529,11 @@ interface AxCompileOptions {
1519
1529
  skipPerfectScore?: boolean;
1520
1530
  perfectScore?: number;
1521
1531
  maxMetricCalls?: number;
1532
+ /**
1533
+ * Custom labels to include in OpenTelemetry metrics.
1534
+ * These labels are merged with axGlobals.customLabels and AI service customLabels.
1535
+ */
1536
+ customLabels?: Record<string, string>;
1522
1537
  }
1523
1538
 
1524
1539
  interface AxOptimizerMetricsConfig {
@@ -1790,6 +1805,11 @@ declare abstract class AxBaseOptimizer implements AxOptimizer {
1790
1805
  protected readonly metricsInstruments?: AxOptimizerMetricsInstruments;
1791
1806
  private resultExplainer?;
1792
1807
  constructor(args: Readonly<AxOptimizerArgs>);
1808
+ /**
1809
+ * Get merged custom labels from globals, AI services, and compile options.
1810
+ * Labels are merged with later sources overriding earlier ones.
1811
+ */
1812
+ protected getMergedCustomLabels(options?: AxCompileOptions): Record<string, string>;
1793
1813
  /**
1794
1814
  * Initialize the result explanation generator
1795
1815
  * FIXME: Disabled due to circular dependency with ax() function
@@ -1818,7 +1838,7 @@ declare abstract class AxBaseOptimizer implements AxOptimizer {
1818
1838
  /**
1819
1839
  * Trigger early stopping with appropriate callbacks
1820
1840
  */
1821
- protected triggerEarlyStopping(reason: string, bestScoreRound: number): void;
1841
+ protected triggerEarlyStopping(reason: string, bestScoreRound: number, options?: AxCompileOptions): void;
1822
1842
  /**
1823
1843
  * Validate that examples meet minimum requirements for optimization
1824
1844
  * @param examples Examples to validate
@@ -1944,35 +1964,35 @@ declare abstract class AxBaseOptimizer implements AxOptimizer {
1944
1964
  /**
1945
1965
  * Record optimization start metrics
1946
1966
  */
1947
- protected recordOptimizationStart(optimizerType: string, programSignature?: string): void;
1967
+ protected recordOptimizationStart(optimizerType: string, programSignature?: string, options?: AxCompileOptions): void;
1948
1968
  /**
1949
1969
  * Record optimization completion metrics
1950
1970
  */
1951
- protected recordOptimizationComplete(duration: number, success: boolean, optimizerType: string, programSignature?: string): void;
1971
+ protected recordOptimizationComplete(duration: number, success: boolean, optimizerType: string, programSignature?: string, options?: AxCompileOptions): void;
1952
1972
  /**
1953
1973
  * Record convergence metrics
1954
1974
  */
1955
- protected recordConvergenceMetrics(rounds: number, currentScore: number, improvement: number, stagnationRounds: number, optimizerType: string): void;
1975
+ protected recordConvergenceMetrics(rounds: number, currentScore: number, improvement: number, stagnationRounds: number, optimizerType: string, options?: AxCompileOptions): void;
1956
1976
  /**
1957
1977
  * Record early stopping metrics
1958
1978
  */
1959
- protected recordEarlyStoppingMetrics(reason: string, optimizerType: string): void;
1979
+ protected recordEarlyStoppingMetrics(reason: string, optimizerType: string, options?: AxCompileOptions): void;
1960
1980
  /**
1961
1981
  * Record teacher-student interaction metrics
1962
1982
  */
1963
- protected recordTeacherStudentMetrics(latency: number, scoreImprovement: number, optimizerType: string): void;
1983
+ protected recordTeacherStudentMetrics(latency: number, scoreImprovement: number, optimizerType: string, options?: AxCompileOptions): void;
1964
1984
  /**
1965
1985
  * Record checkpoint metrics
1966
1986
  */
1967
- protected recordCheckpointMetrics(operation: 'save' | 'load', latency: number, success: boolean, optimizerType: string): void;
1987
+ protected recordCheckpointMetrics(operation: 'save' | 'load', latency: number, success: boolean, optimizerType: string, options?: AxCompileOptions): void;
1968
1988
  /**
1969
1989
  * Record Pareto optimization metrics
1970
1990
  */
1971
- protected recordParetoMetrics(frontSize: number, solutionsGenerated: number, optimizerType: string, hypervolume?: number): void;
1991
+ protected recordParetoMetrics(frontSize: number, solutionsGenerated: number, optimizerType: string, hypervolume?: number, options?: AxCompileOptions): void;
1972
1992
  /**
1973
1993
  * Record performance metrics
1974
1994
  */
1975
- protected recordPerformanceMetrics(metricType: 'evaluation' | 'demo_generation' | 'metric_computation', duration: number, optimizerType: string): void;
1995
+ protected recordPerformanceMetrics(metricType: 'evaluation' | 'demo_generation' | 'metric_computation', duration: number, optimizerType: string, options?: AxCompileOptions): void;
1976
1996
  protected isOptimizerLoggingEnabled(options?: AxCompileOptions): boolean;
1977
1997
  protected getOptimizerLogger(options?: AxCompileOptions): AxOptimizerLoggerFunction | undefined;
1978
1998
  getStats(): AxOptimizationStats;
@@ -2129,6 +2149,8 @@ interface AxPromptTemplateOptions {
2129
2149
  contextCache?: AxContextCacheOptions;
2130
2150
  /** When true, examples/demos are embedded in system prompt (legacy). When false (default), they are rendered as alternating user/assistant message pairs. */
2131
2151
  examplesInSystem?: boolean;
2152
+ /** When true, cacheBreakpoint is ignored and cache is applied to all positions (for providers with auto-lookback like Anthropic) */
2153
+ ignoreBreakpoints?: boolean;
2132
2154
  }
2133
2155
  type AxChatRequestChatPrompt = Writeable<AxChatRequest['chatPrompt'][0]>;
2134
2156
  type ChatRequestUserMessage = Exclude<Extract<AxChatRequestChatPrompt, {
@@ -2146,7 +2168,13 @@ declare class AxPromptTemplate {
2146
2168
  private readonly functions?;
2147
2169
  private readonly contextCache?;
2148
2170
  private readonly examplesInSystem;
2171
+ private readonly ignoreBreakpoints;
2149
2172
  constructor(sig: Readonly<AxSignature>, options?: Readonly<AxPromptTemplateOptions>, fieldTemplates?: Record<string, AxFieldTemplateFn>);
2173
+ /**
2174
+ * Sort fields so that cached fields come first.
2175
+ * Uses stable sort to preserve relative order among cached and non-cached fields.
2176
+ */
2177
+ private sortFieldsCachedFirst;
2150
2178
  /**
2151
2179
  * Build legacy prompt format (backward compatible)
2152
2180
  */
@@ -2638,6 +2666,8 @@ interface AxAIFeatures {
2638
2666
  supported: boolean;
2639
2667
  /** Types of caching available */
2640
2668
  types: ('ephemeral' | 'persistent')[];
2669
+ /** Whether explicit cache breakpoints are needed. If false, provider has automatic lookback and cache_control is always applied to system and last tool when caching is detected. Defaults to true. */
2670
+ cacheBreakpoints?: boolean;
2641
2671
  };
2642
2672
  /** Whether the provider supports thinking/reasoning modes */
2643
2673
  thinking: boolean;