MCPcopy Index your code
hub / github.com/microsoft/SkillOpt / consolidate_appendix_notes

Function consolidate_appendix_notes

skillopt/optimizer/skill_aware.py:164–206  ·  view source on GitHub ↗

LLM-consolidate appendix notes: dedupe / merge / compact. Mirrors GMemory ``_maybe_refactor_execution_notes`` and paper Eq.11. ``chat_fn`` is the optimizer chat callable ``(system, user, max_completion_tokens, retries, stage) -> (text, meta)``. On ANY failure (parse, empty, exception) t

(
    notes: list[str],
    *,
    chat_fn,
    max_completion_tokens: int = 4096,
)

Source from the content-addressed store, hash-verified

162
163
164def consolidate_appendix_notes(
165 notes: list[str],
166 *,
167 chat_fn,
168 max_completion_tokens: int = 4096,
169) -> list[str]:
170 """LLM-consolidate appendix notes: dedupe / merge / compact.
171
172 Mirrors GMemory ``_maybe_refactor_execution_notes`` and paper Eq.11. ``chat_fn``
173 is the optimizer chat callable ``(system, user, max_completion_tokens, retries,
174 stage) -> (text, meta)``. On ANY failure (parse, empty, exception) the original
175 notes are returned unchanged, so consolidation can never lose the appendix.
176 """
177 from skillopt.utils import extract_json # local import to avoid cycles
178
179 clean = [str(n).strip() for n in (notes or []) if str(n).strip()]
180 if len(clean) < 2:
181 return clean
182
183 numbered = "\n".join(f"{i}. {n}" for i, n in enumerate(clean, 1))
184 user = (
185 f"## Current Execution Notes ({len(clean)} total)\n{numbered}\n\n"
186 "Compact these into a shorter list without losing distinct actionable "
187 "information. Merge duplicates and near-duplicates; keep each note short, "
188 "concrete, and reusable. Return valid JSON only with this schema:\n"
189 '{ "appendix_notes": ["compacted note 1", "compacted note 2"] }'
190 )
191 try:
192 response, _ = chat_fn(
193 system=_CONSOLIDATE_SYSTEM,
194 user=user,
195 max_completion_tokens=max_completion_tokens,
196 retries=2,
197 stage="appendix_consolidate",
198 )
199 result = extract_json(response)
200 compacted = extract_appendix_notes(result)
201 # Guard: only accept a non-empty result that actually shrinks the set.
202 if compacted and len(compacted) <= len(clean):
203 return compacted
204 except Exception: # noqa: BLE001
205 pass
206 return clean

Callers 1

Calls 2

extract_jsonFunction · 0.90
extract_appendix_notesFunction · 0.70

Tested by

no test coverage detected