已合并
[fix]修复AgentContext.template_vars未渲染到主Agent的System Prompt中问题 #44
yuliangbin创建于 5月27日
[fix]修复AgentContext.template_vars未渲染到主Agent的System Prompt中问题 #44
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 yuliangbin 的贡献)5月27日 强制推送 1 个提交:4027865d-fix template_vars
ascend-robot
5月27日 评论:
5月27日 评论:
ascend-robot
5月27日 评论:
5月27日 评论:
Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/msagent | ✅ 刘鹏程, 张伟 (2/2) | ✅ 刘鹏程, 张伟 (2/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
yu_liangbin, thanks for your pull request. All authors of the commits have signed the CLA. 👍


5月27日 添加了label:ascend-cla/yes
Yyuliangbin
5月27日 修改标题为 “[fix]修复AgentContext.template_vars未渲染到主Agent的System Prompt中”,原标题为“fix template_vars”
5月27日 修改标题为 “[fix]修复AgentContext.template_vars未渲染到主Agent的System Prompt中”,原标题为“fix template_vars”
此处折叠了58条消息 查看更多
ascend-robot
6月2日 评论:
6月2日 评论:
The following label is not ready.
lgtm: Please wait for reviewers to review the code.


Mrtutu
6月2日 评论:
6月2日 评论:
/approve


ascend-robot
6月2日 评论:
6月2日 评论:
The following users do not have permission to comment /lgtm or /approve on any module in this PR:
Xilun_Liu


6月2日 添加了label:lgtm
6月2日 合入了pull request
一、问题现状:
environments.md 里的占位符没有被替换,LLM 收到的还是 {working_dir}、{platform}、{current_date_time_zoned} 这类字面量。
关联issue:
https://gitcode.com/Ascend/msagent/issues/24
二、问题原因:
template_vars 虽然已经有真实值,但主 Agent 在发起模型调用前没有正确渲染 system_message。
同时,prompt 中还混有 {worker}、{Rank_ID} 这类示例占位符,原来的整段 str.format(context) 一遇到未知变量就整段回退,导致本来能替换的变量也失效。
三、问题解决:
在 src/msagent/agents/factory.py 的 _SystemMessageMiddleware 中补充运行时 safe render 逻辑,用于在模型调用前渲染 system_message 中的模板变量。
四、结果验证:


修复前日志里是:
Working directory: {working_dir}
Platform: {platform}
修复后日志里已经变成:
Working directory: /home/ylb/msagent
Platform: Linux