From 2d1a0997eba627301f6bdce5823ff2d675759dfa Mon Sep 17 00:00:00 2001 From: Zts0hg <47941778+Zts0hg@users.noreply.github.com> Date: Fri, 21 Nov 2025 09:41:34 +0800 Subject: [PATCH] feat: be compatible with case: `json_object` is not supported by used model (#673) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 兼容使用的模型不支持json结构化输出的情况 * fix: add explicit validation that the response content is valid JSON before proceeding to parse it --------- Co-authored-by: Willem Jiang --- src/graph/nodes.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/graph/nodes.py b/src/graph/nodes.py index 34325a5..fa978bd 100644 --- a/src/graph/nodes.py +++ b/src/graph/nodes.py @@ -282,10 +282,7 @@ def planner_node( if configurable.enable_deep_thinking: llm = get_llm_by_type("reasoning") elif AGENT_LLM_MAP["planner"] == "basic": - llm = get_llm_by_type("basic").with_structured_output( - Plan, - method="json_mode", - ) + llm = get_llm_by_type("basic") else: llm = get_llm_by_type(AGENT_LLM_MAP["planner"]) @@ -299,7 +296,10 @@ def planner_node( full_response = "" if AGENT_LLM_MAP["planner"] == "basic" and not configurable.enable_deep_thinking: response = llm.invoke(messages) - full_response = response.model_dump_json(indent=4, exclude_none=True) + if hasattr(response, "model_dump_json"): + full_response = response.model_dump_json(indent=4, exclude_none=True) + else: + full_response = get_message_content(response) or "" else: response = llm.stream(messages) for chunk in response: @@ -307,6 +307,20 @@ def planner_node( logger.debug(f"Current state messages: {state['messages']}") logger.info(f"Planner response: {full_response}") + # Validate explicitly that response content is valid JSON before proceeding to parse it + if not full_response.strip().startswith('{') and not full_response.strip().startswith('['): + logger.warning("Planner response does not appear to be valid JSON") + if plan_iterations > 0: + return Command( + update=preserve_state_meta_fields(state), + goto="reporter" + ) + else: + return Command( + update=preserve_state_meta_fields(state), + goto="__end__" + ) + try: curr_plan = json.loads(repair_json_output(full_response)) except json.JSONDecodeError: