fix: dedupe tool schema build in tools/base.py#3128
Conversation
Extract shared _extract_schema helper and let validate_tool_schema_consistency optionally return built schemas so get_sorted_tool_schemas reuses them instead of rebuilding every tool schema a second time. No behaviour change. 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.
|
📝 WalkthroughWalkthroughTool schema extraction is centralized in ChangesTool schema reuse
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
Greptile SummaryThis PR removes duplicate tool-schema construction in the shared tools module. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (1): Last reviewed commit: "fix: dedupe tool schema build in tools/b..." | Re-trigger Greptile |
|
@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 Final Architecture Review — PR #3128
Phase 1 — Architecture Review
Phase 2 — IssuesReviewer verdicts: Greptile 5/5 safe to merge, CodeRabbit still processing, Qodo paused. No blocking issues raised. Independent findings:
No code changes required — the fix is already minimal, correct, and complete. Phase 3 — TestsVerdict: ✅ ApproveClean, lightweight de-duplication with a measurable hot-path win and zero behavior/API regression. Recommend merge. |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/praisonai-agents/praisonaiagents/tools/base.py (1)
445-445: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueReplace
getattrwith direct attribute access.As indicated by static analysis tools, calling
getattrwith a constant attribute name is redundant and an anti-pattern. You can safely use direct property access here sincehasattralready confirms the attribute exists.♻️ Proposed refactor
- elif hasattr(tool, 'get_schema') and callable(getattr(tool, 'get_schema')): + elif hasattr(tool, 'get_schema') and callable(tool.get_schema):🤖 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/tools/base.py` at line 445, Update the get_schema capability check to use direct attribute access in the callable test instead of getattr, while retaining the existing hasattr guard and conditional behavior.Source: Linters/SAST tools
🤖 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.
Nitpick comments:
In `@src/praisonai-agents/praisonaiagents/tools/base.py`:
- Line 445: Update the get_schema capability check to use direct attribute
access in the callable test instead of getattr, while retaining the existing
hasattr guard and conditional behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2a5c46d7-093d-4c9b-b83b-1ea6cf35b39e
📒 Files selected for processing (1)
src/praisonai-agents/praisonaiagents/tools/base.py
Fixes #3125
Summary
get_sorted_tool_schemas()previously built every tool's schema twice per call: once insidevalidate_tool_schema_consistency()(which discarded them) and again in its own loop for sorting. The tool-shape schema-extraction block was also duplicated verbatim across both functions.Changes
_extract_schema(tool) -> Optional[dict]helper that resolves a schema from all supported tool shapes (BaseTool, objects withget_schema, plain callables).validate_tool_schema_consistency()now acceptsreturn_schemas=False; whenTrueit returns the schemas it already built.get_sorted_tool_schemas()now validates once and sorts the returned schemas instead of rebuilding them.Behaviour preserved
ToolValidationErroron the same inputs.return_schemasdefaults toFalse).Validation
tests/unit/context/test_cache_optimization.py— 3 passed.return_schemas, sort order, and empty-list handling.Generated with Claude Code
Summary by CodeRabbit