Skip to content

Commit 07b2d5c

Browse files
committed
test(integration): add debug logging and set safe LLM call limit for Google ADK tests
Add comprehensive debug logging to mock LLM server and scenarios to help troubleshoot Google ADK message format issues. Also set a reasonable maximum LLM calls limit of 10 to prevent infinite loops while maintaining test functionality. Added detailed message logging in MockLLMServer to track role and content, including tool calls and tool call IDs. Added debug information in MockScenario to track tool messages and current turn calculations. Set safe LLM call limit to 10 in GoogleADKTestMixin to avoid infinite loops during testing. 添加详细的调试日志记录到模拟 LLM 服务器和场景中,以帮助排查 Google ADK 消息格式问题。同时设置合理的最大 LLM 调用次数限制为 10,以防止无限循环,同时保持测试功能。 在 MockLLMServer 中添加了详细的消息日志记录以跟踪角色和内容,包括工具调用和工具调用 ID。在 MockScenario 中添加了调试信息以跟踪工具消息和当前回合计算。在 GoogleADKTestMixin 中将安全的 LLM 调用限制设置为 10,以避免测试期间的无限循环。 Change-Id: I35875fa483297be319313c00aa706e1f4e160bf6 Signed-off-by: OhYee <oyohyee@oyohyee.com>
1 parent 7da6a03 commit 07b2d5c

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

tests/unittests/integration/mock_llm_server.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,27 @@ def _build_response(
304304
tools_payload is not None,
305305
)
306306

307+
# 添加详细的消息日志,帮助调试 Google ADK 的消息格式
308+
for i, msg in enumerate(messages):
309+
role = msg.get("role", "unknown")
310+
content_preview = str(msg.get("content", ""))[:100]
311+
logger.debug(
312+
"Message[%d] role=%s, content_preview=%s",
313+
i,
314+
role,
315+
content_preview,
316+
)
317+
if "tool_calls" in msg:
318+
logger.debug(
319+
"Message[%d] has tool_calls: %s", i, msg.get("tool_calls")
320+
)
321+
if "tool_call_id" in msg:
322+
logger.debug(
323+
"Message[%d] has tool_call_id: %s",
324+
i,
325+
msg.get("tool_call_id"),
326+
)
327+
307328
# 验证工具格式
308329
if self.validate_tools and self.expect_tools and tools_payload:
309330
self._assert_tools(tools_payload)

tests/unittests/integration/scenarios.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,32 @@ def get_response(self, messages: List[Dict]) -> MockTurn:
113113
- 如果最后一条消息是 tool 类型,说明工具已执行,进入下一轮
114114
- 否则返回当前轮次
115115
"""
116+
import logging
117+
118+
logger = logging.getLogger(__name__)
119+
116120
# 计算当前应该返回哪一轮
117121
tool_rounds = sum(1 for msg in messages if msg.get("role") == "tool")
118122

123+
# 添加调试信息
124+
logger.debug(
125+
"Scenario '%s': Found %d tool messages, total turns: %d",
126+
self.name,
127+
tool_rounds,
128+
len(self.turns),
129+
)
130+
119131
# 根据工具消息数量确定当前轮次
120132
# 每个工具响应对应一个轮次的推进
121133
current_idx = min(tool_rounds, len(self.turns) - 1)
134+
135+
logger.debug(
136+
"Scenario '%s': Returning turn %d, has_tool_calls=%s",
137+
self.name,
138+
current_idx,
139+
self.turns[current_idx].has_tool_calls(),
140+
)
141+
122142
return self.turns[current_idx]
123143

124144
def reset(self):

tests/unittests/integration/test_google_adk.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ async def ainvoke(self, agent: Any, message: str) -> IntegrationTestResult:
9494
app_name=runner.app_name, user_id="test-user"
9595
)
9696

97-
# 禁用 LLM 调用限制以避免测试失败
97+
# 设置一个安全的 LLM 调用限制,避免无限循环
98+
# 正常的工具调用场景不应该超过 10 次 LLM 调用
9899
from google.adk.agents.run_config import RunConfig
99100

100-
run_config = RunConfig(max_llm_calls=0)
101+
run_config = RunConfig(max_llm_calls=10)
101102

102103
result = runner.run(
103104
user_id=session.user_id,

0 commit comments

Comments
 (0)