Skip to content

Reward Design

Reward design is the stage that turns task intent, environment information, and scout context into runnable Python reward functions. It follows a generate, evaluate, and evolve loop inspired by LLM-driven reward search.

Reward design uses:

InputSource
Task description and success criteriaTaskSpec
Environment matchEnvMatch and EnvEntry
Observation and action infoinspect_env stage
Literature contextscout stage, unless skipped
Training feedbackPrevious evaluation iteration, if retrying

Generated reward functions must expose a callable that accepts the previous observation, action, next observation, and info dictionary.

import numpy as np
def compute_reward(obs, action, next_obs, info):
forward_velocity = float(next_obs[8]) if len(next_obs) > 8 else 0.0
action_penalty = 0.01 * float(np.square(action).sum())
reward = forward_velocity - action_penalty
components = {
"forward_velocity": forward_velocity,
"action_penalty": -action_penalty,
}
return reward, components

The return value is a tuple:

ValueMeaning
rewardFloat used by the training backend.
componentsDict of named reward terms for debugging.

ForgeRewardWrapper replaces the environment reward with the custom reward and keeps the original reward in info.

import gymnasium as gym
from robosmith.envs.reward_wrapper import ForgeRewardWrapper
env = gym.make("Ant-v5")
env = ForgeRewardWrapper(env, compute_reward, reward_clip=100.0)

On every step(), the wrapper adds:

Info keyMeaning
custom_rewardClipped custom reward used for training.
reward_componentsComponent dict from the reward function.
original_rewardEnvironment reward before replacement.

The wrapper is defensive because generated reward functions are untrusted:

CaseBehavior
Reward is non-finiteClamp reward to 0.0 and record an error component.
Reward function raisesUse 0.0 reward and put the exception string in components.
Reward magnitude is largeClip to [-reward_clip, reward_clip].
Dict observationsFlatten and concatenate values before passing to reward code.

RewardSearchConfig controls reward generation and short candidate evaluation.

reward_search:
candidates_per_iteration: 4
num_iterations: 3
eval_timesteps: 50000
eval_time_minutes: 2.0

CLI override:

Terminal window
robosmith run --task "..." --candidates 6

When evaluation routes back to reward design, the next pass receives a training reflection. The reflection is meant to explain whether the previous run stalled, collapsed, learned the wrong behavior, or needs a different reward emphasis.

This keeps the loop from behaving like repeated first attempts.

AreaModule
Reward design stagerobosmith.stages.reward_design.reward_design
Reward agentrobosmith.agent.models.reward.agent
Reward typesrobosmith.agent.models.reward.types
Reward wrapperrobosmith.envs.reward_wrapper
Pipeline noderobosmith.agent.graphs.run.design