Skip to content

Collector

Search from a prompt and prepare training data. A Collector combines an agent, a critic, a search strategy, and an actor recipe; collect() returns a Batch of actor and critic samples.

Search from a prompt and prepare training data. A collector combines an agent, a critic, a search strategy, and an actor recipe. collect() returns a Batch; search() and prepare() split the two stages when you want the tree.

from focus import Collector, Critic, Selective

collector = Collector(
    agent,
    critic=Critic.constant(0.5),
    search=Selective(budget=32, warmup=16),
)
async with collector:
    batch = await collector.collect("Solve 3x + 7 = 22.")
records = batch.to_records(0)

The search has a 16-transition warm-up followed by a 32-transition selective phase. The constant critic gives every state the same starting prediction. Preparation computes direct-branch backups and refined values; DirectBranchTd uses those values for actor advantages. Critic targets come from the backups and stay the same when you change the actor recipe. Leaving the async with block closes the agent’s execution services. The caller owns policy clients and critics, which can be shared across collectors.

Definition

class Collector
def __init__(self, agent: Agent[Any, Any], *, search: Search, critic: Critic | None=None, estimator: Estimator | None=DirectBranchTd(), reward: RewardConfig | None=None, own: bool=True) -> None
async def __aenter__(self) -> Collector
async def __aexit__(self, *exc: object) -> None
async def aclose(self) -> None

Close the agent’s execution services.

async def collect(self, prompt: str | AnyRollout, *, workspace: Workspace | None=None) -> Batch

Search from prompt and prepare a Batch with the collector’s estimator. Pass a workspace for task-local state, or an existing rollout checkpoint as prompt. Inspect batch.stats and batch.failures before training: a partial collection still returns its successful records.

def prepare(self, tree: Tree[AnyRollout], *, estimator: Estimator | EllipsisType | None=...) -> Batch

Prepare a Batch from a searched tree. Pass estimator= to apply another recipe to the same evidence, or estimator=None for critic targets only.

async def search(self, prompt: str | AnyRollout, *, workspace: Workspace | None=None) -> Tree[AnyRollout]

Search from prompt and return the tree. When a critic is supplied, score new checkpoints before ranking them.

The searched rollout tree: every checkpoint, its children, its critic prediction, and the collection statistics. Collector.search() returns it and Collector.prepare() reads it.

from focus import Tree

Definition

Tree = SchedulerState