Action Sampler

Action samplers define how an agent selects actions from a large language model.

API Reference

class unstable.collection.action_samplers.BaseActionSampler(agent)

Abstract base class for action samplers. Provides a consistent callable interface over agents implementing either act_full(observation) or a simple callable API agent(observation).

Parameters:

agent (Any) – The agent or policy object used to generate actions.

Methods

sample_action(observation: str) Action

Query the agent for an action given the textual observation.

Parameters:

observation (str) – The environment observation provided to the agent.

MajorityVotingActionSampler

class unstable.collection.action_samplers.MajorityVotingActionSampler(agent, k: int = 10)

Action sampler implementing majority voting over multiple parallel agent invocations.

Parameters:
  • agent (Any) – The language model to sample from.

  • k (int) – Number of parallel samples used for majority voting. Must be a positive integer.

Methods

sample_action(observation: str) Action

Sample \(k\) independent actions from the agent and return the majority-voted result.

Parameters:

observation (str) – The environment observation.

_entropy(counts: Counter) float

Compute Shannon entropy of the empirical vote distribution.

Parameters:

counts (Counter) – Counter of action frequencies.