BetaAgentsOperations Class
Warning
DO NOT instantiate this class directly.
Instead, you should access the following operations through
<xref:beta.agents> attribute.
Constructor
BetaAgentsOperations(*args, **kwargs)
Methods
| cancel_optimization_job |
Cancels an agent optimization job. Request cancellation. Idempotent on terminal states. |
| create_optimization_job |
Creates an agent optimization job. Create an optimization job. Returns 201 with the queued job. Honours |
| create_session |
Creates a new session for an agent endpoint. The endpoint resolves the backing agent version
from |
| create_version_from_code |
create_version_from_code. |
| delete_optimization_job |
Deletes an agent optimization job. Delete the job and its candidate artifacts. Cancels first if non-terminal. |
| delete_session |
Deletes a session synchronously. Returns 204 No Content when the session is deleted or does not exist. |
| delete_session_file |
Delete a file or directory from the session sandbox. If |
| download_code |
Download the code zip for a code-based hosted agent.
Returns the previously-uploaded zip ( If The SHA-256 digest of the returned bytes matches the |
| download_session_file |
Download a file from the session sandbox as a binary stream. |
| get_candidate_file |
Get a candidate file. Stream a specific file from the candidate's blob directory. |
| get_optimization_candidate |
Get a candidate by id. Get a single candidate's metadata, manifest, and promotion info. |
| get_optimization_candidate_config |
Get candidate deploy config. Get the candidate's deploy config JSON. Used to compose |
| get_optimization_candidate_results |
Get candidate evaluation results. Get full per-task evaluation results for a candidate. |
| get_optimization_job |
Get info about an agent optimization job. Get an optimization job by id. Returns 202 while in progress, 200 when terminal. |
| get_session |
Retrieves a session by ID. |
| get_session_log_stream |
Streams console logs (stdout / stderr) for a specific hosted agent session as a Server-Sent Events (SSE) stream. Each SSE frame contains:
Example SSE frames:
The stream remains open until the client disconnects or the server terminates the connection. Clients should handle reconnection as needed. |
| list_optimization_candidates |
Returns a list of candidates for an optimization job. List candidates produced by a job. |
| list_optimization_jobs |
Returns a list of agent optimization jobs. List optimization jobs. Supports cursor pagination and optional status / agent_name filters. |
| list_session_files |
List files and directories at a given path in the session sandbox. Returns only the immediate children of the specified directory (non-recursive). If path is not provided, lists the session home directory. |
| list_sessions |
Returns a list of sessions for the specified agent. |
| patch_agent_details |
Updates an agent endpoint. |
| promote_candidate |
Promote a candidate. Promotes a candidate, recording the deployment timestamp and target agent version. |
| stop_session |
Stops a session. Returns 204 No Content when the stop succeeds. |
| upload_session_file |
Upload a file to the session sandbox. Accepts either a |
cancel_optimization_job
Cancels an agent optimization job.
Request cancellation. Idempotent on terminal states.
cancel_optimization_job(job_id: str, **kwargs: Any) -> OptimizationJob
Parameters
| Name | Description |
|---|---|
|
job_id
Required
|
The ID of the job to cancel. Required. |
Returns
| Type | Description |
|---|---|
|
OptimizationJob. The OptimizationJob is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
create_optimization_job
Creates an agent optimization job.
Create an optimization job. Returns 201 with the queued job. Honours Operation-Id for
idempotent retry.
create_optimization_job(inputs: OptimizationJobInputs | MutableMapping[str, Any] | IO[bytes], *, operation_id: str | None = None, **kwargs: Any) -> OptimizationJob
Parameters
| Name | Description |
|---|---|
|
inputs
Required
|
The optimization job inputs. Is one of the following types: OptimizationJobInputs, JSON, IO[bytes] Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
operation_id
|
Client-generated unique ID for idempotent retries. When absent, the server creates the job unconditionally. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
OptimizationJob. The OptimizationJob is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
create_session
Creates a new session for an agent endpoint. The endpoint resolves the backing agent version
from version_indicator and enforces session ownership using the provided isolation key for
session-mutating operations.
create_session(agent_name: str, body: ~collections.abc.MutableMapping[str, ~typing.Any] | ~typing.IO[bytes] = <object object>, *, version_indicator: ~azure.ai.projects.models._models.VersionIndicator = <object object>, user_isolation_key: str | None = None, agent_session_id: str | None = None, **kwargs: ~typing.Any) -> AgentSessionResource
Parameters
| Name | Description |
|---|---|
|
agent_name
Required
|
The name of the agent to create a session for. Required. |
|
body
|
Is either a JSON type or a IO[bytes] type. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
version_indicator
|
Determines which agent version backs the session. Required. Default value: <object object at 0x0000020BF5381A50>
|
|
user_isolation_key
|
Opaque per-user isolation key used to scope endpoint-scoped data (responses, conversations, sessions) to a specific end user. Default value is None. Default value: None
|
|
agent_session_id
|
Optional caller-provided session ID. If specified, it must be unique within the agent endpoint. Auto-generated if omitted. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
AgentSessionResource. The AgentSessionResource is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
create_version_from_code
create_version_from_code.
create_version_from_code(agent_name: str, content: CreateAgentVersionFromCodeContent | MutableMapping[str, Any], *, code_zip_sha256: str, **kwargs: Any) -> AgentVersionDetails
Parameters
| Name | Description |
|---|---|
|
agent_name
Required
|
The unique name that identifies the agent. Name can be used to retrieve/update/delete the agent.
|
|
content
Required
|
CreateAgentVersionFromCodeContent or
<xref:JSON>
Is either a CreateAgentVersionFromCodeContent type or a JSON type. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
code_zip_sha256
|
SHA-256 hex digest of the uploaded code zip. Used for change detection (dedup) and integrity verification. Required. |
Returns
| Type | Description |
|---|---|
|
AgentVersionDetails. The AgentVersionDetails is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
delete_optimization_job
Deletes an agent optimization job.
Delete the job and its candidate artifacts. Cancels first if non-terminal.
delete_optimization_job(job_id: str, *, force: bool | None = None, **kwargs: Any) -> None
Parameters
| Name | Description |
|---|---|
|
job_id
Required
|
The ID of the job to delete. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
force
|
When true, force-delete even if the job is in a non-terminal state. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
None |
Exceptions
| Type | Description |
|---|---|
delete_session
Deletes a session synchronously. Returns 204 No Content when the session is deleted or does not exist.
delete_session(agent_name: str, session_id: str, *, user_isolation_key: str | None = None, **kwargs: Any) -> None
Parameters
| Name | Description |
|---|---|
|
agent_name
Required
|
The name of the agent. Required. |
|
session_id
Required
|
The session identifier. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
user_isolation_key
|
Opaque per-user isolation key used to scope endpoint-scoped data (responses, conversations, sessions) to a specific end user. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
None |
Exceptions
| Type | Description |
|---|---|
delete_session_file
Delete a file or directory from the session sandbox. If recursive is false (default) and
the target is a non-empty directory, the API returns 409 Conflict.
delete_session_file(agent_name: str, agent_session_id: str, *, path: str, recursive: bool | None = None, user_isolation_key: str | None = None, **kwargs: Any) -> None
Parameters
| Name | Description |
|---|---|
|
agent_name
Required
|
The name of the agent. Required. |
|
agent_session_id
Required
|
The session ID. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
path
|
The file or directory path to delete, relative to the session home directory. Required. |
|
recursive
|
Whether to recursively delete directory contents. The service defaults to
Default value: None
|
|
user_isolation_key
|
Opaque per-user isolation key used to scope endpoint-scoped data (responses, conversations, sessions) to a specific end user. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
None |
Exceptions
| Type | Description |
|---|---|
download_code
Download the code zip for a code-based hosted agent.
Returns the previously-uploaded zip (application/zip).
If agent_version is supplied, returns that version's code zip; otherwise
returns the latest version's code zip.
The SHA-256 digest of the returned bytes matches the content_hash on the
resolved version's code_configuration.
download_code(agent_name: str, *, agent_version: str | None = None, **kwargs: Any) -> Iterator[bytes]
Parameters
| Name | Description |
|---|---|
|
agent_name
Required
|
The name of the agent. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
agent_version
|
The version of the agent whose code zip should be downloaded. If omitted, the latest version's code zip is returned. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
Iterator[bytes] |
Exceptions
| Type | Description |
|---|---|
download_session_file
Download a file from the session sandbox as a binary stream.
download_session_file(agent_name: str, agent_session_id: str, *, path: str, user_isolation_key: str | None = None, **kwargs: Any) -> Iterator[bytes]
Parameters
| Name | Description |
|---|---|
|
agent_name
Required
|
The name of the agent. Required. |
|
agent_session_id
Required
|
The session ID. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
path
|
The file path to download from the sandbox, relative to the session home directory. Required. |
|
user_isolation_key
|
Opaque per-user isolation key used to scope endpoint-scoped data (responses, conversations, sessions) to a specific end user. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
Iterator[bytes] |
Exceptions
| Type | Description |
|---|---|
get_candidate_file
Get a candidate file.
Stream a specific file from the candidate's blob directory.
get_candidate_file(job_id: str, candidate_id: str, *, path: str, **kwargs: Any) -> Iterator[bytes]
Parameters
| Name | Description |
|---|---|
|
job_id
Required
|
The optimization job id. Required. |
|
candidate_id
Required
|
The candidate id. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
path
|
Relative path of the file to download (e.g. 'files/examples.jsonl'). Required. |
Returns
| Type | Description |
|---|---|
|
Iterator[bytes] |
Exceptions
| Type | Description |
|---|---|
get_optimization_candidate
Get a candidate by id.
Get a single candidate's metadata, manifest, and promotion info.
get_optimization_candidate(job_id: str, candidate_id: str, **kwargs: Any) -> CandidateMetadata
Parameters
| Name | Description |
|---|---|
|
job_id
Required
|
The optimization job id. Required. |
|
candidate_id
Required
|
The candidate id. Required. |
Returns
| Type | Description |
|---|---|
|
CandidateMetadata. The CandidateMetadata is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
get_optimization_candidate_config
Get candidate deploy config.
Get the candidate's deploy config JSON. Used to compose agents.create_version(...) from a
candidate.
get_optimization_candidate_config(job_id: str, candidate_id: str, **kwargs: Any) -> CandidateDeployConfig
Parameters
| Name | Description |
|---|---|
|
job_id
Required
|
The optimization job id. Required. |
|
candidate_id
Required
|
The candidate id. Required. |
Returns
| Type | Description |
|---|---|
|
CandidateDeployConfig. The CandidateDeployConfig is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
get_optimization_candidate_results
Get candidate evaluation results.
Get full per-task evaluation results for a candidate.
get_optimization_candidate_results(job_id: str, candidate_id: str, **kwargs: Any) -> CandidateResults
Parameters
| Name | Description |
|---|---|
|
job_id
Required
|
The optimization job id. Required. |
|
candidate_id
Required
|
The candidate id. Required. |
Returns
| Type | Description |
|---|---|
|
CandidateResults. The CandidateResults is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
get_optimization_job
Get info about an agent optimization job.
Get an optimization job by id. Returns 202 while in progress, 200 when terminal.
get_optimization_job(job_id: str, **kwargs: Any) -> OptimizationJob
Parameters
| Name | Description |
|---|---|
|
job_id
Required
|
The ID of the job. Required. |
Returns
| Type | Description |
|---|---|
|
OptimizationJob. The OptimizationJob is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
get_session
Retrieves a session by ID.
get_session(agent_name: str, session_id: str, *, user_isolation_key: str | None = None, **kwargs: Any) -> AgentSessionResource
Parameters
| Name | Description |
|---|---|
|
agent_name
Required
|
The name of the agent. Required. |
|
session_id
Required
|
The session identifier. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
user_isolation_key
|
Opaque per-user isolation key used to scope endpoint-scoped data (responses, conversations, sessions) to a specific end user. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
AgentSessionResource. The AgentSessionResource is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
get_session_log_stream
Streams console logs (stdout / stderr) for a specific hosted agent session as a Server-Sent Events (SSE) stream.
Each SSE frame contains:
event: always "log"
data: a plain-text log line (currently JSON-formatted, but the schema is not contractual and may include additional keys or change format over time; clients should treat it as an opaque string)
Example SSE frames:
event: log
data: {"timestamp":"2026-03-10T09:33:17.121Z","stream":"stdout","message":"Starting FoundryCBAgent server on port 8088"}
event: log
data: {"timestamp":"2026-03-10T09:33:17.130Z","stream":"stderr","message":"INFO: Application startup complete."}
event: log
data: {"timestamp":"2026-03-10T09:34:52.714Z","stream":"status","message":"Successfully connected to container"}
event: log
data: {"timestamp":"2026-03-10T09:35:52.714Z","stream":"status","message":"No logs since last 60 seconds"}
The stream remains open until the client disconnects or the server terminates the connection. Clients should handle reconnection as needed.
get_session_log_stream(agent_name: str, agent_version: str, session_id: str, **kwargs: Any) -> SessionLogEvent
Parameters
| Name | Description |
|---|---|
|
agent_name
Required
|
The name of the hosted agent. Required. |
|
agent_version
Required
|
The version of the agent. Required. |
|
session_id
Required
|
The session ID (maps to an ADC sandbox). Required. |
Returns
| Type | Description |
|---|---|
|
SessionLogEvent. The SessionLogEvent is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
list_optimization_candidates
Returns a list of candidates for an optimization job.
List candidates produced by a job.
list_optimization_candidates(job_id: str, *, limit: int | None = None, order: str | PageOrder | None = None, after: str | None = None, before: str | None = None, **kwargs: Any) -> AgentsPagedResultOptimizationCandidate
Parameters
| Name | Description |
|---|---|
|
job_id
Required
|
The optimization job id. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
limit
|
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. Default value is None. Default value: None
|
|
order
|
Sort order by the Default value: None
|
|
after
|
A cursor for use in pagination. Default value: None
|
|
before
|
A cursor for use in pagination. Default value: None
|
Returns
| Type | Description |
|---|---|
|
AgentsPagedResultOptimizationCandidate. The AgentsPagedResultOptimizationCandidate is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
list_optimization_jobs
Returns a list of agent optimization jobs.
List optimization jobs. Supports cursor pagination and optional status / agent_name filters.
list_optimization_jobs(*, limit: int | None = None, order: str | PageOrder | None = None, before: str | None = None, status: str | JobStatus | None = None, agent_name: str | None = None, **kwargs: Any) -> ItemPaged[OptimizationJob]
Keyword-Only Parameters
| Name | Description |
|---|---|
|
limit
|
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. Default value is None. Default value: None
|
|
order
|
Sort order by the Default value: None
|
|
before
|
A cursor for use in pagination. Default value: None
|
|
status
|
Filter to jobs in this lifecycle state. Known values are: "queued", "in_progress", "succeeded", "failed", and "cancelled". Default value is None. Default value: None
|
|
agent_name
|
Filter to jobs targeting this agent name. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An iterator like instance of OptimizationJob |
Exceptions
| Type | Description |
|---|---|
list_session_files
List files and directories at a given path in the session sandbox. Returns only the immediate children of the specified directory (non-recursive). If path is not provided, lists the session home directory.
list_session_files(agent_name: str, agent_session_id: str, *, path: str | None = None, user_isolation_key: str | None = None, limit: int | None = None, order: str | PageOrder | None = None, before: str | None = None, **kwargs: Any) -> ItemPaged[SessionDirectoryEntry]
Parameters
| Name | Description |
|---|---|
|
agent_name
Required
|
The name of the agent. Required. |
|
agent_session_id
Required
|
The session ID. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
path
|
The directory path to list, relative to the session home directory. Defaults to the home directory if not provided. Default value is None. Default value: None
|
|
user_isolation_key
|
Opaque per-user isolation key used to scope endpoint-scoped data (responses, conversations, sessions) to a specific end user. Default value is None. Default value: None
|
|
limit
|
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. Default value is None. Default value: None
|
|
order
|
Sort order by the Default value: None
|
|
before
|
A cursor for use in pagination. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An iterator like instance of SessionDirectoryEntry |
Exceptions
| Type | Description |
|---|---|
list_sessions
Returns a list of sessions for the specified agent.
list_sessions(agent_name: str, *, user_isolation_key: str | None = None, limit: int | None = None, order: str | PageOrder | None = None, before: str | None = None, **kwargs: Any) -> ItemPaged[AgentSessionResource]
Parameters
| Name | Description |
|---|---|
|
agent_name
Required
|
The name of the agent. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
user_isolation_key
|
Opaque per-user isolation key used to scope endpoint-scoped data (responses, conversations, sessions) to a specific end user. Default value is None. Default value: None
|
|
limit
|
A limit on the number of objects to be returned. Limit can range between 1 and 100, and the default is 20. Default value is None. Default value: None
|
|
order
|
Sort order by the Default value: None
|
|
before
|
A cursor for use in pagination. Default value: None
|
Returns
| Type | Description |
|---|---|
|
An iterator like instance of AgentSessionResource |
Exceptions
| Type | Description |
|---|---|
patch_agent_details
Updates an agent endpoint.
patch_agent_details(agent_name: str, body: ~collections.abc.MutableMapping[str, ~typing.Any] | ~typing.IO[bytes] = <object object>, *, agent_endpoint: ~azure.ai.projects.models._models.AgentEndpointConfig | None = None, agent_card: ~azure.ai.projects.models._models.AgentCard | None = None, **kwargs: ~typing.Any) -> AgentDetails
Parameters
| Name | Description |
|---|---|
|
agent_name
Required
|
The name of the agent to retrieve. Required. |
|
body
|
Is either a JSON type or a IO[bytes] type. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
agent_endpoint
|
The endpoint configuration for the agent. Default value is None. Default value: None
|
|
agent_card
|
Optional agent card for the agent. Default value is None. Default value: None
|
Returns
| Type | Description |
|---|---|
|
AgentDetails. The AgentDetails is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
promote_candidate
Promote a candidate.
Promotes a candidate, recording the deployment timestamp and target agent version.
promote_candidate(job_id: str, candidate_id: str, candidate_request: PromoteCandidateRequest | MutableMapping[str, Any] | IO[bytes], **kwargs: Any) -> PromoteCandidateResponse
Parameters
| Name | Description |
|---|---|
|
job_id
Required
|
The optimization job id. Required. |
|
candidate_id
Required
|
The candidate id to promote. Required. |
|
candidate_request
Required
|
Promotion details. Is one of the following types: PromoteCandidateRequest, JSON, IO[bytes] Required. |
Returns
| Type | Description |
|---|---|
|
PromoteCandidateResponse. The PromoteCandidateResponse is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
stop_session
Stops a session. Returns 204 No Content when the stop succeeds.
stop_session(agent_name: str, session_id: str, **kwargs: Any) -> None
Parameters
| Name | Description |
|---|---|
|
agent_name
Required
|
The name of the agent. Required. |
|
session_id
Required
|
The session identifier. Required. |
Returns
| Type | Description |
|---|---|
|
None |
Exceptions
| Type | Description |
|---|---|
upload_session_file
Upload a file to the session sandbox.
Accepts either a bytes buffer or a local file path (str).
When a file path is provided the file is read from disk and its contents
are forwarded to the service. Maximum file size is 50 MB. Uploads
exceeding this limit return 413 Payload Too Large.
upload_session_file(agent_name: str, session_id: str, content_or_file_path: bytes | str, *, path: str, **kwargs: Any) -> SessionFileWriteResult
Parameters
| Name | Description |
|---|---|
|
agent_name
Required
|
The name of the agent. Required. |
|
session_id
Required
|
The session ID. Required. |
|
content_or_file_path
Required
|
The binary content to upload, or the full path to a local file whose contents should be uploaded. Required. |
Keyword-Only Parameters
| Name | Description |
|---|---|
|
path
|
The destination file path within the sandbox, relative to the session home directory. Required. |
Returns
| Type | Description |
|---|---|
|
SessionFileWriteResult. The SessionFileWriteResult is compatible with MutableMapping |
Exceptions
| Type | Description |
|---|---|
|
If content_or_file_path is a |