smarts.core.agent module

class smarts.core.agent.Agent[source]

The base class for agents


The agent action. See documentation on observations, AgentSpec, and AgentInterface.

Expects an adapted observation and returns an unadapted action.

classmethod from_function(agent_function: Callable)[source]

A utility function to create an agent from a lambda or other callable object.

keep_lane_agent = Agent.from_function(lambda obs: "keep_lane")
class smarts.core.agent.AgentPolicy[source]
class smarts.core.agent.AgentSpec(interface: Optional[smarts.core.agent_interface.AgentInterface] = None, agent_builder: Optional[Callable[[...], smarts.core.agent.Agent]] = None, agent_params: Optional[Any] = None, policy_builder: Optional[Callable[[...], smarts.core.agent.Agent]] = None, policy_params: Optional[Any] = None, observation_adapter: Callable = <function AgentSpec.<lambda>>, action_adapter: Callable = <function AgentSpec.<lambda>>, reward_adapter: Callable = <function AgentSpec.<lambda>>, info_adapter: Callable = <function AgentSpec.<lambda>>, perform_self_test: bool = False)[source]

A configuration that is used by SMARTS environments.

agent_spec = AgentSpec(
    agent_params={"agent_function": lambda _: "keep_lane"},

env = gym.make(
    agent_specs={agent_id: agent_spec},

agent = agent_spec.build_agent()

Refer to the Agent documentation.


An adaptor that allows shaping of the action (default lambda act: act)

agent_builder: Callable[[], smarts.core.agent.Agent] = None

A callable to build an smarts.core.agent.Agent given AgentSpec.agent_params (default None)

agent_params: Optional[Any] = None

Parameters to be given to AgentSpec.agent_builder (default None)


Construct an Agent from the AgentSpec configuration.

info_adapter(reward, info)

An adaptor that allows shaping of info (default lambda obs, reward, info: info)

interface: smarts.core.agent_interface.AgentInterface = None

the adaptor used to wrap agent observation and action flow (default None)


An adaptor that allows shaping of the observations (default lambda obs: obs)

perform_self_test: bool = False

[DEPRECATED] this parameter is not used anymore

policy_builder: Callable[[], smarts.core.agent.Agent] = None

[DEPRECATED] see AgentSpec.agent_builder (default None)

policy_params: Optional[Any] = None

[DEPRECATED] see AgentSpec.agent_params (default None)


Return a copy of this AgentSpec with the given fields updated.


An adaptor that allows shaping of the reward (default lambda obs, reward: reward)