MCPcopy Create free account
hub / github.com/VectifyAI/OpenKB / _strip_cache_control

Function _strip_cache_control

openkb/agent/compiler.py:308–327  ·  view source on GitHub ↗

Return ``messages`` with every ``cache_control`` key removed. Only list-of-blocks contents (see :func:`_cached_text`) can carry the marker; plain-string contents pass through untouched. The input is not mutated.

(messages: list[dict])

Source from the content-addressed store, hash-verified

306
307
308def _strip_cache_control(messages: list[dict]) -> list[dict]:
309 """Return ``messages`` with every ``cache_control`` key removed.
310
311 Only list-of-blocks contents (see :func:`_cached_text`) can carry the
312 marker; plain-string contents pass through untouched. The input is not
313 mutated.
314 """
315 cleaned: list[dict] = []
316 for msg in messages:
317 content = msg.get("content")
318 if isinstance(content, list):
319 blocks = [
320 {k: v for k, v in block.items() if k != "cache_control"}
321 if isinstance(block, dict)
322 else block
323 for block in content
324 ]
325 msg = {**msg, "content": blocks}
326 cleaned.append(msg)
327 return cleaned
328
329
330def _prepare_messages(model: str, messages: list[dict]) -> list[dict]:

Calls 1

getMethod · 0.45