datawhalechina/hello-agents · error · Exception

When the theorem name contains 'perimeter', 'area', 'similar

Error message

When the theorem name contains 'perimeter', 'area', 'similar' and 'congruent', theorem parameters must be added.

What it means

Raised in the no-parameter branch of apply() when the theorem name (even when not in special_theorem) contains one of the substrings 'perimeter', 'area', 'similar' or 'congruent' and no parameters were given. These theorem families have combinatorially explosive or ambiguous premise matching when auto-instantiated, so the solver requires the caller to bind points explicitly instead of enumerating all instances via GPL.

Source

Thrown at Co-creation-projects/BitSecret-GPSAgent/src/gps/symbolic_solver.py:1331

            fact_id, goal_ids = self._add_conclusion(theorem_gdl, replace, premise_ids, operation_id)
            if fact_id is None:
                return f"定理'{theorem}'所有前提已满足,但添加结论失败。结论可能已经存在,或者结论未通过合法性检查。"

            self._check_goals(goal_ids)

            result = f"定理'{theorem}'执行成功,以下为问题的状态更新。\n"
            return result + self._get_update(old_fact_id, old_goal_id, old_goal_status)

        else:
            if theorem_name in special_theorem:
                msg = f"When using the 'apply' tool with theorem '{theorem_name}', theorem parameters must be added."
                raise Exception(msg)

            if ('perimeter' in theorem_name or 'area' in theorem_name or
                    'similar' in theorem_name or 'congruent' in theorem_name):
                msg = ("When the theorem name contains 'perimeter', 'area', 'similar' and 'congruent', "
                       "theorem parameters must be added.")
                raise Exception(msg)

            all_goal_ids = set()
            theorem_gdl = self.parsed_gdl['Theorems'][theorem_name]
            paras, instances, premise_ids = self._run_gpl(theorem_gdl['premises_gpl'])
            for i in range(len(instances)):
                replace = dict(zip(paras, instances[i]))

                # add operation
                theorem_paras = replace_paras(theorem_gdl['paras'], replace)
                operation_id = self._add_operation(('Apply', theorem_name, theorem_paras))

                # add conclusions
                fact_id, goal_ids = self._add_conclusion(theorem_gdl, replace, premise_ids[i], operation_id)
                all_goal_ids.update(goal_ids)

            self._check_goals(all_goal_ids)

            if len(all_goal_ids) == 0:

View on GitHub (pinned to 606a07d341)

Solutions

  1. Add an explicit parameter list with the correct arity, e.g. apply('similar_triangle(A,B,C,D,E,F)').
  2. Look up the expected parameter count from parsed_gdl['Theorems'][name]['paras'] first.
  3. If auto-instantiation is genuinely needed, pick an equivalent theorem whose name avoids the four substrings.

Example fix

# before
solver.apply('congruent_triangle')

# after
n = len(solver.parsed_gdl['Theorems']['congruent_triangle']['paras'])
solver.apply('congruent_triangle(A,B,C,D,E,F)')
Defensive patterns

Strategy: validation

Validate before calling

NEEDS_PARAMS_SUBSTR = ('perimeter', 'area', 'similar', 'congruent')
def must_bind_explicitly(theorem_name):
    return any(s in theorem_name for s in NEEDS_PARAMS_SUBSTR)

Try / catch

try:
    solver.apply(theorem)
except Exception as e:
    if 'perimeter' in str(e):
        theorem = bind_params_from_gdl(solver, theorem)  # fill arity from parsed_gdl, retry

Prevention

When it happens

Trigger: Calling solver.apply('area_formula') or solver.apply('similar_triangle') bare; any bare apply whose theorem name merely contains one of the four substrings, even as part of a longer word.

Common situations: Agents trying bare invocation because it works for simpler theorems; theorem named e.g. 'compare_areas' accidentally matching the substring check and surprising the caller.

Related errors


AI-assisted analysis of datawhalechina/hello-agents@606a07d341 (2026-08-14). Data as JSON: /api/errors/afee9586eced114e. Report an issue: GitHub.