feat: deprecate agent-level cli_backend and add doctor fix migration#1946
feat: deprecate agent-level cli_backend and add doctor fix migration#1946praisonai-triage-agent[bot] wants to merge 2 commits into
Conversation
- Add DeprecationWarning to core Agent when cli_backend used with model config - Add DeprecationWarning to wrapper Agent when cli_backend used with model config - Implement doctor fix command for automated config migration - Add --fix, --execute, and --no-backup flags to doctor CLI - Create migration tool that detects and annotates deprecated cli_backend usage - Maintain backward compatibility during deprecation period Fixes #1942 Co-authored-by: MervinPraison <MervinPraison@users.noreply.github.com>
|
@coderabbitai review |
|
/review |
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more โ On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
โ Action performedReview finished.
|
|
Important Review skippedBot user detected. To trigger a single review, invoke the โ๏ธ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
๐ WalkthroughWalkthroughDeprecation warnings now gate agent-level Changescli_backend Deprecation and Doctor Fix Migration
Estimated code review effort๐ฏ 3 (Moderate) | โฑ๏ธ ~20 minutes Possibly related PRs
Poem
๐ฅ Pre-merge checks | โ 4 | โ 1โ Failed checks (1 inconclusive)
โ Passed checks (4 passed)
โ๏ธ Tip: You can configure your own custom pre-merge checks in the settings. โจ Finishing Touches๐งช Generate unit tests (beta)
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. Comment |
|
@copilot Do a thorough review of this PR. Read ALL existing reviewer comments above from Qodo, Coderabbit, and Gemini first โ incorporate their findings. Review areas:
|
Greptile SummaryThis PR deprecates the agent-level
Confidence Score: 3/5Safe to merge for the deprecation warning path; the The deprecation warning change in the core and wrapper agents is straightforward and low-risk. The src/praisonai/praisonai/cli/features/doctor/handler.py โ the Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[praisonai doctor fix] --> B{--execute flag?}
B -- No dry-run --> C[Scan *.yaml / *.yml]
B -- Yes execute --> C
C --> D{YAML files found?}
D -- No --> E[Print: No YAML files found
return 0]
D -- Yes --> F[For each YAML file]
F --> G[yaml.safe_load]
G --> H{has cli_backend + llm/model?}
H -- No --> I[Next file]
H -- Yes --> J[issues_found++
print warning]
J --> K{--execute?}
K -- No dry-run --> L[Print: run with --execute
return 0 even if issues found]
K -- Yes --> M{--no-backup?}
M -- No --> N[shutil.copy2 to .bak]
M -- Yes --> O[Skip backup]
N --> P[_migrate_cli_backend_config
shallow copy + annotate]
O --> P
P --> Q[yaml.dump strips all comments
and reformats file]
Q --> R[files_modified++]
R --> I
I --> S[All files done]
S --> T{files_failed > 0?}
T -- Yes --> U[return 1]
T -- No --> V[return 0]
Reviews (2): Last reviewed commit: "fix: address critical deprecation and do..." | Re-trigger Greptile |
| def _migrate_cli_backend_config(self, data: dict) -> dict: | ||
| """Migrate cli_backend configuration (simplified migration).""" | ||
| migrated = data.copy() | ||
|
|
||
| # Add migration comment at top level | ||
| if 'migration_info' not in migrated: | ||
| migrated['migration_info'] = { | ||
| 'cli_backend_migration': 'Agent-level cli_backend deprecated. Consider model-scoped runtime configuration.', | ||
| 'migrated_by': 'praisonai doctor fix', | ||
| } | ||
|
|
||
| # For now, just add comments rather than removing cli_backend | ||
| # since full migration requires understanding the intended model-scoped runtime pattern | ||
| for section in ['roles', 'agents']: | ||
| section_data = migrated.get(section, {}) | ||
| if isinstance(section_data, dict): | ||
| for agent_name, agent_config in section_data.items(): | ||
| if isinstance(agent_config, dict) and 'cli_backend' in agent_config: | ||
| if 'llm' in agent_config or 'model' in agent_config: | ||
| # Add migration note | ||
| agent_config['_migration_note'] = f"cli_backend is deprecated when model is specified. Consider model-scoped runtime." | ||
|
|
||
| return migrated |
There was a problem hiding this comment.
Shallow copy mutates original
data through nested references
migrated = data.copy() is a shallow copy, so migrated['roles'] and data['roles'] still point to the same nested dict objects. The loop then mutates agent_config['_migration_note'] = ... directly on those shared objects, meaning the original data is also modified. In the current flow this has no observable consequence (the migrated dict is written, then the function returns), but it violates the contract of a helper that should not modify its input and could cause subtle bugs if the caller reuses data after this call.
There was a problem hiding this comment.
Actionable comments posted: 6
๐ค Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/praisonai-agents/praisonaiagents/agent/agent.py`:
- Around line 2038-2048: The deprecation warning text emitted when 'cli_backend'
is provided (in the block checking llm or model) contains incorrect remediation
hints; update the warnings.warn message in that block to remove the invalid "Use
'allow_legacy_runtime_pin=True'..." suggestion and to point users to the correct
remediation and CLI command (replace "praisonai doctor --fix" with "praisonai
doctor fix" and/or a pointer to the docs). Specifically, edit the warnings.warn
call that references 'cli_backend' (the llm/model check) so the message suggests
using model-scoped runtime configuration or the documented way to opt into
legacy runtime pinning (do not reference the nonexistent
allow_legacy_runtime_pin parameter) and instructs users to run "praisonai doctor
fix" for migration assistance; keep DeprecationWarning and stacklevel=2.
In `@src/praisonai/praisonai/agent.py`:
- Around line 33-45: The wrapper-level DeprecationWarning for cli_backend is
duplicating the same warning emitted by super().__init__; remove the warning
block in this wrapper (the if 'model' in kwargs or 'llm' in kwargs
warnings.warn(...) code that references cli_backend and DeprecationWarning) and
simply pass through kwargs (including allow_legacy_runtime_pin) to
super().__init__; alternatively, if you prefer an explicit suppression approach,
set an internal flag in kwargs (e.g. '_suppress_deprecation_warning'=True)
before calling super().__init__ and have the upstream super().__init__ check
that flag to avoid emitting the duplicate warning โ in either case ensure
cli_backend, allow_legacy_runtime_pin, and the wrapper call to super().__init__
are the touched symbols.
In `@src/praisonai/praisonai/cli/commands/doctor.py`:
- Around line 350-360: The doctor CLI is forwarding --config but the downstream
DoctorHandler expects --file (config_file), so update the argument construction
in the doctor command (the block building args in
src/praisonai/praisonai/cli/commands/doctor.py) to pass the flag the handler
parses: replace args.extend(["--config", config_path]) with
args.extend(["--file", config_path]) (or alternatively update DoctorHandler to
accept --config and map it to config_file), ensuring the flag name and the
handler parameter (config_file) match.
In `@src/praisonai/praisonai/cli/features/doctor/handler.py`:
- Line 378: Remove the unnecessary f-string prefixes on the two plain-string
print calls (e.g., change print(f" Run with --execute to apply migration") to
print(" Run with --execute to apply migration")); locate the two occurrences
by searching for the exact string " Run with --execute to apply migration"
(and the other similar plain-constant print at the other reported location) and
simply drop the leading f so they are ordinary string literals, keeping all
other code unchanged.
- Around line 330-333: The YAML discovery can add duplicates because patterns =
["*.yaml", "*.yml", "agents.yaml", "config.yaml"] is iterated and yaml_files is
extended for each match; after the loop, deduplicate yaml_files (preserving
order) before any migration/processing (e.g., replace yaml_files with
list(dict.fromkeys(yaml_files)) or use an OrderedDict/set-based filter) so each
file is processed once; ensure this deduplication occurs after the loop that
builds yaml_files and before any summary/count or migration logic that uses
yaml_files.
- Around line 380-395: The handler currently logs per-file exceptions inside the
try/except but always returns 0, hiding failures; update the function in
src/praisonai/praisonai/cli/features/doctor/handler.py (the CLI "doctor" handler
that uses variables issues_found and files_modified) to track processing errors
(e.g., add an errors_count or had_errors flag initialized before the file loop
and increment/set it inside the except Exception as e block), and then change
the final return logic so the function returns a non-zero exit code (e.g.,
return 1) when any file processing errors were recorded; keep existing summary
prints intact (including the quiet/execute branches) but ensure the return value
reflects errors_found.
๐ช Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
โน๏ธ Review info
โ๏ธ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: b9362e5b-f9c0-479f-9555-eeff09d6b3ec
๐ Files selected for processing (6)
src/praisonai-agents/praisonaiagents/agent/agent.pysrc/praisonai/praisonai/agent.pysrc/praisonai/praisonai/cli/commands/doctor.pysrc/praisonai/praisonai/cli/features/doctor/handler.pysrc/praisonai/praisonai/cli/features/doctor/models.pytest_config.yaml
| # Emit deprecation warning when model-scoped runtime is available | ||
| if llm is not None or model is not None: | ||
| import warnings | ||
| warnings.warn( | ||
| "Agent-level 'cli_backend' parameter is deprecated when model configuration is available. " | ||
| "Consider using model-scoped runtime configuration instead. " | ||
| "Use 'allow_legacy_runtime_pin=True' to suppress this warning. " | ||
| "For migration assistance, run: praisonai doctor --fix", | ||
| DeprecationWarning, | ||
| stacklevel=2 | ||
| ) |
There was a problem hiding this comment.
Fix deprecation warning remediation text to match actual APIs.
Line 2044-2045 suggests allow_legacy_runtime_pin=True and praisonai doctor --fix, but this constructor does not accept allow_legacy_runtime_pin, and the new command surface is praisonai doctor fix. Following this guidance can misroute users and fail migrations.
Suggested patch
- warnings.warn(
- "Agent-level 'cli_backend' parameter is deprecated when model configuration is available. "
- "Consider using model-scoped runtime configuration instead. "
- "Use 'allow_legacy_runtime_pin=True' to suppress this warning. "
- "For migration assistance, run: praisonai doctor --fix",
- DeprecationWarning,
- stacklevel=2
- )
+ warnings.warn(
+ "Agent-level 'cli_backend' parameter is deprecated when model configuration is available. "
+ "Consider using model-scoped runtime configuration instead. "
+ "For migration assistance, run: praisonai doctor fix --execute",
+ DeprecationWarning,
+ stacklevel=2
+ )As per coding guidelines, โError messages must include remediation hints and propagate context โฆ for debugging.โ
๐ค Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/praisonai-agents/praisonaiagents/agent/agent.py` around lines 2038 -
2048, The deprecation warning text emitted when 'cli_backend' is provided (in
the block checking llm or model) contains incorrect remediation hints; update
the warnings.warn message in that block to remove the invalid "Use
'allow_legacy_runtime_pin=True'..." suggestion and to point users to the correct
remediation and CLI command (replace "praisonai doctor --fix" with "praisonai
doctor fix" and/or a pointer to the docs). Specifically, edit the warnings.warn
call that references 'cli_backend' (the llm/model check) so the message suggests
using model-scoped runtime configuration or the documented way to opt into
legacy runtime pinning (do not reference the nonexistent
allow_legacy_runtime_pin parameter) and instructs users to run "praisonai doctor
fix" for migration assistance; keep DeprecationWarning and stacklevel=2.
Source: Coding guidelines
| # Check for deprecation warning in wrapper layer | ||
| if cli_backend is not None: | ||
| # Check if model/llm is specified in kwargs | ||
| if 'model' in kwargs or 'llm' in kwargs: | ||
| import warnings | ||
| warnings.warn( | ||
| "Agent-level 'cli_backend' parameter is deprecated when model configuration is available. " | ||
| "Consider using model-scoped runtime configuration instead. " | ||
| "Use 'allow_legacy_runtime_pin=True' to suppress this warning. " | ||
| "For migration assistance, run: praisonai doctor --fix", | ||
| DeprecationWarning, | ||
| stacklevel=2 | ||
| ) |
There was a problem hiding this comment.
This wrapper path emits duplicate deprecation warnings.
Line 33-45 warns here, and super().__init__ warns again in src/praisonai-agents/praisonaiagents/agent/agent.py Line 2038-2048 for the same call. Consider warning in only one layer (or adding an internal suppression path) to avoid duplicate DeprecationWarning emissions.
๐ค Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/praisonai/praisonai/agent.py` around lines 33 - 45, The wrapper-level
DeprecationWarning for cli_backend is duplicating the same warning emitted by
super().__init__; remove the warning block in this wrapper (the if 'model' in
kwargs or 'llm' in kwargs warnings.warn(...) code that references cli_backend
and DeprecationWarning) and simply pass through kwargs (including
allow_legacy_runtime_pin) to super().__init__; alternatively, if you prefer an
explicit suppression approach, set an internal flag in kwargs (e.g.
'_suppress_deprecation_warning'=True) before calling super().__init__ and have
the upstream super().__init__ check that flag to avoid emitting the duplicate
warning โ in either case ensure cli_backend, allow_legacy_runtime_pin, and the
wrapper call to super().__init__ are the touched symbols.
| config_path: Optional[str] = typer.Option(None, "--config", help="Specific config file to fix"), | ||
| ): | ||
| """Fix common configuration issues, including deprecated cli_backend usage.""" | ||
| args = ["fix"] | ||
| if not dry_run: | ||
| args.append("--execute") | ||
| if not backup: | ||
| args.append("--no-backup") | ||
| if config_path: | ||
| args.extend(["--config", config_path]) | ||
| raise typer.Exit(_run_doctor(args)) |
There was a problem hiding this comment.
doctor fix --config is forwarded with a flag the handler does not parse.
Line 359 forwards --config, but DoctorHandler currently consumes config_file from --file. This mismatch can cause the targeted-file path to be ignored or parse-fail in the downstream handler path.
Suggested patch
- if config_path:
- args.extend(["--config", config_path])
+ if config_path:
+ args.extend(["--file", config_path])๐ Committable suggestion
โผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| config_path: Optional[str] = typer.Option(None, "--config", help="Specific config file to fix"), | |
| ): | |
| """Fix common configuration issues, including deprecated cli_backend usage.""" | |
| args = ["fix"] | |
| if not dry_run: | |
| args.append("--execute") | |
| if not backup: | |
| args.append("--no-backup") | |
| if config_path: | |
| args.extend(["--config", config_path]) | |
| raise typer.Exit(_run_doctor(args)) | |
| config_path: Optional[str] = typer.Option(None, "--config", help="Specific config file to fix"), | |
| ): | |
| """Fix common configuration issues, including deprecated cli_backend usage.""" | |
| args = ["fix"] | |
| if not dry_run: | |
| args.append("--execute") | |
| if not backup: | |
| args.append("--no-backup") | |
| if config_path: | |
| args.extend(["--file", config_path]) | |
| raise typer.Exit(_run_doctor(args)) |
๐ค Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/praisonai/praisonai/cli/commands/doctor.py` around lines 350 - 360, The
doctor CLI is forwarding --config but the downstream DoctorHandler expects
--file (config_file), so update the argument construction in the doctor command
(the block building args in src/praisonai/praisonai/cli/commands/doctor.py) to
pass the flag the handler parses: replace args.extend(["--config", config_path])
with args.extend(["--file", config_path]) (or alternatively update DoctorHandler
to accept --config and map it to config_file), ensuring the flag name and the
handler parameter (config_file) match.
| patterns = ["*.yaml", "*.yml", "agents.yaml", "config.yaml"] | ||
| for pattern in patterns: | ||
| yaml_files.extend(glob.glob(pattern)) | ||
|
|
There was a problem hiding this comment.
Deduplicate discovered YAML files before migration.
The pattern list (*.yaml, *.yml, plus specific filenames) can include the same file more than once, leading to duplicate processing and noisy summary counts.
Suggested patch
- patterns = ["*.yaml", "*.yml", "agents.yaml", "config.yaml"]
+ patterns = ["*.yaml", "*.yml", "agents.yaml", "config.yaml"]
for pattern in patterns:
yaml_files.extend(glob.glob(pattern))
+ yaml_files = sorted(set(yaml_files))๐ Committable suggestion
โผ๏ธ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| patterns = ["*.yaml", "*.yml", "agents.yaml", "config.yaml"] | |
| for pattern in patterns: | |
| yaml_files.extend(glob.glob(pattern)) | |
| patterns = ["*.yaml", "*.yml", "agents.yaml", "config.yaml"] | |
| for pattern in patterns: | |
| yaml_files.extend(glob.glob(pattern)) | |
| yaml_files = sorted(set(yaml_files)) |
๐ค Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/praisonai/praisonai/cli/features/doctor/handler.py` around lines 330 -
333, The YAML discovery can add duplicates because patterns = ["*.yaml",
"*.yml", "agents.yaml", "config.yaml"] is iterated and yaml_files is extended
for each match; after the loop, deduplicate yaml_files (preserving order) before
any migration/processing (e.g., replace yaml_files with
list(dict.fromkeys(yaml_files)) or use an OrderedDict/set-based filter) so each
file is processed once; ensure this deduplication occurs after the loop that
builds yaml_files and before any summary/count or migration logic that uses
yaml_files.
| print(f"โ Migrated: {yaml_file}") | ||
| else: | ||
| if not config.quiet: | ||
| print(f" Run with --execute to apply migration") |
There was a problem hiding this comment.
Remove f-string prefixes with no interpolation (Ruff F541).
These two lines are plain constants and should not be f-strings to keep lint clean.
Also applies to: 432-432
๐งฐ Tools
๐ช Ruff (0.15.15)
[error] 378-378: f-string without any placeholders
Remove extraneous f prefix
(F541)
๐ค Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/praisonai/praisonai/cli/features/doctor/handler.py` at line 378, Remove
the unnecessary f-string prefixes on the two plain-string print calls (e.g.,
change print(f" Run with --execute to apply migration") to print(" Run with
--execute to apply migration")); locate the two occurrences by searching for the
exact string " Run with --execute to apply migration" (and the other similar
plain-constant print at the other reported location) and simply drop the leading
f so they are ordinary string literals, keeping all other code unchanged.
Source: Linters/SAST tools
| except Exception as e: | ||
| if not config.quiet: | ||
| print(f"โ Error processing {yaml_file}: {e}") | ||
|
|
||
| if not config.quiet: | ||
| if issues_found == 0: | ||
| print("โ No deprecated cli_backend configurations found.") | ||
| else: | ||
| action = "would be" if not config.execute else "were" | ||
| print(f"๐ Summary: {issues_found} files with deprecated configs, {files_modified} {action} migrated.") | ||
|
|
||
| if not config.execute and issues_found > 0: | ||
| print("\n๐ก To apply migrations, run: praisonai doctor fix --execute") | ||
|
|
||
| return 0 | ||
|
|
There was a problem hiding this comment.
Fix mode reports success even when file processing errors occur.
Line 380-383 records per-file errors, but Line 394 always returns 0. This can make CI/automation treat failed migrations as successful.
Suggested patch
- issues_found = 0
- files_modified = 0
+ issues_found = 0
+ files_modified = 0
+ files_failed = 0
@@
except Exception as e:
+ files_failed += 1
if not config.quiet:
print(f"โ Error processing {yaml_file}: {e}")
@@
- return 0
+ return 1 if files_failed > 0 else 0๐งฐ Tools
๐ช Ruff (0.15.15)
[warning] 380-380: Do not catch blind exception: Exception
(BLE001)
๐ค Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/praisonai/praisonai/cli/features/doctor/handler.py` around lines 380 -
395, The handler currently logs per-file exceptions inside the try/except but
always returns 0, hiding failures; update the function in
src/praisonai/praisonai/cli/features/doctor/handler.py (the CLI "doctor" handler
that uses variables issues_found and files_modified) to track processing errors
(e.g., add an errors_count or had_errors flag initialized before the file loop
and increment/set it inside the except Exception as e block), and then change
the final return logic so the function returns a non-zero exit code (e.g.,
return 1) when any file processing errors were recorded; keep existing summary
prints intact (including the quiet/execute branches) but ensure the return value
reflects errors_found.
|
@claude You are the FINAL architecture reviewer. If the branch is under MervinPraison/PraisonAI (not a fork), you are able to make modifications to this branch and push directly. SCOPE: Focus ONLY on Python packages (praisonaiagents, praisonai). Do NOT modify praisonai-rust or praisonai-ts. Read ALL comments above from Gemini, Qodo, CodeRabbit, and Copilot carefully before responding. Phase 1: Review per AGENTS.md
Phase 2: FIX Valid Issues Phase 3: Final Verdict |
|
Claude finished @MervinPraison's task โโ View job Architecture Review & Bug Fixes โI've conducted a final architecture review and fixed all valid bugs identified by previous reviewers. Todo List:
Architecture Analysis:โ
Protocol-driven design: Correctly places deprecation warnings in both core SDK ( Fixed Issues:
Testing Results:
Final Verdict: โ APPROVEDAll critical issues identified by Greptile, CodeRabbit, Qodo, and Copilot have been resolved. The PR now:
The implementation correctly deprecates agent-level Recommendation: Merge this PR. All blocking issues have been addressed. ๐ Files Modified:
|
- Remove duplicate deprecation warnings between wrapper and core Agent - Fix CLI command reference from 'praisonai doctor --fix' to 'praisonai doctor fix --execute' - Remove unimplemented 'allow_legacy_runtime_pin=True' reference - Fix duplicate file processing in doctor handler by deduplicating yaml_files - Add proper error handling with exit codes in doctor fix command - Remove unused imports and variables in doctor handler - Fix CLI flag mapping from --config to --file for handler compatibility - Remove test fixture from repository root These fixes address all critical bugs identified by previous reviewers. Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
Implements deprecation of agent-level cli_backend and external runtime pins as requested in issue #1942.
Changes Made
Deprecation Warnings
Doctor Migration Tool
Backward Compatibility
Acceptance Criteria Met
Fixes #1942
Summary by CodeRabbit
New Features
praisonai doctor fixcommand to automatically migrate deprecatedcli_backendconfigurations with options for dry-run, execution, backup creation, and custom config paths.Deprecations
cli_backendparameter when used alongside model configuration; users should transition to model-scoped runtime configuration instead.