"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(channels): keep multi-paragraph teams quotes out of the user reply (#1958)
Lanre Shittu11cff3f3a2d8
diff --git a/agent/src/channels/msteams.py b/agent/src/channels/msteams.pyindex e79a2974e..d3cc94c4d 100644--- a/agent/src/channels/msteams.py+++ b/agent/src/channels/msteams.py@@ -463,10 +463,15 @@ class MSTeamsChannel(BaseChannel):if lines and lines[0].strip().startswith("Reply wrapper"):body = normalized_newlines.split("\n", 1)[1] if "\n" in normalized_newlines else ""body = body.lstrip()- parts = re.split(r"\n\s*\n", body, maxsplit=1)- if len(parts) == 2:- quoted = re.sub(r"\s+", " ", parts[0]).strip()- reply = re.sub(r"\s+", " ", parts[1]).strip()+ # Split on every blank-line boundary, not just the first: a+ # multi-paragraph quoted message has its own internal blank+ # lines, and splitting on the first one leaves the remaining+ # quoted paragraphs mixed into what gets reported as the+ # user's own reply. Only the final block is the actual reply.+ parts = re.split(r"\n\s*\n", body)+ if len(parts) >= 2:+ quoted = re.sub(r"\s+", " ", "\n\n".join(parts[:-1])).strip()+ reply = re.sub(r"\s+", " ", parts[-1]).strip()if quoted or reply:return self._format_reply_with_quote(quoted, reply)diff --git a/agent/tests/test_msteams_reply_quote_normalization.py b/agent/tests/test_msteams_reply_quote_normalization.pynew file mode 100644index 000000000..33762fc66--- /dev/null+++ b/agent/tests/test_msteams_reply_quote_normalization.py@@ -0,0 +1,46 @@+"""Regression: a multi-paragraph quoted Teams message must not leak its later+paragraphs into what the agent is told is the user's own reply.+"""++from __future__ import annotations++from src.channels.msteams import MSTeamsChannel+++def _sanitize(text: str) -> str:+ channel = MSTeamsChannel.__new__(MSTeamsChannel)+ activity = {+ "type": "message",+ "text": text,+ "replyToId": "msg-123",+ "channelData": {},+ }+ return channel._sanitize_inbound_text(activity)+++class TestReplyQuoteNormalization:+ def test_multi_paragraph_quote_stays_fully_in_the_quote(self) -> None:+ text = (+ "Reply wrapper\nFirst paragraph of the original quoted message.\n\n"+ "Second paragraph of the original quoted message.\n\n"+ "Here is my actual reply."+ )++ result = _sanitize(text)++ assert "User is replying to: First paragraph of the original quoted message. " \+ "Second paragraph of the original quoted message." in result+ assert result.endswith("User reply: Here is my actual reply.")+ assert "Second paragraph of the original quoted message." not in result.split(+ "User reply:"+ )[1]++ def test_single_paragraph_quote_still_works(self) -> None:+ text = "Reply wrapper\nSingle paragraph quote.\n\nHere is my actual reply."++ result = _sanitize(text)++ assert result == (+ "User is replying to: Single paragraph quote.\n"+ "User reply: Here is my actual reply."+ )