Skip to content

Fix: Add Reach Max Tool Iter Debug Info#146

Open
wjc1207 wants to merge 1 commit intomemovai:mainfrom
wjc1207:feat/tool-iter
Open

Fix: Add Reach Max Tool Iter Debug Info#146
wjc1207 wants to merge 1 commit intomemovai:mainfrom
wjc1207:feat/tool-iter

Conversation

@wjc1207
Copy link
Copy Markdown
Contributor

@wjc1207 wjc1207 commented Mar 12, 2026

Fix: Add Reach Max Tool Iter Debug Info

Summary by CodeRabbit

  • Bug Fixes
    • Improved messaging when the agent reaches the maximum tool-iteration limit: users will now see a clear notice indicating processing stopped due to hitting the iteration cap, making failures easier to understand.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 12, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 01987657-e355-4276-bf2a-272298f226d0

📥 Commits

Reviewing files that changed from the base of the PR and between a99b7cd and 352d823.

📒 Files selected for processing (1)
  • main/agent/agent_loop.c
🚧 Files skipped from review as they are similar to previous changes (1)
  • main/agent/agent_loop.c

📝 Walkthrough

Walkthrough

Added a post-loop guard log in the agent loop that emits an error when the iteration count reached or exceeded MIMI_AGENT_MAX_TOOL_ITER. No control-flow or final response/error-handling behavior was changed.

Changes

Cohort / File(s) Summary
Agent loop guard
main/agent/agent_loop.c
Added a post-loop check that logs an error "Reached maximum tool iterations, stop processing" when iterations >= MIMI_AGENT_MAX_TOOL_ITER. No control-flow or final-response changes were introduced.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇 I hopped through loops and counted each try,
When max was reached I gave a small cry.
A log I left, clear as a bell,
So debuggers read and all is well.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding debug logging when maximum tool iterations are reached.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
main/agent/agent_loop.c (1)

308-312: LGTM! Clear improvement to error messaging.

The condition iteration >= MIMI_AGENT_MAX_TOOL_ITER correctly identifies when the loop exited due to hitting the max iterations limit vs. other errors (LLM failure). The logic is consistent with the loop condition while (iteration < MIMI_AGENT_MAX_TOOL_ITER) at line 218.

Optional: Consider adding an ESP_LOGW when max iterations is reached for server-side observability/debugging:

💡 Optional logging enhancement
             if (iteration >= MIMI_AGENT_MAX_TOOL_ITER) {
+                ESP_LOGW(TAG, "Reached max tool iterations (%d) without final response for %s:%s",
+                         MIMI_AGENT_MAX_TOOL_ITER, msg.channel, msg.chat_id);
                 out.content = strdup("Sorry, I reached the maximum number of tool iterations without completing the response.");
             } else {

,

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@main/agent/agent_loop.c` around lines 308 - 312, Add a warning log when the
loop exits due to hitting the max tool iterations: inside the existing branch
that checks iteration >= MIMI_AGENT_MAX_TOOL_ITER (the same block that sets
out.content to the "maximum number of tool iterations" message), call ESP_LOGW
(or the project's logging macro) with context including the current iteration
and MIMI_AGENT_MAX_TOOL_ITER to aid server-side observability; keep the existing
out.content behavior unchanged and place the log next to that strdup to ensure
it's executed in the same failure path (refer to variables iteration,
MIMI_AGENT_MAX_TOOL_ITER, and out.content and the while (iteration <
MIMI_AGENT_MAX_TOOL_ITER) loop in agent_loop.c).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@main/agent/agent_loop.c`:
- Around line 308-312: Add a warning log when the loop exits due to hitting the
max tool iterations: inside the existing branch that checks iteration >=
MIMI_AGENT_MAX_TOOL_ITER (the same block that sets out.content to the "maximum
number of tool iterations" message), call ESP_LOGW (or the project's logging
macro) with context including the current iteration and MIMI_AGENT_MAX_TOOL_ITER
to aid server-side observability; keep the existing out.content behavior
unchanged and place the log next to that strdup to ensure it's executed in the
same failure path (refer to variables iteration, MIMI_AGENT_MAX_TOOL_ITER, and
out.content and the while (iteration < MIMI_AGENT_MAX_TOOL_ITER) loop in
agent_loop.c).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 73ba6989-2bf6-4238-b77b-d24235217e68

📥 Commits

Reviewing files that changed from the base of the PR and between 974ec7f and a99b7cd.

📒 Files selected for processing (1)
  • main/agent/agent_loop.c

@crispyberry
Copy link
Copy Markdown
Contributor

What's your use case to hit this limits bro

@wjc1207
Copy link
Copy Markdown
Contributor Author

wjc1207 commented Mar 12, 2026

What's your use case to hit this limits bro

@crispyberry I let mimiclaw write and run micropython to do some simulation. It tried, failed and re-tried repeatively. Finally it hit this limit

@IRONICBo IRONICBo self-requested a review March 12, 2026 17:11
@IRONICBo IRONICBo self-assigned this Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants