From 9cc173cc4d3a99ad63ed07dae598b8118d60c2c4 Mon Sep 17 00:00:00 2001 From: zhayujie Date: Thu, 2 Apr 2026 17:01:56 +0800 Subject: [PATCH] fix: use dynamic model name in system prompt runtime info --- agent/prompt/builder.py | 9 ++++++++- bridge/agent_initializer.py | 6 +++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/agent/prompt/builder.py b/agent/prompt/builder.py index fbd2e089..1b96d2cf 100644 --- a/agent/prompt/builder.py +++ b/agent/prompt/builder.py @@ -478,7 +478,14 @@ def _build_runtime_section(runtime_info: Dict[str, Any], language: str) -> List[ # Add other runtime info runtime_parts = [] - if runtime_info.get("model"): + # Support dynamic model via callable, fallback to static value + if callable(runtime_info.get("_get_model")): + try: + runtime_parts.append(f"模型={runtime_info['_get_model']()}") + except Exception: + if runtime_info.get("model"): + runtime_parts.append(f"模型={runtime_info['model']}") + elif runtime_info.get("model"): runtime_parts.append(f"模型={runtime_info['model']}") if runtime_info.get("workspace"): runtime_parts.append(f"工作空间={runtime_info['workspace']}") diff --git a/bridge/agent_initializer.py b/bridge/agent_initializer.py index 26c67c48..58bbbfb3 100644 --- a/bridge/agent_initializer.py +++ b/bridge/agent_initializer.py @@ -465,8 +465,12 @@ class AgentInitializer: 'timezone': timezone_name } + def get_model(): + """Get current model name dynamically from config""" + return conf().get("model", "unknown") + return { - "model": conf().get("model", "unknown"), + "_get_model": get_model, "workspace": workspace_root, "channel": ", ".join(conf().get("channel_type")) if isinstance(conf().get("channel_type"), list) else conf().get("channel_type", "unknown"), "_get_current_time": get_current_time # Dynamic time function