Skip to content

fix: clamp retry_attempts in CriticAgent like ChatAgent - #4382

Open
aniketkrs wants to merge 1 commit into
camel-ai:masterfrom
aniketkrs:fix/critic-retry-clamp
Open

aniketkrs wants to merge 1 commit into
camel-ai:masterfrom
aniketkrs:fix/critic-retry-clamp

Conversation

@aniketkrs

Copy link
Copy Markdown

User impact

CriticAgent(retry_attempts=0) never consults the model: get_option() skips its retry loop entirely and silently returns a random option. Users passing retry_attempts=0 get an ungrounded answer with no indication that the LLM was never called.

Fixes #4378.

Technical cause

ChatAgent.__init__ clamps the value (chat_agent.py:649, self.retry_attempts = max(1, retry_attempts)), but CriticAgent.__init__ overwrites it with the raw argument (critic_agent.py:97, self.retry_attempts = retry_attempts). With retry_attempts=0, the while i < self.retry_attempts: loop at critic_agent.py:138 never executes, so control falls through to the warnings.warn(...) + random.choice(...) fallback at lines 165-170.

Fix

Mirror the parent's clamp in the subclass:

self.retry_attempts = max(1, retry_attempts)

This restores the invariant ChatAgent already enforces; clone() also propagates the clamped value since it passes self.retry_attempts on.

Copilot AI balanced review requested due to automatic review settings September 30, 2026 04:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

鈿欙笍 Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: a7548a69-8053-41be-9b2a-e95e3f62f155

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 馃攳 Trigger review

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.

This branch has not been deployed

No deployments
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.

[BUG] CriticAgent overwrites ChatAgent's retry_attempts clamp, so retry_attempts=0 answers at random without calling the model

2 participants