fix: skip empty factor rules llm calls
This commit is contained in:
parent
360ae6d604
commit
721f2b7cad
|
|
@ -8,6 +8,7 @@ from pathlib import Path
|
||||||
MODULE_PATH = Path(__file__).resolve().parents[1] / "tradingagents" / "agents" / "utils" / "factor_rules.py"
|
MODULE_PATH = Path(__file__).resolve().parents[1] / "tradingagents" / "agents" / "utils" / "factor_rules.py"
|
||||||
GRAPH_SETUP_PATH = Path(__file__).resolve().parents[1] / "tradingagents" / "graph" / "setup.py"
|
GRAPH_SETUP_PATH = Path(__file__).resolve().parents[1] / "tradingagents" / "graph" / "setup.py"
|
||||||
DEFAULT_CONFIG_PATH = Path(__file__).resolve().parents[1] / "tradingagents" / "default_config.py"
|
DEFAULT_CONFIG_PATH = Path(__file__).resolve().parents[1] / "tradingagents" / "default_config.py"
|
||||||
|
FACTOR_RULE_ANALYST_PATH = Path(__file__).resolve().parents[1] / "tradingagents" / "agents" / "analysts" / "factor_rule_analyst.py"
|
||||||
SPEC = importlib.util.spec_from_file_location("factor_rules", MODULE_PATH)
|
SPEC = importlib.util.spec_from_file_location("factor_rules", MODULE_PATH)
|
||||||
factor_rules = importlib.util.module_from_spec(SPEC)
|
factor_rules = importlib.util.module_from_spec(SPEC)
|
||||||
SPEC.loader.exec_module(factor_rules)
|
SPEC.loader.exec_module(factor_rules)
|
||||||
|
|
@ -425,5 +426,22 @@ class DefaultConfigSourceTests(unittest.TestCase):
|
||||||
self.assertIn('"default_headers": None', source)
|
self.assertIn('"default_headers": None', source)
|
||||||
|
|
||||||
|
|
||||||
|
class FactorRuleAnalystSourceTests(unittest.TestCase):
|
||||||
|
def test_factor_rule_analyst_short_circuits_when_rules_missing(self):
|
||||||
|
source = FACTOR_RULE_ANALYST_PATH.read_text(encoding="utf-8")
|
||||||
|
module = ast.parse(source)
|
||||||
|
|
||||||
|
create_fn = None
|
||||||
|
for node in module.body:
|
||||||
|
if isinstance(node, ast.FunctionDef) and node.name == "create_factor_rule_analyst":
|
||||||
|
create_fn = node
|
||||||
|
break
|
||||||
|
|
||||||
|
self.assertIsNotNone(create_fn)
|
||||||
|
self.assertIn("if not rules:", source)
|
||||||
|
self.assertIn('"messages": []', source)
|
||||||
|
self.assertIn('"factor_rules_report": summary', source)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,12 @@ def create_factor_rule_analyst(llm):
|
||||||
rules, rule_path = load_factor_rules(config)
|
rules, rule_path = load_factor_rules(config)
|
||||||
summary = _sanitize_text(summarize_factor_rules(rules, ticker, current_date))
|
summary = _sanitize_text(summarize_factor_rules(rules, ticker, current_date))
|
||||||
|
|
||||||
|
if not rules:
|
||||||
|
return {
|
||||||
|
"messages": [],
|
||||||
|
"factor_rules_report": summary,
|
||||||
|
}
|
||||||
|
|
||||||
system_prompt = """You are a Factor Rule Analyst for a trading research team.
|
system_prompt = """You are a Factor Rule Analyst for a trading research team.
|
||||||
Your job is to interpret manually curated factor rules and produce a concise, practical analyst report.
|
Your job is to interpret manually curated factor rules and produce a concise, practical analyst report.
|
||||||
You must:
|
You must:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue