@@ -25,6 +25,7 @@ pub struct Operation {
25
25
tool : Tool ,
26
26
source_text : String ,
27
27
persisted_query_id : Option < String > ,
28
+ character_count : usize ,
28
29
}
29
30
30
31
impl AsRef < Tool > for Operation {
@@ -118,10 +119,24 @@ impl Operation {
118
119
) ) ;
119
120
} ;
120
121
122
+ let tool = Tool :: new ( operation_name. clone ( ) , description, schema) ;
123
+ let character_count = tool_character_length ( & tool) ;
124
+ match character_count {
125
+ Ok ( length) => tracing:: info!(
126
+ "Tool {} loaded with a character count of {}" ,
127
+ operation_name,
128
+ length
129
+ ) ,
130
+ Err ( _) => tracing:: info!(
131
+ "Tool {} loaded with an unknown character count" ,
132
+ operation_name
133
+ ) ,
134
+ }
121
135
Ok ( Operation {
122
- tool : Tool :: new ( operation_name , description , schema ) ,
136
+ tool,
123
137
source_text : source_text. to_string ( ) ,
124
138
persisted_query_id,
139
+ character_count : character_count. unwrap_or_default ( ) ,
125
140
} )
126
141
}
127
142
@@ -247,6 +262,15 @@ impl Operation {
247
262
248
263
lines. join ( "\n " )
249
264
}
265
+
266
+ pub fn tool_character_length ( & self ) -> usize {
267
+ self . character_count
268
+ }
269
+ }
270
+
271
+ fn tool_character_length ( tool : & Tool ) -> Result < usize , serde_json:: Error > {
272
+ let tool_schema_string = serde_json:: to_string_pretty ( & serde_json:: json!( tool. input_schema) ) ?;
273
+ Ok ( tool. name . len ( ) + tool. description . len ( ) + tool_schema_string. len ( ) )
250
274
}
251
275
252
276
fn get_json_schema (
0 commit comments