From dab1ba47891a8ee64644f15edcb86f26fd717e56 Mon Sep 17 00:00:00 2001 From: Zhao Longjie Date: Tue, 29 Apr 2025 18:17:27 +0800 Subject: [PATCH] fix(planner): skip human feedback if context is sufficient Change-Id: I2b5628a7a8ecb6a6bad2712a9ff81b9b1cd323c6 --- src/graph/nodes.py | 18 ++++++++++++++++++ src/prompts/planner_model.py | 2 +- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/graph/nodes.py b/src/graph/nodes.py index e5cc896..412b362 100644 --- a/src/graph/nodes.py +++ b/src/graph/nodes.py @@ -116,6 +116,24 @@ def planner_node( logger.debug(f"Current state messages: {state['messages']}") logger.info(f"Planner response: {full_response}") + try: + curr_plan = json.loads(repair_json_output(full_response)) + except json.JSONDecodeError: + logger.warning("Planner response is not a valid JSON") + if plan_iterations > 0: + return Command(goto="reporter") + else: + return Command(goto="__end__") + if curr_plan.get("has_enough_context"): + logger.info("Planner response has enough context.") + new_plan = Plan.model_validate(curr_plan) + return Command( + update={ + "messages": [AIMessage(content=full_response, name="planner")], + "current_plan": new_plan, + }, + goto="reporter", + ) return Command( update={ "messages": [AIMessage(content=full_response, name="planner")], diff --git a/src/prompts/planner_model.py b/src/prompts/planner_model.py index b75d00b..4e1f544 100644 --- a/src/prompts/planner_model.py +++ b/src/prompts/planner_model.py @@ -32,7 +32,7 @@ class Plan(BaseModel): thought: str title: str steps: List[Step] = Field( - ..., + default_factory=list, description="Research & Processing steps to get more context", )