"""Stream only the explicitly delimited email body, never model reasoning.""" import json import re def reply_body(raw, *, complete=False): match = re.search(r'<<<\s*REPLY\s*>>>', raw, re.I) if not match: return '' body = raw[match.end():] end = re.search(r'<<<\s*END\s*>>>', body, re.I) if complete and not end: return '' body = body[:end.start()] if end else body.split('<', 1)[0] if re.search(r'