代码提交
This commit is contained in:
1 parent
1eae02f782
commit
e58da3fbdf
4 files changed
+240
-57
No files matched your search
+29
-12
@@ -1445,6 +1445,27 @@ class ScheduledTaskService:
|
||||
return "\n".join(p for p in parts if p)
|
||||
return str(content)
|
||||
|
||||
async def _agent_soul_and_model(
|
||||
self, task: dict[str, Any], model_name: str | None
|
||||
) -> tuple[str | None, str | None]:
|
||||
"""Resolve the task agent's SOUL; fall back to its model when none chosen.
|
||||
|
||||
Used by both template pipelines so the **task's selected agent** shapes
|
||||
content conversion: the SOUL carries the agent's domain instructions,
|
||||
and when the user didn't pick an explicit model the agent's configured
|
||||
model is preferred over the system default. Returns ``(soul, model)``.
|
||||
"""
|
||||
agent_ref = task.get("execution_agent_name")
|
||||
agent_id = await self._resolve_agent_id(agent_ref, task["user_id"]) if agent_ref else None
|
||||
soul = load_agent_soul(agent_id) if agent_id else None
|
||||
if not model_name and agent_id:
|
||||
try:
|
||||
agent_cfg = load_agent_config(agent_id)
|
||||
model_name = (agent_cfg.model if agent_cfg else None) or None
|
||||
except Exception:
|
||||
model_name = None
|
||||
return soul, model_name
|
||||
|
||||
async def _convert_to_template_data(
|
||||
self,
|
||||
template_id: str,
|
||||
@@ -1574,8 +1595,9 @@ class ScheduledTaskService:
|
||||
cfg = self._html_config(task)
|
||||
model_name = str(cfg.get("model_name") or "").strip() or None
|
||||
# 「执行数据抽取」开关**只**控制 HTML 用「抽取数据」还是「模板默认数据」,
|
||||
# 不影响 Markdown 生成等其它正常操作。
|
||||
extract = bool(cfg.get("template_extract"))
|
||||
# 不影响 Markdown 生成等其它正常操作。缺省(未存该键的老任务)视为开启:
|
||||
# 模板有真实数据来源后,默认走「智能体检索 → 转换填充」,显式 False 才关闭。
|
||||
extract = cfg.get("template_extract") is not False
|
||||
also_markdown = _task_requires_markdown(task)
|
||||
prompt = str(task.get("prompt") or "").strip()
|
||||
description = str(task.get("description") or "").strip()
|
||||
@@ -1626,9 +1648,12 @@ class ScheduledTaskService:
|
||||
source = (data_text or "").strip()
|
||||
used_default = True
|
||||
if do_extract and source:
|
||||
# 转换阶段同样带上任务所选智能体:SOUL 提供领域口径,未显式选模型时
|
||||
# 兜底用该智能体配置的模型(与模板填充模式一致)。
|
||||
soul, conv_model = await self._agent_soul_and_model(task, model_name)
|
||||
try:
|
||||
converted = await self._convert_to_template_data(
|
||||
tpl_id, source, model_name=model_name, soul=None, run_id=run_id
|
||||
tpl_id, source, model_name=conv_model, soul=soul, run_id=run_id
|
||||
)
|
||||
# 子页面没抽到有效内容的,回退模板原有数据,避免子页面空白。
|
||||
data_obj = template_fill.merge_with_reference(tpl_id, converted)
|
||||
@@ -1712,16 +1737,8 @@ class ScheduledTaskService:
|
||||
tcfg = tcfg if isinstance(tcfg, dict) else {}
|
||||
|
||||
# 选中的内置 agent 的 SOUL + 模型(template_config.model_name 优先,其次 agent.model)。
|
||||
agent_ref = task.get("execution_agent_name")
|
||||
agent_id = await self._resolve_agent_id(agent_ref, task["user_id"]) if agent_ref else None
|
||||
soul = load_agent_soul(agent_id) if agent_id else None
|
||||
model_name = str(tcfg.get("model_name") or "").strip() or None
|
||||
if not model_name and agent_id:
|
||||
try:
|
||||
agent_cfg = load_agent_config(agent_id)
|
||||
model_name = (agent_cfg.model if agent_cfg else None) or None
|
||||
except Exception:
|
||||
model_name = None
|
||||
soul, model_name = await self._agent_soul_and_model(task, model_name)
|
||||
|
||||
converted = await self._convert_to_template_data(
|
||||
template_id, source, model_name=model_name, soul=soul, run_id=run_id
|
||||
|
||||
Reference in new issue
Block a user