"""A Hermes session as Markdown: what was said, thought, and called, in order. Rows are Hermes's `messages` table (state.db), as dicts. >>> print(render([ ... {'role': 'user', 'content': 'Check your messages.'}, ... {'role': 'assistant', 'content': '', 'reasoning': 'I should look.', ... 'tool_calls': '[{"function": {"name": "mcp__host__listMessages", "arguments": "{}"}}]'}, ... {'role': 'tool', 'tool_name': 'mcp__host__listMessages', 'content': '[]'}, ... {'role': 'assistant', 'content': 'Nothing there.'}, ... ], system_prompt='You are Hermes.')) # Hermes session
system prompt ```` You are Hermes. ````
## user Check your messages. ## assistant > I should look. calls `mcp__host__listMessages`: ````json {} ```` ## tool: mcp__host__listMessages ```` [] ```` ## assistant Nothing there. """ import json FENCE = "````" def _pretty(arguments): try: return json.dumps(json.loads(arguments), indent=2) except (TypeError, ValueError): return str(arguments) def render(rows, system_prompt=None): """Markdown for a session's `rows`, after its `system_prompt` if given.""" out = ["# Hermes session", ""] if system_prompt: out += ["
system prompt", "", FENCE, system_prompt, FENCE, "
", ""] for row in rows: role = row["role"] content = row.get("content") or "" if role == "tool": out += [f"## tool: {row.get('tool_name')}", "", FENCE, content, FENCE, ""] continue out += [f"## {role}", ""] thought = row.get("reasoning") or row.get("reasoning_content") if thought: out += ["\n".join("> " + line for line in thought.splitlines()), ""] if content: out += [content, ""] for call in json.loads(row.get("tool_calls") or "[]"): fn = call.get("function", {}) out += [f"calls `{fn.get('name')}`:", FENCE + "json", _pretty(fn.get("arguments")), FENCE, ""] return "\n".join(out)