MCPcopy Create free account
hub / github.com/pgadmin-org/pgadmin4 / _classify_message

Function _classify_message

web/pgadmin/llm/compaction.py:139–182  ·  view source on GitHub ↗

Classify a message by importance for compaction decisions. Args: message: The message to classify. Returns: Importance score from 0.0 to 1.0.

(message: Message)

Source from the content-addressed store, hash-verified

137
138
139def _classify_message(message: Message) -> float:
140 """Classify a message by importance for compaction decisions.
141
142 Args:
143 message: The message to classify.
144
145 Returns:
146 Importance score from 0.0 to 1.0.
147 """
148 content = message.content or ''
149
150 # Tool results containing schema info are anchors
151 if message.role == Role.TOOL:
152 for tr in message.tool_results:
153 if _SCHEMA_PATTERNS.search(tr.content):
154 return CLASS_ANCHOR
155 if _ERROR_PATTERNS.search(tr.content):
156 return CLASS_IMPORTANT
157 # Large tool results are contextual
158 if len(tr.content) > 500:
159 return CLASS_CONTEXTUAL
160 return CLASS_ROUTINE
161
162 # Assistant messages with tool calls are important (they reference tools)
163 if message.role == Role.ASSISTANT and message.tool_calls:
164 return CLASS_IMPORTANT
165
166 # Check content patterns
167 if _SCHEMA_PATTERNS.search(content):
168 return CLASS_ANCHOR
169 if _ERROR_PATTERNS.search(content):
170 return CLASS_IMPORTANT
171 if _QUERY_PATTERNS.search(content):
172 return CLASS_IMPORTANT
173
174 # Short messages are transient
175 if len(content) < 30:
176 return CLASS_TRANSIENT
177
178 # Medium messages are routine
179 if len(content) < 100:
180 return CLASS_ROUTINE
181
182 return CLASS_CONTEXTUAL
183
184
185def _find_tool_pair_indices(

Callers 1

compact_historyFunction · 0.85

Calls 1

searchMethod · 0.80

Tested by

no test coverage detected