fix: guard tool execution against non-compliant API gateway injection

This commit is contained in:
Subal
2026-04-17 20:39:46 +08:00
committed by Xubin Ren
parent aabc3d5017
commit 322da6ca06
4 changed files with 218 additions and 106 deletions
+22 -8
View File
@@ -93,18 +93,29 @@ class HeartbeatService:
response = await self.provider.chat_with_retry(
messages=[
{"role": "system", "content": "You are a heartbeat agent. Call the heartbeat tool to report your decision."},
{"role": "user", "content": (
f"Current Time: {current_time_str(self.timezone)}\n\n"
"Review the following HEARTBEAT.md and decide whether there are active tasks.\n\n"
f"{content}"
)},
{
"role": "system",
"content": "You are a heartbeat agent. Call the heartbeat tool to report your decision.",
},
{
"role": "user",
"content": (
f"Current Time: {current_time_str(self.timezone)}\n\n"
"Review the following HEARTBEAT.md and decide whether there are active tasks.\n\n"
f"{content}"
),
},
],
tools=_HEARTBEAT_TOOL,
model=self.model,
)
if not response.has_tool_calls:
if not response.should_execute_tools:
if response.has_tool_calls:
logger.warning(
"Ignoring tool calls under finish_reason='%s' in heartbeat",
response.finish_reason,
)
return "skip", ""
args = response.tool_calls[0].arguments
@@ -166,7 +177,10 @@ class HeartbeatService:
if response:
should_notify = await evaluate_response(
response, tasks, self.provider, self.model,
response,
tasks,
self.provider,
self.model,
)
if should_notify and self.on_notify:
logger.info("Heartbeat: completed, delivering response")