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

Function _fmt_messages

openkb/agent/compiler.py:373–392  ·  view source on GitHub ↗

Format messages for debug output, truncating long content. Accepts both plain-string content and the list-of-blocks shape used by cache_control-tagged messages (joins all text blocks for preview).

(messages: list[dict], max_content: int = 200)

Source from the content-addressed store, hash-verified

371
372
373def _fmt_messages(messages: list[dict], max_content: int = 200) -> str:
374 """Format messages for debug output, truncating long content.
375
376 Accepts both plain-string content and the list-of-blocks shape used by
377 cache_control-tagged messages (joins all text blocks for preview).
378 """
379 parts = []
380 for msg in messages:
381 role = msg["role"]
382 raw = msg["content"]
383 if isinstance(raw, list):
384 text = "".join(b.get("text", "") for b in raw if isinstance(b, dict))
385 else:
386 text = raw
387 if len(text) > max_content:
388 preview = text[:max_content] + f"... ({len(text)} chars)"
389 else:
390 preview = text
391 parts.append(f" [{role}] {preview}")
392 return "\n".join(parts)
393
394
395class TruncatedResponseError(Exception):

Callers 2

_llm_callFunction · 0.85
_llm_call_asyncFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected