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

This commit is contained in:
Subal authored and Xubin Ren committed 2026-04-17 20:39:46 +08:00
1 parent aabc3d5017
commit 322da6ca06
4 files changed
+218 -106

No files matched your search

+18 -8
View File
@@ -39,6 +39,7 @@ _EVALUATE_TOOL = [
}
]
async def evaluate_response(
response: str,
task_context: str,
@@ -55,12 +56,15 @@ async def evaluate_response(
llm_response = await provider.chat_with_retry(
messages=[
{"role": "system", "content": render_template("agent/evaluator.md", part="system")},
{"role": "user", "content": render_template(
"agent/evaluator.md",
part="user",
task_context=task_context,
response=response,
)},
{
"role": "user",
"content": render_template(
"agent/evaluator.md",
part="user",
task_context=task_context,
response=response,
),
},
],
tools=_EVALUATE_TOOL,
model=model,
@@ -68,8 +72,14 @@ async def evaluate_response(
temperature=0.0,
)
if not llm_response.has_tool_calls:
logger.warning("evaluate_response: no tool call returned, defaulting to notify")
if not llm_response.should_execute_tools:
if llm_response.has_tool_calls:
logger.warning(
"evaluate_response: ignoring tool calls under finish_reason='%s', defaulting to notify",
llm_response.finish_reason,
)
else:
logger.warning("evaluate_response: no tool call returned, defaulting to notify")
return True
args = llm_response.tool_calls[0].arguments