@@ -73,3 +73,122 @@ def _convert_consolidation_config(self) -> Dict[str, Any]:
73
73
if self .consolidation_config .model_id is not None :
74
74
config ["modelId" ] = self .consolidation_config .model_id
75
75
return config
76
+
77
+
78
+ class CustomSummaryStrategy (BaseStrategy ):
79
+ """Custom summary strategy with configurable consolidation.
80
+
81
+ This strategy allows customization of consolidation using custom prompts and models.
82
+
83
+ Attributes:
84
+ consolidation_config: Configuration for consolidation operations
85
+
86
+ Example:
87
+ strategy = CustomSummaryStrategy(
88
+ name="CustomSummary",
89
+ description="Custom summary extraction with specific prompts",
90
+ consolidation_config=ConsolidationConfig(
91
+ append_to_prompt="Consolidate business insights",
92
+ model_id="anthropic.claude-3-haiku-20240307-v1:0"
93
+ ),
94
+ namespaces=["custom/{actorId}/{sessionId}"]
95
+ )
96
+ """
97
+
98
+ consolidation_config : ConsolidationConfig = Field (..., description = "Consolidation configuration" )
99
+
100
+ def to_dict (self ) -> Dict [str , Any ]:
101
+ """Convert to dictionary format for API calls."""
102
+ config = {
103
+ "name" : self .name ,
104
+ "configuration" : {
105
+ "summaryOverride" : {
106
+ "consolidation" : self ._convert_consolidation_config (),
107
+ }
108
+ },
109
+ }
110
+
111
+ if self .description is not None :
112
+ config ["description" ] = self .description
113
+
114
+ if self .namespaces is not None :
115
+ config ["namespaces" ] = self .namespaces
116
+
117
+ return {"customMemoryStrategy" : config }
118
+
119
+ def _convert_consolidation_config (self ) -> Dict [str , Any ]:
120
+ """Convert consolidation config to API format."""
121
+ config = {}
122
+ if self .consolidation_config .append_to_prompt is not None :
123
+ config ["appendToPrompt" ] = self .consolidation_config .append_to_prompt
124
+ if self .consolidation_config .model_id is not None :
125
+ config ["modelId" ] = self .consolidation_config .model_id
126
+ return config
127
+
128
+
129
+ class CustomUserPreferenceStrategy (BaseStrategy ):
130
+ """Custom userPreference strategy with configurable extraction and consolidation.
131
+
132
+ This strategy allows customization of both extraction and consolidation
133
+ processes using custom prompts and models.
134
+
135
+ Attributes:
136
+ extraction_config: Configuration for extraction operations
137
+ consolidation_config: Configuration for consolidation operations
138
+
139
+ Example:
140
+ strategy = CustomUserPreferenceStrategy(
141
+ name="CustomUserPreference",
142
+ description="Custom user preference extraction with specific prompts",
143
+ extraction_config=ExtractionConfig(
144
+ append_to_prompt="Extract key business insights",
145
+ model_id="anthropic.claude-3-sonnet-20240229-v1:0"
146
+ ),
147
+ consolidation_config=ConsolidationConfig(
148
+ append_to_prompt="Consolidate business insights",
149
+ model_id="anthropic.claude-3-haiku-20240307-v1:0"
150
+ ),
151
+ namespaces=["custom/{actorId}/{sessionId}"]
152
+ )
153
+ """
154
+
155
+ extraction_config : ExtractionConfig = Field (..., description = "Extraction configuration" )
156
+ consolidation_config : ConsolidationConfig = Field (..., description = "Consolidation configuration" )
157
+
158
+ def to_dict (self ) -> Dict [str , Any ]:
159
+ """Convert to dictionary format for API calls."""
160
+ config = {
161
+ "name" : self .name ,
162
+ "configuration" : {
163
+ "userPreferenceOverride" : {
164
+ "extraction" : self ._convert_extraction_config (),
165
+ "consolidation" : self ._convert_consolidation_config (),
166
+ }
167
+ },
168
+ }
169
+
170
+ if self .description is not None :
171
+ config ["description" ] = self .description
172
+
173
+ if self .namespaces is not None :
174
+ config ["namespaces" ] = self .namespaces
175
+
176
+ return {"customMemoryStrategy" : config }
177
+
178
+ def _convert_extraction_config (self ) -> Dict [str , Any ]:
179
+ """Convert extraction config to API format."""
180
+ config = {}
181
+ if self .extraction_config .append_to_prompt is not None :
182
+ config ["appendToPrompt" ] = self .extraction_config .append_to_prompt
183
+ if self .extraction_config .model_id is not None :
184
+ config ["modelId" ] = self .extraction_config .model_id
185
+ return config
186
+
187
+ def _convert_consolidation_config (self ) -> Dict [str , Any ]:
188
+ """Convert consolidation config to API format."""
189
+ config = {}
190
+ if self .consolidation_config .append_to_prompt is not None :
191
+ config ["appendToPrompt" ] = self .consolidation_config .append_to_prompt
192
+ if self .consolidation_config .model_id is not None :
193
+ config ["modelId" ] = self .consolidation_config .model_id
194
+ return config
0 commit comments