feat: ✨ Add calculator tool for mathematical operations#51
Merged
TheRockPusher merged 4 commits intomainfrom Dec 4, 2025
Merged
feat: ✨ Add calculator tool for mathematical operations#51TheRockPusher merged 4 commits intomainfrom
TheRockPusher merged 4 commits intomainfrom
Conversation
- Generated autonomous plan with deep codebase analysis - Documented all assumptions and design decisions - 18 comprehensive test cases designed - Ready for remote implementation via /github:implement-remote Confidence: 9/10 - Fully autonomous with minimal ambiguity
- Add calculator_tool function with simpleeval for safe expression evaluation - Support basic operations: +, -, *, /, **, % with proper PEMDAS - Implement comprehensive error handling with ModelRetry for LLM recovery - Format floats to 4 decimal places, integers without decimals - Register tool in task_management agent TASK_TOOLS list - Add 18 comprehensive test cases covering all operations and edge cases - Add simpleeval>=1.0.0 dependency to pyproject.toml Implements GitHub Issue #50 Follows implementation plan in .agents/plans/add-calculator-tool-for-agents.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
5 tasks
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
## P1 Fixes ### 1. Update uv.lock for simpleeval dependency - Regenerated uv.lock to include simpleeval v1.0.3 - Fixes CI/CD pipeline failures with `uv lock --locked` - Ensures simpleeval is properly installed in production ### 2. Catch simpleeval-specific exceptions - Import InvalidExpression base class from simpleeval - Catch InvalidExpression (NameNotDefined, FunctionNotDefined, etc.) - Previously: Variables like "x + 5" and functions like "print(5)" bubbled up as uncaught exceptions - Now: All simpleeval errors properly converted to ModelRetry for LLM self-correction ### 3. Fix test for invalid syntax - Changed test expression from "2 + + 2" to "2 + * 2" - Reason: Python interprets "+ +" as unary plus (valid: 2 + (+2) = 4) - New expression "2 + * 2" properly tests syntax error handling ### 4. Update test expectations - Updated test_task_agent_has_14_tools (was 13, now 14 with calculator_tool) - Added calculator_tool assertion to tool list completeness test ## Test Results ✅ All 93 agent tests passing ✅ 21 calculator tool tests passing ✅ No regressions in existing functionality ## Files Changed - uv.lock: +11 lines (simpleeval v1.0.3 entry) - src/taskweaver/agents/tools.py: +8 lines (InvalidExpression handling) - src/taskweaver/agents/tests/test_calculator_tool.py: 1 change (fix test) - src/taskweaver/agents/tests/test_task_management.py: +9 lines (update counts) Addresses code review feedback on PR #51 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Owner
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements GitHub Issue #50: Add calculator tool to agents for mathematical operations
Enables agents to perform safe mathematical calculations for:
Implementation
simpleeval(AST-based, no code execution possible)Files Changed
pyproject.toml: Added simpleeval>=1.0.0 dependencysrc/taskweaver/agents/tools.py: Implemented calculator_tool function (81 lines)src/taskweaver/agents/task_management.py: Registered tool in TASK_TOOLSsrc/taskweaver/agents/tests/test_calculator_tool.py: 21 comprehensive test cases (195 lines)Total: 281 lines added across 4 files
Testing
Test Coverage (21 test cases)
Basic Operations (6 tests):
Complex Expressions (4 tests):
(92*0.35) + (78*0.30) + (88*0.35)2 + 3 * 4= 14 (not 20)(2 + 3) * 4= 20((10 - 5) * 2) + 3= 13Edge Cases (5 tests):
10 / 3= 3.33331000000 * 1000= 10000000003.5 * 2.5= 8.7500Error Handling (6 tests):
Test Execution
# All tests designed to pass - CI will validate pytest src/taskweaver/agents/tests/test_calculator_tool.py -vValidation Checklist
Documentation
Security Considerations
✅ AST-Based Evaluation:
simpleevaluses AST whitelisting (secure by design)✅ No Code Execution: Variables, functions, and imports are blocked
✅ Input Validation: Empty expressions rejected before evaluation
✅ Comprehensive Error Handling: All exception types caught and converted to ModelRetry
Autonomous Implementation
All design decisions were made based on:
Related
🤖 Generated with Claude Code