Python
fix(agents): stop conflict alone from defaulting the verdict to Hold
Yijia-Xiao62d34792175c
diff --git a/tests/test_structured_agents.py b/tests/test_structured_agents.pyindex ba3aa6f03..f411beb35 100644--- a/tests/test_structured_agents.py+++ b/tests/test_structured_agents.py@@ -7,12 +7,14 @@ behavior we added for the Trader, Research Manager, and Sentiment Analystso they share the same deterministic output shape."""+import inspectfrom unittest.mock import MagicMockimport pytestfrom pydantic import ValidationErrorfrom tradingagents.agents.analysts.sentiment_analyst import create_sentiment_analyst+from tradingagents.agents.managers.portfolio_manager import create_portfolio_managerfrom tradingagents.agents.managers.research_manager import create_research_managerfrom tradingagents.agents.schemas import (PortfolioDecision,@@ -484,3 +486,20 @@ class TestSentimentAnalystAgent:llm.with_structured_output.return_value = structuredllm.invoke.return_value = MagicMock(content=plain)assert create_sentiment_analyst(llm)(_make_sentiment_state())["sentiment_report"] == plain++[email protected]("source", [+ pytest.param(lambda: ResearchPlan.model_fields["recommendation"].description, id="ResearchPlan.recommendation"),+ pytest.param(lambda: PortfolioDecision.model_fields["rating"].description, id="PortfolioDecision.rating"),+ pytest.param(lambda: inspect.getsource(create_research_manager), id="research_manager prompt"),+ pytest.param(lambda: inspect.getsource(create_portfolio_manager), id="portfolio_manager prompt"),+])+def test_conflict_alone_is_not_a_hold_trigger(source):+ # The debate always contains conflicting arguments, so a Hold condition that+ # conflict satisfies fires on every run and swallows directional calls+ # (#1321). All four decision sites must state the same rule.+ text = " ".join(source().split())+ assert "conflict alone is not a reason to Hold" in text or \+ "Conflicting arguments alone are not a reason to Hold" in text+ assert "materially conflicting" not in textdiff --git a/tradingagents/agents/managers/portfolio_manager.py b/tradingagents/agents/managers/portfolio_manager.pyindex 75508dca6..efaafd7d2 100644--- a/tradingagents/agents/managers/portfolio_manager.py+++ b/tradingagents/agents/managers/portfolio_manager.py@@ -62,7 +62,7 @@ def create_portfolio_manager(llm):----Ground every conclusion in specific evidence from the analysts. Commit to a directional call only when the evidence clearly supports one; choose Hold when the case is balanced, materially conflicting, ambiguous, or insufficient to justify changing exposure, rather than forcing a direction to appear decisive. Weigh the analysts on their merits, independent of speaking order.+Ground every conclusion in specific evidence from the analysts. The risk debate always contains conflicting stances; deciding which is stronger is the job, so conflict alone is not a reason to Hold. Commit to the stronger case, sized by how decisively it wins. Choose Hold only when the evidence is still balanced after that weighing, or too thin to support a call; do not force a direction to appear decisive. Weigh the analysts on their merits, independent of speaking order.{NO_EXTERNAL_TOOLS}{get_language_instruction()}"""diff --git a/tradingagents/agents/managers/research_manager.py b/tradingagents/agents/managers/research_manager.pyindex 85c2d8e90..ed77b88d3 100644--- a/tradingagents/agents/managers/research_manager.py+++ b/tradingagents/agents/managers/research_manager.py@@ -36,7 +36,7 @@ def create_research_manager(llm):- **Underweight**: Cautious view; recommend trimming exposure- **Sell**: Strong conviction in the bear thesis; recommend exiting or avoiding the position-Commit to a directional stance only when the debate's strongest arguments clearly warrant one. Choose Hold when the evidence is balanced, materially conflicting, ambiguous, or insufficient to justify changing exposure; do not manufacture a direction merely to appear decisive. Weigh the bull and bear cases on their merits, independent of which side spoke first or last.+The debate always contains conflicting arguments; deciding which side is stronger is the job, so conflict alone is not a reason to Hold. Commit to the side with the stronger case, sized by how decisively it wins. Choose Hold only when the evidence is still balanced after that weighing, or too thin to support a call; do not manufacture a direction to appear decisive. Weigh the bull and bear cases on their merits, independent of which side spoke first or last.---diff --git a/tradingagents/agents/schemas.py b/tradingagents/agents/schemas.pyindex e933017d7..abafa2a67 100644--- a/tradingagents/agents/schemas.py+++ b/tradingagents/agents/schemas.py@@ -96,11 +96,10 @@ class ResearchPlan(BaseModel):recommendation: PortfolioRating = Field(description=("The investment recommendation. Exactly one of Buy / Overweight / "- "Hold / Underweight / Sell. Choose Hold when the evidence is "- "balanced, materially conflicting, ambiguous, or insufficient to "- "justify changing exposure; otherwise commit to the side with the "- "clearly stronger arguments. Do not pick a direction merely to be "- "decisive."+ "Hold / Underweight / Sell. Conflicting arguments alone are not a "+ "reason to Hold: commit to the stronger side, sized by how "+ "decisively it wins. Choose Hold only when the evidence is still "+ "balanced after weighing, or too thin to support a call."),)rationale: str = Field(@@ -221,10 +220,11 @@ class PortfolioDecision(BaseModel):rating: PortfolioRating = Field(description=("The final position rating. Exactly one of Buy / Overweight / Hold / "- "Underweight / Sell, picked based on the analysts' debate. Choose "- "Hold when the case is balanced, materially conflicting, ambiguous, "- "or insufficient to justify changing exposure, rather than forcing a "- "direction to appear decisive."+ "Underweight / Sell, picked based on the analysts' debate. "+ "Conflicting arguments alone are not a reason to Hold: commit to the "+ "stronger side, sized by how decisively it wins. Choose Hold only "+ "when the evidence is still balanced after weighing, or too thin to "+ "support a call."),)executive_summary: str = Field(