Score the generated battlecard and decide whether to loop back.
(state: dict[str, Any])
| 96 | # --------------------------------------------------------------------------- |
| 97 | |
| 98 | async def quality_check(state: dict[str, Any]) -> dict[str, Any]: |
| 99 | """Score the generated battlecard and decide whether to loop back.""" |
| 100 | from langchain_core.messages import HumanMessage, SystemMessage |
| 101 | from langchain_openai import ChatOpenAI |
| 102 | |
| 103 | llm = ChatOpenAI( |
| 104 | model=config.llm.model, |
| 105 | api_key=config.llm.api_key, |
| 106 | temperature=0.0, |
| 107 | ) |
| 108 | |
| 109 | battlecard = state.get("battlecard", {}) |
| 110 | comparison = state.get("comparison_matrix", {}) |
| 111 | |
| 112 | prompt = ( |
| 113 | "You are a quality evaluator. Rate the following competitive intelligence " |
| 114 | "battlecard on a scale of 1-10 based on:\n" |
| 115 | " - Completeness (are strengths/weaknesses/objections covered?)\n" |
| 116 | " - Accuracy (does it align with the comparison data?)\n" |
| 117 | " - Actionability (can a sales rep use this immediately?)\n\n" |
| 118 | f"Battlecard:\n{json.dumps(battlecard, ensure_ascii=False, indent=2)}\n\n" |
| 119 | f"Comparison Matrix:\n{json.dumps(comparison, ensure_ascii=False, indent=2)}\n\n" |
| 120 | "Return ONLY a JSON object: {\"score\": <float>, \"feedback\": <string>}" |
| 121 | ) |
| 122 | |
| 123 | response = await llm.ainvoke([ |
| 124 | SystemMessage(content="You are a strict quality evaluator."), |
| 125 | HumanMessage(content=prompt), |
| 126 | ]) |
| 127 | |
| 128 | try: |
| 129 | text = response.content.strip() |
| 130 | if text.startswith("```"): |
| 131 | text = text.split("\n", 1)[1].rsplit("```", 1)[0] |
| 132 | result = json.loads(text) |
| 133 | score = float(result.get("score", 5.0)) |
| 134 | except Exception: |
| 135 | score = 5.0 |
| 136 | |
| 137 | reflexion_count = state.get("reflexion_count", 0) + 1 |
| 138 | |
| 139 | return { |
| 140 | "quality_score": score, |
| 141 | "reflexion_count": reflexion_count, |
| 142 | } |
| 143 | |
| 144 | |
| 145 | def _should_retry(state: dict[str, Any]) -> str: |
nothing calls this directly
no outgoing calls
no test coverage detected