Inference¶
HTTP client for deployed Arena inference endpoints. Deployment metadata is
fetched on construction (unless probe_on_init=False) and exposed as
metadata (StatusResponse).
Use get_action() (RL),
predict() (supervised), or
generate() /
generate_stream() (LLM). Errors raise
ArenaInferenceError.
RL and supervised requests use base64 .npy serialization via
agilerl.arena.inference.serde. LLM requests use plain JSON with
LLMParams.
Every request carries your own Arena credential, a profile personal access token
(arena_pat_...) or an access token from
login(). A deployment that keeps memory per
user works out who is calling from it, so there is nothing extra to pass.
open_inference_agent() fills the credential
in from the client. Building an Agent directly
reads ARENA_API_KEY when you pass no api_key. The credential is never
logged, shown in repr(), or written to disk.
Pass session_id to generate() or
generate_stream() to continue an earlier
chat, and use list_sessions() and
get_session() to find one. Sessions come
back most recently updated first. Leaving session_id out sends no session
field, so the deployment starts a new conversation; no id is minted here. The
CLI does mint one, which is how it continues a conversation across commands.
delete_session() removes a conversation and
its messages from the deployment. It reports whether there was anything to
delete rather than raising, since a session that is already gone and one that
belongs to someone else answer the same way.
Which sessions you can see, and which you can delete, depends on the
deployment’s memory scope, set with memory_scope on
deploy_agent().
CLI: arena agent run <deployment> then arena agent generate --prompt '...'
(uses generate_stream; pass a deployment name to generate to override).
Add --session-id to continue a chat. arena agent sessions list and
arena agent sessions get <session-id> show what is stored. Prompts continue
one conversation by default, so the id need not be repeated;
arena agent sessions resume switches to an older one,
arena agent sessions clear starts a new one on the next prompt, and
arena agent sessions delete <session-id> removes one from the deployment.
- class agilerl.arena.inference.LLMParams(*, max_new_tokens: int = 100, temperature: float = 0.7, top_p: float = 0.9, do_sample: bool = True)¶
LLM sampling parameters model.
- Parameters:
- model_config: ClassVar[ConfigDict] = {'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agilerl.arena.inference.StatusResponse(*, success: bool = True, deployment_id: str = '', instance_id: str = '', agent: AgentInfo | None = None)¶
Status response model.
GET /statusis public, so it reports little beyond the deployment id. Fields a deployment leaves out stay at their defaults, and agent isNonewhen it does not describe its shape at all.- Parameters:
- model_config: ClassVar[ConfigDict] = {'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agilerl.arena.inference.PredictResult(*, batch_size: int, inference_time_ms: float, success: bool = True)¶
Metadata from
POST /predict(excluding deserialized tensors).- Parameters:
- model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agilerl.arena.inference.LLMCompletionResult(*, prompt: str = '', completion: str = '')¶
Single prompt/completion pair from
POST /generate.- Parameters:
- model_config: ClassVar[ConfigDict] = {'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agilerl.arena.inference.LLMResults(*, results: list[LLMCompletionResult], batch_size: int, inference_time_ms: float, tokens_per_second: float, success: bool = True)¶
LLM completion response model.
- Parameters:
results (list[LLMCompletionResult]) – The results of the LLM completions.
batch_size (int) – The batch size of the LLM completions.
inference_time_ms (float) – The inference time in milliseconds.
tokens_per_second (float) – The tokens per second of the LLM completions.
success (bool) – Whether the LLM completions were successful.
- model_config: ClassVar[ConfigDict] = {'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agilerl.arena.inference.SessionInfo(*, session_id: str = '', created_at: str | None = None, last_updated: str | None = None)¶
One chat session summary from
GET /sessions.- Parameters:
- model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agilerl.arena.inference.SessionMessage(*, role: str = '', content: str = '')¶
One message in a chat session.
- model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agilerl.arena.inference.SessionDetail(*, session_id: str = '', created_at: str | None = None, last_updated: str | None = None, messages: list[~agilerl.arena.inference.agent.SessionMessage] = <factory>)¶
A
SessionInfoplus its messages, fromGET /sessions/{session_id}.- Parameters:
messages (list[SessionMessage]) – The messages in the session.
- model_config: ClassVar[ConfigDict] = {'extra': 'ignore', 'frozen': True}¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class agilerl.arena.inference.Agent(endpoint: str, *, api_key: str | None = None, org_key: str | None = None, external_user_id: str | None = None, timeout: int = 30, generate_params: LLMParams | None = None, probe_on_init: bool = True)¶
HTTP client for a deployed Arena inference endpoint.
When probe_on_init is
True(default),status()runs once at construction and storesmetadata. Wrong endpoint for the deployment type returns HTTP 400 from the server.Every request carries your own Arena credential as
Authorization: Bearer. A deployment that keeps memory per user works out who is calling from it, so there is nothing else to pass. Organisation-key clients also sendX-External-User-Id. The credential is never logged, shown inrepr(), or written to disk.- Parameters:
endpoint (str) – Base URL of the Arena inference deployment.
api_key (str | None) – Profile PAT (
arena_pat_<uuid>_<secret>) or an access token fromlogin(). Falls back to theARENA_API_KEYenvironment variable.org_key (str | None) – Organisation API key (
arena_org_…). Requires external_user_id. Falls back toARENA_ORG_KEY.external_user_id (str | None) – Partner user id sent as
X-External-User-Id. Requires org_key. Falls back toARENA_EXTERNAL_USER_ID.timeout (int) – Request timeout in seconds.
generate_params (LLMParams | None) – Default LLM sampling parameters; defaults to
LLMParamswhenNone.probe_on_init (bool) – If
True, fetchGET /statusduring__init__.
- delete_session(session_id: str) bool¶
Delete a chat session and every turn the deployment stored for it.
Deleting is idempotent: a session that is already gone, or that belongs to someone else under the deployment’s memory scope, answers the same way, so this reports whether there was anything to delete rather than raising.
- generate(prompts: str | list[str], *, params: LLMParams | dict[str, Any] | None = None, session_id: str | None = None) LLMResults¶
Generate LLM completions.
- Parameters:
params (LLMParams | dict[str, Any] | None) – The parameters to the agent.
session_id (str | None) – Chat session to continue, as listed by
list_sessions(). When omitted the field is left out of the request and the deployment starts a new conversation; no session id is minted here.
- Returns:
The LLM results.
- Return type:
- generate_stream(prompt: str, *, params: LLMParams | dict[str, Any] | None = None, session_id: str | None = None) Iterator[str]¶
Stream generated tokens for a single prompt.
- Parameters:
prompt (str) – The prompt to the agent.
params (LLMParams | dict[str, Any] | None) – The parameters to the agent.
session_id (str | None) – Chat session to continue, as listed by
list_sessions(). When omitted the field is left out of the request and the deployment starts a new conversation; no session id is minted here.
- Returns:
An iterator of strings.
- Return type:
Iterator[str]
- get_action(observation: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | dict[str, RLData] | tuple[RLData, ...] | None, *, batched: bool = False, hidden_state: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | dict[str, RLData] | tuple[RLData, ...] | None = None, info: dict[str, ndarray[tuple[int, ...], dtype[_ScalarType_co]] | dict[str, RLData] | tuple[RLData, ...] | None] | None = None, env_defined_actions: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | dict[str, RLData] | tuple[RLData, ...] | None = None) tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]] | dict[str, RLData] | tuple[RLData, ...] | None, ndarray[tuple[int, ...], dtype[_ScalarType_co]] | dict[str, RLData] | tuple[RLData, ...] | None]¶
Get actions from a deployed RL agent.
For multi-agent deployments, pass observation as
dict[agent_id, obs]. Per-agentaction_maskin info must be a dict keyed by agent id.- Parameters:
- Returns:
A tuple containing the action and the hidden state.
- Return type:
tuple[RLData, RLData | None]
- get_session(session_id: str) SessionDetail¶
Fetch one chat session and its messages.
- Parameters:
session_id (str) – The ID of the session to fetch.
- Returns:
The session and its messages.
- Return type:
- list_sessions() list[SessionInfo]¶
List the chat sessions the calling user has with this deployment.
- Returns:
The sessions, most recently updated first as ordered by the deployment. Empty when the user has no conversations yet.
- Return type:
- predict(inputs: ndarray[tuple[int, ...], dtype[_ScalarType_co]] | dict[str, RLData] | tuple[RLData, ...] | None, *, batched: bool = False) tuple[ndarray[tuple[int, ...], dtype[_ScalarType_co]] | dict[str, RLData] | tuple[RLData, ...] | None, PredictResult]¶
Return a prediction from a supervised agent.
- Parameters:
inputs (RLData) – The inputs to the agent.
batched (bool) – Whether to batch the inputs.
- Returns:
A tuple containing the prediction and the metadata.
- Return type:
tuple[RLData, PredictResult]
- Raises:
ArenaInferenceError – If the agent is not supervised.
- status(*, refresh: bool = False) StatusResponse¶
Return deployment metadata.
- Parameters:
refresh (bool) – Whether to refresh the metadata.
- Returns:
The deployment metadata.
- Return type: