feat(agent-runtime): 补全测试替身编排闭环
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"""Agent 运行配置边界。"""
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
from common.exceptions import AgentConfigurationError
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class AgentRuntimeConfig:
|
||||
"""集中表达真实 SDK 执行所需配置,避免业务服务直接读取环境变量。"""
|
||||
|
||||
api_key: str
|
||||
model: str
|
||||
agent_name: str
|
||||
|
||||
@classmethod
|
||||
def from_settings(cls) -> "AgentRuntimeConfig":
|
||||
"""从 Django 设置构建配置;这里只读取,不在日志或异常中回显秘密。"""
|
||||
|
||||
return cls(
|
||||
api_key=str(settings.OPENAI_API_KEY or "").strip(),
|
||||
model=str(settings.OPENAI_MODEL or "").strip(),
|
||||
agent_name=str(settings.AGENT_DEFAULT_NAME or "job_research").strip(),
|
||||
)
|
||||
|
||||
def require_real_execution(self) -> "AgentRuntimeConfig":
|
||||
"""真实执行前快速失败;非 Agent 页面无需调用此方法。"""
|
||||
|
||||
missing = []
|
||||
if not self.api_key:
|
||||
missing.append("OPENAI_API_KEY")
|
||||
if not self.model:
|
||||
missing.append("OPENAI_MODEL")
|
||||
if missing:
|
||||
raise AgentConfigurationError(f"真实 Agent 执行缺少配置:{', '.join(missing)}。")
|
||||
return self
|
||||
Reference in New Issue
Block a user