"""Normalize assistant reasoning before sending history to an inference server. The tested vLLM response uses `reasoning`; the tested llama-server input parser accepts `reasoning_content`. This helper preserves content and tool-call fields. """ from copy import deepcopy def normalize_messages(messages): result = deepcopy(messages) for message in result: if message.get('role') != 'assistant': continue alias = message.get('reasoning') if isinstance(alias, str): if not message.get('reasoning_content'): message['reasoning_content'] = alias del message['reasoning'] content = message.get('content') if isinstance(content, str) and content.startswith('') and '' in content: thought, answer = content.split('', 1) if not message.get('reasoning_content'): message['reasoning_content'] = thought[7:].strip() message['content'] = answer.strip() return result if __name__ == '__main__': import json, sys json.dump(normalize_messages(json.load(sys.stdin)), sys.stdout, ensure_ascii=False, indent=2) sys.stdout.write('\n')