Skill: Calculate para IA
Publicado por Andrés López

Los LLMs no son fiables con operaciones numéricas. Una skill puede indicarle al agente cuándo y cómo calcular con precisión en lugar de adivinar resultados.
Título
calculate
Descripción
Performs exact arithmetic and advanced numeric operations by executing Python. Use when the agent needs sums, subtractions, multiplications, divisions, percentages, exponents, statistics, financial math, or any numeric result where rounding errors matter — never do mental math even in simple operations.
Skill
# Calculate
## Core rule
**Never compute numbers mentally or approximate.** Always run Python and use only the value printed to stdout.
## When to use
Apply this skill whenever a response depends on a numeric result:
- Basic arithmetic: `+`, `-`, `*`, `/`, `%`, powers
- Percentages, ratios, averages, running totals
- Multi-step expressions with parentheses
- Advanced math: roots, logarithms, trigonometry, factorials
- Statistics: mean, median, standard deviation
- Financial precision: currency, tax, interest
- Any calculation where a rounding error would mislead the user
## Workflow
1. Identify the expression or algorithm needed
2. Run it with `python3 -c '...'` (single line) or a heredoc (multiple lines)
3. Use **only** the value printed to stdout as the result
4. If execution fails, fix the script and retry — do not estimate
## Execution patterns
### Single expression
```bash
python3 -c "print(1234 * 56.78)"
```
### Multiple lines / variables
```bash
python3 <<'PY'
principal = 10000
rate = 0.05
years = 3
print(principal * (1 + rate) ** years)
PY
```
### Decimal precision (money)
```bash
python3 -c "from decimal import Decimal as D; print(D('19.99') * D('3'))"
```
### Statistics
```bash
python3 -c "import statistics as s; print(s.mean([10, 20, 30]))"
```
### Rounding (only at the end, in Python)
```bash
python3 -c "print(round(100 / 3, 2))"
```
## Allowed libraries
Use Python stdlib only — no pip dependencies:
| Module | Use for |
|--------|---------|
| `math` | sqrt, log, trig, factorial, ceil, floor |
| `decimal` | Fixed-precision decimal arithmetic |
| `fractions` | Exact rational numbers |
| `statistics` | mean, median, stdev, variance |
| `cmath` | Complex numbers |
## Multi-step calculations
Print intermediate steps when the user needs to follow the logic:
```bash
python3 <<'PY'
items = [19.99, 4.50, 12.00]
subtotal = sum(items)
tax = subtotal * 0.08
total = subtotal + tax
print(f"subtotal={subtotal}")
print(f"tax={tax}")
print(f"total={total}")
PY
```
## Presenting results
In your response:
1. State the problem in plain language
2. Show the verified result from Python
3. Include intermediate steps only when they add clarity
4. Never round in prose without having rounded in Python first
**Example response:**
> The invoice total is $19.99 + $4.50 + $12.00 = $36.49. With 8% tax ($2.92), the final total is **$39.41**.
## Examples
| Scenario | Command | Result |
|----------|---------|--------|
| Invoice sum | `python3 -c "print(19.99 + 4.50 + 12.00)"` | 36.49 |
| 15% of 2500 | `python3 -c "print(2500 * 0.15)"` | 375.0 |
| Average | `python3 -c "import statistics; print(statistics.mean([12, 18, 24]))"` | 18 |
| Compound interest | heredoc with `principal`, `rate`, `years` | computed |
## Anti-patterns
- Do not do arithmetic in your head or "work it out" without Python
- Do not use `bc`, `node -e`, or other tools unless `python3` is unavailable
- Do not round manually in text without explicit `round()` in the script
- Do not guess when a script fails — fix and re-run
## Fallback
If `python3` is not available, tell the user and ask before using another method.
Si eres desarrollador puedes agregar fácilmente esta skill mediante npx:
npx skills add andreslqr/agents --skill calculate

Andrés López
Gran fan de Laravel, entusiasta de Vue y escritor de cualquier cosa que suene interesante