From dcadb3c33962c5a876e1fbc6ab0834a02c325803 Mon Sep 17 00:00:00 2001 From: MarkLo Date: Wed, 26 Nov 2025 18:46:15 +0800 Subject: [PATCH] --- tradingagents/agents/utils/output_filter.py | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tradingagents/agents/utils/output_filter.py b/tradingagents/agents/utils/output_filter.py index bfe3793c..1fd5bcea 100644 --- a/tradingagents/agents/utils/output_filter.py +++ b/tradingagents/agents/utils/output_filter.py @@ -127,3 +127,29 @@ def post_process_agent_output(content: str, agent_name: str, retry_callback=None # This is optional and should be implemented in the calling code return content + + +def ensure_min_length(content: str, min_words: int = 800, agent_name: str = "Agent") -> tuple: + """ + 確保報告達到最小字數,如果不夠則返回False觸發重試 + + Args: + content: The report content to check + min_words: Minimum required word count (default: 800) + agent_name: Name of the agent for logging + + Returns: + tuple: (content, is_valid: bool) + """ + word_count = count_chinese_words(content) + + if word_count < min_words: + print(f"⚠️ [{agent_name}] 報告字數不足: {word_count}字 < {min_words}字最低要求") + return content, False + elif word_count > 1500: + print(f"⚠️ [{agent_name}] 報告字數過多: {word_count}字 > 1500字上限") + return content, False + else: + print(f"✅ [{agent_name}] 報告字數符合要求: {word_count}字") + return content, True +