oumi.environments#
Environments for agentic tool interactions.
Importing this package populates the environment registry by triggering each concrete environment’s @register_environment(…) decorator.
- class oumi.environments.BaseEnvironment[source]#
Bases:
ABCAbstract base class for tool environments.
- describe_grounding(facts: list[GroundingFact]) str[source]#
Render grounding facts as a bulleted markdown block.
- sample_grounding(n: int, *, rng: Random, tool_ids: set[str] | None = None) list[GroundingFact][source]#
Sample grounding facts from this environment. Default:
[].
- abstractmethod step(calls: list[tuple[str, dict[str, Any]]]) list[ToolResult][source]#
Execute a batch of tool calls; returns results in the same order.
- tool_params_cls#
alias of
ToolParams
- class oumi.environments.DeterministicEnvironment(params: EnvironmentParams, kwargs: DeterministicEnvironmentKwargs)[source]#
Bases:
BaseEnvironmentEnvironment that resolves tools from a per-tool lookup table.
The env’s
env_kwargs.lookup_tableis the source of truth for tool behavior. Tools listed inparams.toolsdeclare contracts only; their data lives on the env.- classmethod from_params(params: EnvironmentParams) DeterministicEnvironment[source]#
Build a DeterministicEnvironment from its params object.
- sample_grounding(n: int, *, rng: Random, tool_ids: set[str] | None = None) list[GroundingFact][source]#
Sample grounding facts from per-tool projected pools.
Walks every tool that has a per-tool entry in
params.grounding.tools. Each entry in that tool’s lookup table is projected via{**input, **output}filtered through the configuredfieldswhitelist. Tools without a grounding entry contribute nothing.
- step(calls: list[tuple[str, dict[str, Any]]]) list[ToolResult][source]#
Resolve a batch of deterministic tool calls to their outputs.
- Raises:
ValueError – If any
tool_idis not declared in this env’s tools list.ToolLookupError – If no entry in the env’s lookup table matches the provided arguments for any call.
- tool_params_cls#
alias of
ToolParams
- class oumi.environments.DeterministicEnvironmentKwargs(lookup_table: dict[str, list[~oumi.environments.deterministic_environment.ToolLookupEntry]]=<factory>)[source]#
Bases:
BaseParamsType-specific kwargs for DeterministicEnvironment.
- lookup_table: dict[str, list[ToolLookupEntry]]#
Per-tool list of (input, output) entries, keyed by tool id.
- class oumi.environments.GroundingConfig(sample_size: int = 3, seed: int | None = None, tools: dict[str, ~oumi.core.configs.params.grounding_params.ToolGroundingConfig]=<factory>)[source]#
Bases:
BaseParamsPer-environment grounding configuration.
- sample_size: int = 3#
Number of grounding facts sampled per conversation.
- seed: int | None = None#
Optional seed for reproducible grounding sampling.
- tools: dict[str, ToolGroundingConfig]#
Per-tool field whitelists, keyed by tool id.
- class oumi.environments.GroundingFact(data: dict[str, ~typing.Any]=<factory>)[source]#
Bases:
BaseParamsEnv-agnostic representation of a single grounding fact.
Environments produce these during sampling; the planner prompt renders each fact’s
datadict as one bullet line. Values are expected to be JSON-serializable scalars.- data: dict[str, Any]#
- class oumi.environments.JSONSchema(*, type: Literal['object', 'string', 'number', 'integer', 'boolean', 'array', 'null'] | list[Literal['object', 'string', 'number', 'integer', 'boolean', 'array', 'null']] | None = None, description: str | None = None, title: str | None = None, properties: dict[str, JSONSchema] | None = None, required: list[str] | None = None, items: JSONSchema | None = None, enum: list[Any] | None = None, default: Any = None, format: str | None = None, **extra_data: Any)[source]#
Bases:
BaseModelA JSON Schema object describing the shape of a value.
Models the subset of JSON Schema commonly used in LLM tool definitions.
extra="allow"lets less-common keywords ($ref,$defs,additionalProperties,anyOf, numeric constraints, etc.) round-trip unchanged, matching the rest of this module — see the module docstring for why round-tripping matters.- default: Any#
Default value used when the field is omitted.
- description: str | None#
Human-readable description, used by the model to choose values.
- enum: list[Any] | None#
Restricts the value to a fixed set of allowed values.
- format: str | None#
Semantic format hint (e.g.,
"date-time","email").
- items: JSONSchema | None#
schema for array elements.
- Type:
For
type="array"
- model_config = {'extra': 'allow', 'frozen': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- properties: dict[str, JSONSchema] | None#
schema for each named property.
- Type:
For
type="object"
- required: list[str] | None#
names of properties that must be present.
- Type:
For
type="object"
- title: str | None#
Short human-readable label.
- type: Literal['object', 'string', 'number', 'integer', 'boolean', 'array', 'null'] | list[Literal['object', 'string', 'number', 'integer', 'boolean', 'array', 'null']] | None#
JSON type(s) of this value. A list expresses a union (e.g.,
["string", "null"]for a nullable string).
- class oumi.environments.SyntheticEnvironment(params: EnvironmentParams, kwargs: SyntheticEnvironmentKwargs)[source]#
Bases:
BaseEnvironmentLLM-simulated environment with optional mutable state.
- attach_inference(engine: BaseInferenceEngine, base_config: InferenceConfig) None[source]#
Inject the orchestrator’s inference engine + base config.
- property current_state: dict[str, Any] | None#
Return the current in-memory state snapshot.
- classmethod from_params(params: EnvironmentParams) SyntheticEnvironment[source]#
Build a SyntheticEnvironment from its params object.
- step(calls: list[tuple[str, dict[str, Any]]]) list[ToolResult][source]#
Execute synthetic tool calls. Cache-misses batched per tool_id.
- Raises:
RuntimeError – If
attach_inferencewas not called.ValueError – If any tool id is unknown.
ToolError – On simulator parse failure or output_schema mismatch.
- class oumi.environments.SyntheticEnvironmentKwargs(system_prompt: str = '', state_params: SyntheticStateParams | None = None, cache_by_input: bool = True)[source]#
Bases:
BaseParamsType-specific kwargs for SyntheticEnvironment.
- cache_by_input: bool = True#
- state_params: SyntheticStateParams | None = None#
- system_prompt: str = ''#
- class oumi.environments.SyntheticStateParams(state_schema: dict[str, Any] | None = None, initial_state: dict[str, Any] | None = None)[source]#
Bases:
BaseParamsOptional state configuration for a synthetic environment.
- initial_state: dict[str, Any] | None = None#
- state_schema: dict[str, Any] | None = None#
- exception oumi.environments.ToolArgumentError[source]#
Bases:
ToolErrorRaised when tool-call arguments fail schema validation.
- exception oumi.environments.ToolError[source]#
Bases:
ExceptionBase class for tool errors surfaced back to the LLM.
Subclasses of this exception are caught by the tool-call loop and re-emitted as structured
toolmessages so the model can self-correct on the next iteration.
- class oumi.environments.ToolGroundingConfig(fields: list[str])[source]#
Bases:
BaseParamsPer-tool field whitelist for grounding projection.
Tools listed in
GroundingConfig.toolsare projected throughfieldswhen the env samples grounding facts. Tools not listed contribute nothing.- fields: list[str]#
- class oumi.environments.ToolLookupEntry(input: dict[str, ~typing.Any]=<factory>, output: dict[str, ~typing.Any]=<factory>)[source]#
Bases:
BaseParamsOne (input, output) pair in a deterministic env’s lookup table.
- input: dict[str, Any]#
- output: dict[str, Any]#
- exception oumi.environments.ToolLookupError[source]#
Bases:
ToolErrorRaised when a tool cannot resolve an output for the given arguments.
Currently used by
DeterministicEnvironmentwhen no configuredLookupEntrymatches the provided arguments.
- class oumi.environments.ToolParams(id: str, name: str, description: str, parameters: dict[str, ~typing.Any]=<factory>, output_schema: dict[str, ~typing.Any] | None=None, read_only: bool = True)[source]#
Bases:
BaseParamsTool schema owned by an environment.
parametersandoutput_schemaare stored as plain JSON-Schema dicts so OmegaConf can carry them through YAML round-trips. They are converted to a PydanticJSONSchemaonly at the wire-format boundary into_tool_definition().- __post_init__()[source]#
Validate common tool fields.
Accepts
JSONSchemainstances onparameters/output_schemafor callers that build a tool with Pydantic types directly; converts them to dicts so the canonical in-memory shape stays JSON-Schema-shaped.
- classmethod create(raw: Any) ToolParams[source]#
Create a tool from raw config data.
- description: str#
- id: str#
- name: str#
- output_schema: dict[str, Any] | None = None#
- parameters: dict[str, Any]#
- read_only: bool = True#
- to_llm_schema() dict[str, Any][source]#
Export a provider-agnostic schema for LLM tool registration.
- to_tool_definition() ToolDefinition[source]#
Project to OpenAI-wire-format
ToolDefinition.Drops chain-internal fields (
output_schema,read_only,namedisplay label) that have no slot in the OpenAI contract. CoercesparameterstoJSONSchemaat the boundary.
- validate_arguments(arguments: dict[str, Any]) None[source]#
Validate call-time arguments against this tool’s
parametersschema.- Raises:
ToolArgumentError – If
argumentsdo not conform.
- class oumi.environments.ToolResult(output: str | dict[str, Any], updated_state: dict[str, Any] | None = None)[source]#
Bases:
objectResult returned by an environment
step().Runtime value (not an OpenAI wire-format type) — projected by the synthesizer into
Message(role=TOOL, content=...)before output.outputmay be a string or a JSON-serializable dict; the synthesizer json-encodes dicts at the message boundary.- output: str | dict[str, Any]#
- updated_state: dict[str, Any] | None = None#