Skip to content

Implement AI tool execution and validation #143

Description

@apermo

Summary

Implement server-side execution and validation of AI tool calls. The AI proposes actions, the backend validates and executes them safely.

Tool Definitions

update_exercise

Update weight, sets, reps, or rest time.

  • Validate exercise exists
  • Validate reasonable ranges (weight ±20%, reps 1-100, etc.)
  • Log change to audit

skip_exercise

Mark exercise to skip for a date.

  • Create date override
  • Require reason

add_exercise

Add new exercise to a day.

  • Validate day exists
  • Validate exercise type
  • Set sort_order

create_override

Create one-time schedule change.

  • Validate date format
  • Validate override type

get_exercise_history

Read-only: get recent feedback.

  • Return last N feedback entries
  • Used by AI to understand patterns

get_schedule

Read-only: get schedule for date.

  • Used by AI to understand current program

Validation Rules

class ToolValidator {
    public function validateUpdateExercise(array $params): ValidationResult {
        // Weight change max ±20%
        // Sets 1-10
        // Reps 1-100
        // Rest 10-300 seconds
    }
}

Audit Logging

CREATE TABLE ai_actions (
    id INT AUTO_INCREMENT PRIMARY KEY,
    conversation_id VARCHAR(36),
    tool_name VARCHAR(50) NOT NULL,
    params JSON NOT NULL,
    result JSON,
    status ENUM('success', 'rejected', 'error') NOT NULL,
    rejection_reason TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Part of

Phase 2: AI Proxy

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions