Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix: In the output, the order of 'ta' is sometimes reversed as 'at'. #8015 (#8791)
Wei-shun Baofb32e5ca9a10
diff --git a/api/core/agent/output_parser/cot_output_parser.py b/api/core/agent/output_parser/cot_output_parser.pyindex 99876b2f5eb..085bac8601b 100644--- a/api/core/agent/output_parser/cot_output_parser.py+++ b/api/core/agent/output_parser/cot_output_parser.py@@ -62,6 +62,8 @@ class CotAgentOutputParser:thought_str = "thought:"thought_idx = 0+ last_character = ""+for response in llm_response:if response.delta.usage:usage_dict["usage"] = response.delta.usage@@ -74,35 +76,38 @@ class CotAgentOutputParser:while index < len(response):steps = 1delta = response[index : index + steps]- last_character = response[index - 1] if index > 0 else ""+ yield_delta = Falseif delta == "`":+ last_character = deltacode_block_cache += deltacode_block_delimiter_count += 1else:if not in_code_block:if code_block_delimiter_count > 0:+ last_character = deltayield code_block_cachecode_block_cache = ""else:+ last_character = deltacode_block_cache += deltacode_block_delimiter_count = 0if not in_code_block and not in_json:if delta.lower() == action_str[action_idx] and action_idx == 0:if last_character not in {"\n", " ", ""}:+ yield_delta = True+ else:+ last_character = delta+ action_cache += delta+ action_idx += 1+ if action_idx == len(action_str):+ action_cache = ""+ action_idx = 0index += steps- yield deltacontinue-- action_cache += delta- action_idx += 1- if action_idx == len(action_str):- action_cache = ""- action_idx = 0- index += steps- continueelif delta.lower() == action_str[action_idx] and action_idx > 0:+ last_character = deltaaction_cache += deltaaction_idx += 1if action_idx == len(action_str):@@ -112,24 +117,25 @@ class CotAgentOutputParser:continueelse:if action_cache:+ last_character = deltayield action_cacheaction_cache = ""action_idx = 0if delta.lower() == thought_str[thought_idx] and thought_idx == 0:if last_character not in {"\n", " ", ""}:+ yield_delta = True+ else:+ last_character = delta+ thought_cache += delta+ thought_idx += 1+ if thought_idx == len(thought_str):+ thought_cache = ""+ thought_idx = 0index += steps- yield deltacontinue-- thought_cache += delta- thought_idx += 1- if thought_idx == len(thought_str):- thought_cache = ""- thought_idx = 0- index += steps- continueelif delta.lower() == thought_str[thought_idx] and thought_idx > 0:+ last_character = deltathought_cache += deltathought_idx += 1if thought_idx == len(thought_str):@@ -139,12 +145,20 @@ class CotAgentOutputParser:continueelse:if thought_cache:+ last_character = deltayield thought_cachethought_cache = ""thought_idx = 0+ if yield_delta:+ index += steps+ last_character = delta+ yield delta+ continue+if code_block_delimiter_count == 3:if in_code_block:+ last_character = deltayield from extra_json_from_code_block(code_block_cache)code_block_cache = ""@@ -156,8 +170,10 @@ class CotAgentOutputParser:if delta == "{":json_quote_count += 1in_json = True+ last_character = deltajson_cache += deltaelif delta == "}":+ last_character = deltajson_cache += deltaif json_quote_count > 0:json_quote_count -= 1@@ -168,16 +184,19 @@ class CotAgentOutputParser:continueelse:if in_json:+ last_character = deltajson_cache += deltaif got_json:got_json = False+ last_character = deltayield parse_action(json_cache)json_cache = ""json_quote_count = 0in_json = Falseif not in_code_block and not in_json:+ last_character = deltayield delta.replace("`", "")index += steps