fix(agent): harden secret confirmation failures (#6287)

This commit is contained in:
InfinityPacer
2026-08-13 10:55:02 +08:00
committed by GitHub
parent 527ceff5d1
commit f80562915d
4 changed files with 145 additions and 10 deletions
+29 -8
View File
@@ -907,6 +907,20 @@ class MoviePilotAgent:
return delivered is not False
return await self._deliver_private_channel_message(content)
async def _deliver_protected_output_with_fallback(
self,
content: str,
fallback_message: str,
) -> bool:
"""受保护投递失败时,仅通过普通回复报告不含敏感值的状态。"""
delivered = await self._deliver_protected_output(content)
if delivered:
return True
self._emit_output(fallback_message)
if self.should_dispatch_reply:
await self.send_agent_message(fallback_message)
return False
async def _handle_secret_confirmation_control(
self,
message: str,
@@ -955,7 +969,7 @@ class MoviePilotAgent:
tools=[pending.tool],
)
try:
_, result = await policy.execute_tool_call(
executed, result = await policy.execute_tool_call(
tool=pending.tool,
arguments=pending.arguments,
invocation_id=f"secret-confirmation-{uuid.uuid4().hex}",
@@ -963,15 +977,22 @@ class MoviePilotAgent:
)
except Exception:
message_text = "敏感设置读取失败,请稍后重试。"
await self._deliver_protected_output(message_text)
await self._deliver_protected_output_with_fallback(
message_text,
message_text,
)
return message_text
delivered = await self._deliver_protected_output(result)
fallback_message = (
"敏感设置读取已完成,但结果投递失败,请重新发起。"
if executed
else result
)
delivered = await self._deliver_protected_output_with_fallback(
result,
fallback_message,
)
if not delivered:
message_text = "敏感设置读取已完成,但结果投递失败,请重新发起。"
self._emit_output(message_text)
if self.should_dispatch_reply:
await self.send_agent_message(message_text)
return message_text
return fallback_message
return "敏感设置确认已处理。"
def _build_policy_context(self) -> ToolPolicyContext:
+8 -2
View File
@@ -18,6 +18,7 @@ from app.agent.tools.impl.query_system_settings import QuerySystemSettingsTool
POLICY_DENIED_MESSAGE = "当前宿主策略不允许执行该工具。"
POLICY_UNAVAILABLE_MESSAGE = "宿主策略暂时不可用,未执行该工具。"
class AgentPolicyMiddleware(AgentMiddleware):
@@ -135,9 +136,10 @@ class AgentPolicyMiddleware(AgentMiddleware):
arguments=arguments,
invocation_id=invocation_id,
)
if enforce_decision and observation is None:
return False, POLICY_UNAVAILABLE_MESSAGE
if (
enforce_decision
and observation is not None
and observation.decision.allowed is False
):
return False, POLICY_DENIED_MESSAGE
@@ -162,4 +164,8 @@ class AgentPolicyMiddleware(AgentMiddleware):
return True, result
__all__ = ["AgentPolicyMiddleware", "POLICY_DENIED_MESSAGE"]
__all__ = [
"AgentPolicyMiddleware",
"POLICY_DENIED_MESSAGE",
"POLICY_UNAVAILABLE_MESSAGE",
]