Merge pull request #2693 from 6vision/fix/bot-type-and-web-config

fix: rename zhipu bot_type, persist bot_type in web config, fix re.syb escape error
This commit is contained in:
zhayujie
2026-03-11 10:24:19 +08:00
committed by GitHub
6 changed files with 25 additions and 12 deletions

View File

@@ -166,7 +166,8 @@ class Agent:
# Find and replace the runtime section
import re
pattern = r'\n## 运行时信息\s*\n.*?(?=\n##|\Z)'
updated_prompt = re.sub(pattern, new_runtime_section.rstrip('\n'), prompt, flags=re.DOTALL)
_repl = new_runtime_section.rstrip('\n')
updated_prompt = re.sub(pattern, lambda m: _repl, prompt, flags=re.DOTALL)
return updated_prompt
except Exception as e:
@@ -195,7 +196,9 @@ class Agent:
if has_old_block:
replacement = new_block or "<available_skills>\n</available_skills>"
prompt = re.sub(old_block_pattern, replacement, prompt, flags=re.DOTALL)
# Use lambda to prevent re.sub from interpreting backslashes in replacement
# (e.g. Windows paths like \LinkAI would be treated as bad escape sequences)
prompt = re.sub(old_block_pattern, lambda m: replacement, prompt, flags=re.DOTALL)
elif new_block:
skills_header = "以下是可用技能:"
idx = prompt.find(skills_header)
@@ -224,7 +227,7 @@ class Agent:
# Replace existing tooling section
pattern = r'## 工具系统\s*\n.*?(?=\n## |\Z)'
updated = re.sub(pattern, new_section, prompt, count=1, flags=re.DOTALL)
updated = re.sub(pattern, lambda m: new_section, prompt, count=1, flags=re.DOTALL)
return updated
except Exception as e:
logger.warning(f"Failed to rebuild tool list section: {e}")