Skip to navigation

nemo_gym.agents.context_management

View as MarkdownOpen in Claude

Opt-in context management shared by sequential Responses agents.

Submodules

Package Contents

Classes

NameDescription
ContextGuardRejectedThe next action cannot satisfy the configured guards, even after compaction.
ContextHistoryConfigCapability-gated semantic context-history configuration for a Gym agent.
ContextManagedResponsesClientOne logical rollout. A transport ambiguity is terminal; it is never retried here.

API

class nemo_gym.agents.context_management.ContextGuardRejected()

Bases: RuntimeError

The next action cannot satisfy the configured guards, even after compaction.

class nemo_gym.agents.context_management.ContextHistoryConfig()

Bases: BaseModel

Capability-gated semantic context-history configuration for a Gym agent.

enabled
bool = False
guards
ContextGuardConfig = Field(default_factory=ContextGuardConfig)
max_model_calls
int = Field(default=256, ge=1)
max_response_retries
int = Field(default=0, ge=0)
model_config
= ConfigDict(extra='forbid')
policy
HistoryPolicyConfig = Field(default_factory=HistoryPolicyConfig)
schedule
CompactionScheduleConfig = Field(default_factory=CompactionScheduleConfig)
class nemo_gym.agents.context_management.ContextManagedResponsesClient(
logical_rollout_id: str,
seed_observations: collections.abc.Sequence[typing.Any] = (),
cookies: typing.Any = None
)

One logical rollout. A transport ambiguity is terminal; it is never retried here.

Agents may pass their complete append-only history to create(body) or call append_observation(items) followed by create(). Both use the same history. select_response permits bounded, deliberate resampling of definite responses.

_last_accepted_response_id
str | None = None
_model_calls
= 0
_request
= initial_request.model_copy(deep=True)
_seed_event_count
= len(self.history.events)
_selected_ids
set[str] = set()
_step
= 1
config
= config.model_copy(deep=True)
controller
cookies
= dict(cookies or {})
history
= SemanticHistory(logical_rollout_id)
output_items
list[dict[str, Any]]

Materialize the final conversation once, not a full prefix per action.

nemo_gym.agents.context_management.ContextManagedResponsesClient._accept(
) -> None
nemo_gym.agents.context_management.ContextManagedResponsesClient._append_suffix(
) -> None
nemo_gym.agents.context_management.ContextManagedResponsesClient._check_open() -> None
nemo_gym.agents.context_management.ContextManagedResponsesClient._measure(
async
nemo_gym.agents.context_management.ContextManagedResponsesClient._prepare() -> nemo_gym.agents.context_management.history.PreparedHistoryView
async
nemo_gym.agents.context_management.ContextManagedResponsesClient._semantic_source() -> list[dict[str, typing.Any]]
nemo_gym.agents.context_management.ContextManagedResponsesClient.append_observation(
items: collections.abc.Sequence[typing.Any]
) -> None
nemo_gym.agents.context_management.ContextManagedResponsesClient.create(
select_response: collections.abc.Callable[[NeMoGymResponse], bool | collections.abc.Awaitable[bool]] | None = None
async
nemo_gym.agents.context_management.ContextManagedResponsesClient.finish(
) -> None

Validate the final accepted response and close the policy lifecycle.