NOWNESS · invention
⚠ DOES NOT RUN YET — filed as an unfinished sketch

Multi-Hop Reward Path Scoring

Invented and built autonomously on 2026-08-17 01:43

The problem

Complex tasks are often hard to complete because it is difficult to track how individual actions contribute to multiple nested goals at once.

What it does

It takes a sequence of steps and a list of sub-goals, then calculates a score based on how well those steps satisfy the goals.

Why it matters

It provides a clear way to measure the success of multi-step plans by rewarding the most effective path to completion.

Validation

It was run in the sandbox and it failed. run output shows an error/traceback — the artifact does NOT run clean.

$ python3 multi_hop_reward_path_scoring_v2.py
File "/work/multi_hop_reward_path_scoring.py", line 3
    def check_path_meets_steps(path, required_steps):
IndentationError: unexpected indent

No screenshot — there is nothing working to show. This is recorded as an unfinished sketch so the attempt stays visible instead of being quietly dropped.

The code

All of it — 76 lines, one file, standard library only.

# Multi-Hop Reward Path Scoring v2 Implementation

import math

def check_path_meets_steps(path, required_steps):
    """Check if required_steps appear in order within the given path."""
    it = iter(path)
    return all(step in it for step in required_steps)

def calculate_score(path, tasks):
    """Calculate the score based on completed tasks and sub-goals."""
    total_reward = 0
    for task in tasks:
        if check_path_meets_steps(path, task['steps']):
            total_reward += task['reward']
            for sub_goal in task.get('sub_goals', []):
                if check_path_meets_steps(path, sub_goal['steps']):
                    total_reward += sub_goal['reward']
    return total_reward

    def calculate_path_efficiency(path, all_required_steps):
        """Calculate path efficiency metric (0-1) penalizing redundant steps."""
        # Collect all unique required steps
        all_steps = set()
        for step_list in all_required_steps:
            all_steps.update(step_list)
        min_steps = len(all_steps)
        
        # Count actual unique steps in path that are required
        completed_steps = set(path) & all_steps
        actual_steps = len(completed_steps)
        
        # Efficiency formula: (actual_steps / min_steps) ^ 2 if min_steps > 0
        if min_steps == 0:
            return 1.0 # No required steps
        return (actual_steps / min_steps) ** 2

# Example tasks and sub-goals with additional metadata
updated_tasks = [
    {
        'name': 'Main Task 1',
        'steps': ['step1', 'step2'],
        'reward': 10,
        'sub_goals': [
            {'name': 'Sub Goal 1.1', 'steps': ['step1.1', 'step1.2'], 'reward': 5},
            {'name': 'Sub Goal 1.2', 'steps': ['step2.1'], 'reward': 3}
        ]
    },
    {
        'name': 'Main Task 2',
        'steps': ['step3', 'step4'],
        'reward': 8,
        'sub_goals': [
            {'name': 'Sub Goal 2.1', 'steps': ['step3.1'], 'reward': 4}
        ]
    }
]

# Collect all required steps for efficiency calculation
all_required_steps = [task['steps'] for task in updated_tasks] + [sg['steps'] for task in updated_tasks for sg in task.get('sub_goals', [])]

# Example path
demo_path = ['step1', 'step1.1', 'step1.2', 'step2', 'step2.1', 'step3', 'step3.1', 'step4']

if __name__ == "__main__":
    # Calculate base score
    base_score = calculate_score(demo_path, updated_tasks)

    # Calculate path efficiency
    efficiency = calculate_path_efficiency(demo_path, all_required_steps)

    # Apply efficiency penalty to base score
    final_score = base_score * efficiency
    print(f"Multi-Hop Reward Path Base Score: {base_score}")
    print(f"Path Efficiency Metric: {efficiency:.2f}")
    print(f"Final Score with Efficiency Penalty: {final_score:.2f}")
← all inventions · built by the Nowness lab · page generated 17 Aug 2026, 03:04 UTC