AgentsOperations Class

Warning

DO NOT instantiate this class directly.

Instead, you should access the following operations through

AIProjectClient's

<xref:agents> attribute.

Constructor

AgentsOperations(*args, **kwargs)

Methods

create_session

Create a 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 user identity for session-mutating operations.

create_version

Create an agent version.

Creates a new version for the specified agent and returns the created version resource.

create_version_from_code

Create an agent version from code.

Creates a new agent version from code. Uploads the code zip and creates a new version for an existing agent. The SHA-256 hex digest of the zip is provided in the x-ms-code-zip-sha256 header for integrity and dedup. The request body is multipart/form-data with a JSON metadata part and a binary code part (part order is irrelevant). Maximum upload size is 250 MB.

create_version_from_manifest

Create an agent version from manifest.

Imports the provided manifest to create a new version for the specified agent.

delete

Delete an agent.

Deletes an agent. For hosted agents, if any version has active sessions, the request is rejected with HTTP 409 unless force is set to true. When force is true, all associated sessions are cascade-deleted along with the agent and its versions.

delete_session

Delete a session.

Deletes a session synchronously. Returns 204 No Content when the session is deleted or does not exist.

delete_session_file

Delete a session file.

Deletes the specified file or directory from the session sandbox. When recursive is false, deleting a non-empty directory returns 409 Conflict.

delete_version

Delete an agent version.

Deletes a specific version of an agent. For hosted agents, if the version has active sessions, the request is rejected with HTTP 409 unless force is set to true. When force is true, all sessions associated with this version are cascade-deleted.

disable

Disable an agent.

Disables the specified agent, preventing it from accepting new sessions or processing requests. Existing active sessions are allowed to drain gracefully but no new sessions can be created. This operation is idempotent — disabling an already-disabled agent returns success with no side effects.

download_code

Download agent code.

Downloads 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_session_file

Download a session file.

Downloads the file at the specified sandbox path as a binary stream. The path is resolved relative to the session home directory.

enable

Enable an agent.

Enables the specified agent, allowing it to accept new sessions and process requests. This operation is idempotent — enabling an already-enabled agent returns success with no side effects.

get

Get an agent.

Retrieves an agent definition by its unique name.

get_session

Get a session.

Retrieves the details of a hosted agent session by agent name and session identifier.

get_session_log_stream

Stream console logs for a hosted agent session.

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_version

Get an agent version.

Retrieves the specified version of an agent by its agent name and version identifier.

list

List agents.

Returns a paged collection of agent resources.

list_session_files

List session files.

Returns files and directories at the specified path in the session sandbox. The response includes only the immediate children of the target directory and defaults to the session home directory when no path is supplied.

list_sessions

List sessions for an agent.

Returns a paged collection of sessions associated with the specified agent endpoint.

list_versions

List agent versions.

Returns a paged collection of versions for the specified agent.

stop_session

Stop a session.

Terminates the specified hosted agent session and returns 204 No Content when the request succeeds.

update_details

Update an agent endpoint.

Applies a merge-patch update to the specified agent endpoint configuration.

upload_session_file

Upload a session file.

Uploads binary file content to the specified path in the session sandbox. The service stores the file relative to the session home directory and rejects payloads larger than 50 MB.

create_session

Create a 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 user identity 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>, agent_session_id: str | None = None, **kwargs: ~typing.Any) -> AgentSessionResource

Parameters

Name Description
agent_name
Required
str

The name of the agent to create a session for. Required.

body
<xref:JSON> or IO[bytes]

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 0x000002A3330F9BE0>
agent_session_id
str

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

Create an agent version.

Creates a new version for the specified agent and returns the created version resource.

create_version(agent_name: str, *, definition: _models.AgentDefinition, content_type: str = 'application/json', metadata: dict[str, str] | None = None, description: str | None = None, blueprint_reference: _models.AgentBlueprintReference | None = None, draft: bool | None = None, **kwargs: Any) -> _models.AgentVersionDetails

Parameters

Name Description
agent_name
Required
str

The unique name that identifies the agent. Name can be used to retrieve/update/delete the agent.

  • Must start and end with alphanumeric characters,

  • Can contain hyphens in the middle

  • Must not exceed 63 characters. Required.

body
<xref:JSON> or IO[bytes]

Is either a JSON type or a IO[bytes] type. Required.

Keyword-Only Parameters

Name Description
definition

The agent definition. This can be a workflow, hosted agent, or a simple agent definition. Required.

Default value: <object object at 0x000002A3330F9BE0>
metadata

Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.

Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters. Default value is None.

Default value: None
description
str

A human-readable description of the agent. Default value is None.

Default value: None
blueprint_reference

The blueprint reference for the agent. Default value is None.

Default value: None
draft

(Preview) Whether this agent version is a draft (candidate) rather than a release. The service defaults to false if a value is not specified by the caller. Draft versions are recorded but excluded from default 'latest' resolution and are not auto-promoted. Default value is None.

Default value: None

Returns

Type Description

AgentVersionDetails. The AgentVersionDetails is compatible with MutableMapping

Exceptions

Type Description

create_version_from_code

Create an agent version from code.

Creates a new agent version from code. Uploads the code zip and creates a new version for an existing agent. The SHA-256 hex digest of the zip is provided in the x-ms-code-zip-sha256 header for integrity and dedup. The request body is multipart/form-data with a JSON metadata part and a binary code part (part order is irrelevant). Maximum upload size is 250 MB.

create_version_from_code(agent_name: str, *, definition: HostedAgentDefinition, code: IO[bytes], code_zip_sha256: str | None = None, description: str | None = None, metadata: dict[str, str] | None = None, **kwargs: Any) -> AgentVersionDetails

Parameters

Name Description
agent_name
Required
str

The unique name that identifies the agent. Name can be used to retrieve/update/delete the agent.

  • Must start and end with alphanumeric characters,

  • Can contain hyphens in the middle

  • Must not exceed 63 characters. Required.

Keyword-Only Parameters

Name Description
definition

The hosted agent definition including code_configuration (runtime, entry_point), cpu, memory, and protocol_versions. Required.

code

The code zip file stream (max 250 MB). Required. The stream must expose a name attribute (for example, a stream returned by open) and that name must end with .zip.

code_zip_sha256
str

SHA-256 hex digest of the uploaded code zip. Used for change detection (dedup) and integrity verification. If not provided, it will be calculated automatically from the code content. Default value is None.

Default value: None
description
str

A human-readable description of the agent. Default value is None.

Default value: None
metadata

Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.

Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters. Default value is None.

Default value: None

Returns

Type Description

AgentVersionDetails. The AgentVersionDetails is compatible with MutableMapping

Exceptions

Type Description

create_version_from_manifest

Create an agent version from manifest.

Imports the provided manifest to create a new version for the specified agent.

create_version_from_manifest(agent_name: str, body: ~collections.abc.MutableMapping[str, ~typing.Any] | ~typing.IO[bytes] = <object object>, *, manifest_id: str = <object object>, parameter_values: dict[str, typing.Any] = <object object>, metadata: dict[str, str] | None = None, description: str | None = None, **kwargs: ~typing.Any) -> AgentVersionDetails

Parameters

Name Description
agent_name
Required
str

The unique name that identifies the agent. Name can be used to retrieve/update/delete the agent.

  • Must start and end with alphanumeric characters,

  • Can contain hyphens in the middle

  • Must not exceed 63 characters. Required.

body
<xref:JSON> or IO[bytes]

Is either a JSON type or a IO[bytes] type. Required.

Keyword-Only Parameters

Name Description
manifest_id
str

The manifest ID to import the agent version from. Required.

Default value: <object object at 0x000002A3330F9BE0>
parameter_values

The inputs to the manifest that will result in a fully materialized Agent. Required.

Default value: <object object at 0x000002A3330F9BE0>
metadata

Set of 16 key-value pairs that can be attached to an object. This can be useful for storing additional information about the object in a structured format, and querying for objects via API or the dashboard.

Keys are strings with a maximum length of 64 characters. Values are strings with a maximum length of 512 characters. Default value is None.

Default value: None
description
str

A human-readable description of the agent. Default value is None.

Default value: None

Returns

Type Description

AgentVersionDetails. The AgentVersionDetails is compatible with MutableMapping

Exceptions

Type Description

delete

Delete an agent.

Deletes an agent. For hosted agents, if any version has active sessions, the request is rejected with HTTP 409 unless force is set to true. When force is true, all associated sessions are cascade-deleted along with the agent and its versions.

delete(agent_name: str, *, force: bool | None = None, **kwargs: Any) -> DeleteAgentResponse

Parameters

Name Description
agent_name
Required
str

The name of the agent to delete. Required.

Keyword-Only Parameters

Name Description
force

For Hosted Agents, if true, force-deletes the agent even if its versions have active sessions, cascading deletion to all associated sessions. The service defaults to false if a value is not specified by the caller. This value is not relevant for other Agent types. Default value is None.

Default value: None

Returns

Type Description

DeleteAgentResponse. The DeleteAgentResponse is compatible with MutableMapping

Exceptions

Type Description

delete_session

Delete a 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, **kwargs: Any) -> None

Parameters

Name Description
agent_name
Required
str

The name of the agent. Required.

session_id
Required
str

The session identifier. Required.

Returns

Type Description

None

Exceptions

Type Description

delete_session_file

Delete a session file.

Deletes the specified file or directory from the session sandbox. When recursive is false, deleting a non-empty directory returns 409 Conflict.

delete_session_file(agent_name: str, session_id: str, *, path: str, recursive: bool | None = None, **kwargs: Any) -> None

Parameters

Name Description
agent_name
Required
str

The name of the agent. Required.

session_id
Required
str

The session ID. Required.

Keyword-Only Parameters

Name Description
path
str

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 false if a value is not specified by the caller. Default value is None.

Default value: None

Returns

Type Description

None

Exceptions

Type Description

delete_version

Delete an agent version.

Deletes a specific version of an agent. For hosted agents, if the version has active sessions, the request is rejected with HTTP 409 unless force is set to true. When force is true, all sessions associated with this version are cascade-deleted.

delete_version(agent_name: str, agent_version: str, *, force: bool | None = None, **kwargs: Any) -> DeleteAgentVersionResponse

Parameters

Name Description
agent_name
Required
str

The name of the agent to delete. Required.

agent_version
Required
str

The version of the agent to delete. Required.

Keyword-Only Parameters

Name Description
force

For Hosted Agents, if true, force-deletes the version even if it has active sessions, cascading deletion to all associated sessions. The service defaults to false if a value is not specified by the caller. This value is not relevant for other Agent types. Default value is None.

Default value: None

Returns

Type Description

DeleteAgentVersionResponse. The DeleteAgentVersionResponse is compatible with MutableMapping

Exceptions

Type Description

disable

Disable an agent.

Disables the specified agent, preventing it from accepting new sessions or processing requests. Existing active sessions are allowed to drain gracefully but no new sessions can be created. This operation is idempotent — disabling an already-disabled agent returns success with no side effects.

disable(agent_name: str, **kwargs: Any) -> None

Parameters

Name Description
agent_name
Required
str

The name of the agent to disable. Required.

Returns

Type Description

None

Exceptions

Type Description

download_code

Download agent code.

Downloads 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
str

The name of the agent. Required.

Keyword-Only Parameters

Name Description
agent_version
str

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 session file.

Downloads the file at the specified sandbox path as a binary stream. The path is resolved relative to the session home directory.

download_session_file(agent_name: str, session_id: str, *, path: str, **kwargs: Any) -> Iterator[bytes]

Parameters

Name Description
agent_name
Required
str

The name of the agent. Required.

session_id
Required
str

The session ID. Required.

Keyword-Only Parameters

Name Description
path
str

The file path to download from the sandbox, relative to the session home directory. Required.

Returns

Type Description

Iterator[bytes]

Exceptions

Type Description

enable

Enable an agent.

Enables the specified agent, allowing it to accept new sessions and process requests. This operation is idempotent — enabling an already-enabled agent returns success with no side effects.

enable(agent_name: str, **kwargs: Any) -> None

Parameters

Name Description
agent_name
Required
str

The name of the agent to enable. Required.

Returns

Type Description

None

Exceptions

Type Description

get

Get an agent.

Retrieves an agent definition by its unique name.

get(agent_name: str, **kwargs: Any) -> AgentDetails

Parameters

Name Description
agent_name
Required
str

The name of the agent to retrieve. Required.

Returns

Type Description

AgentDetails. The AgentDetails is compatible with MutableMapping

Exceptions

Type Description

get_session

Get a session.

Retrieves the details of a hosted agent session by agent name and session identifier.

get_session(agent_name: str, session_id: str, **kwargs: Any) -> AgentSessionResource

Parameters

Name Description
agent_name
Required
str

The name of the agent. Required.

session_id
Required
str

The session identifier. Required.

Returns

Type Description

AgentSessionResource. The AgentSessionResource is compatible with MutableMapping

Exceptions

Type Description

get_session_log_stream

Stream console logs for a hosted agent session.

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
str

The name of the hosted agent. Required.

agent_version
Required
str

The version of the agent. Required.

session_id
Required
str

The session ID (maps to an ADC sandbox). Required.

Returns

Type Description

SessionLogEvent. The SessionLogEvent is compatible with MutableMapping

Exceptions

Type Description

get_version

Get an agent version.

Retrieves the specified version of an agent by its agent name and version identifier.

get_version(agent_name: str, agent_version: str, **kwargs: Any) -> AgentVersionDetails

Parameters

Name Description
agent_name
Required
str

The name of the agent to retrieve. Required.

agent_version
Required
str

The version of the agent to retrieve. Required.

Returns

Type Description

AgentVersionDetails. The AgentVersionDetails is compatible with MutableMapping

Exceptions

Type Description

list

List agents.

Returns a paged collection of agent resources.

list(*, kind: str | AgentKind | None = None, limit: int | None = None, order: str | PageOrder | None = None, before: str | None = None, **kwargs: Any) -> ItemPaged[AgentDetails]

Keyword-Only Parameters

Name Description
kind

Filter agents by kind. If not provided, all agents are returned. Known values are: "prompt", "hosted", "workflow", and "external". Default value is None.

Default value: None
limit
int

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 created_at timestamp of the objects. asc for ascending order anddesc for descending order. Known values are: "asc" and "desc". Default value is None.

Default value: None
before
str

A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. Default value is None.

Default value: None

Returns

Type Description

An iterator like instance of AgentDetails

Exceptions

Type Description

list_session_files

List session files.

Returns files and directories at the specified path in the session sandbox. The response includes only the immediate children of the target directory and defaults to the session home directory when no path is supplied.

list_session_files(agent_name: str, session_id: str, *, path: 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
str

The name of the agent. Required.

session_id
Required
str

The session ID. Required.

Keyword-Only Parameters

Name Description
path
str

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
limit
int

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 created_at timestamp of the objects. asc for ascending order anddesc for descending order. Known values are: "asc" and "desc". Default value is None.

Default value: None
before
str

A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. Default value is None.

Default value: None

Returns

Type Description

An iterator like instance of SessionDirectoryEntry

Exceptions

Type Description

list_sessions

List sessions for an agent.

Returns a paged collection of sessions associated with the specified agent endpoint.

list_sessions(agent_name: str, *, limit: int | None = None, order: str | PageOrder | None = None, before: str | None = None, **kwargs: Any) -> ItemPaged[AgentSessionResource]

Parameters

Name Description
agent_name
Required
str

The name of the agent. Required.

Keyword-Only Parameters

Name Description
limit
int

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 created_at timestamp of the objects. asc for ascending order anddesc for descending order. Known values are: "asc" and "desc". Default value is None.

Default value: None
before
str

A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. Default value is None.

Default value: None

Returns

Type Description

An iterator like instance of AgentSessionResource

Exceptions

Type Description

list_versions

List agent versions.

Returns a paged collection of versions for the specified agent.

list_versions(agent_name: str, *, limit: int | None = None, order: str | PageOrder | None = None, before: str | None = None, include_drafts: bool | None = None, **kwargs: Any) -> ItemPaged[AgentVersionDetails]

Parameters

Name Description
agent_name
Required
str

The name of the agent to retrieve versions for. Required.

Keyword-Only Parameters

Name Description
limit
int

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 created_at timestamp of the objects. asc for ascending order anddesc for descending order. Known values are: "asc" and "desc". Default value is None.

Default value: None
before
str

A cursor for use in pagination. before is an object ID that defines your place in the list. For instance, if you make a list request and receive 100 objects, ending with obj_foo, your subsequent call can include before=obj_foo in order to fetch the previous page of the list. Default value is None.

Default value: None
include_drafts

(Preview) Whether to include draft versions in the listing. The service defaults to false if a value is not specified by the caller (only non-draft versions are returned). Default value is None.

Default value: None

Returns

Type Description

An iterator like instance of AgentVersionDetails

Exceptions

Type Description

stop_session

Stop a session.

Terminates the specified hosted agent session and returns 204 No Content when the request succeeds.

stop_session(agent_name: str, session_id: str, **kwargs: Any) -> None

Parameters

Name Description
agent_name
Required
str

The name of the agent. Required.

session_id
Required
str

The session identifier. Required.

Returns

Type Description

None

Exceptions

Type Description

update_details

Update an agent endpoint.

Applies a merge-patch update to the specified agent endpoint configuration.

update_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
str

The name of the agent to retrieve. Required.

body
<xref:JSON> or IO[bytes]

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

upload_session_file

Upload a session file.

Uploads binary file content to the specified path in the session sandbox. The service stores the file relative to the session home directory and rejects payloads larger than 50 MB.

upload_session_file(agent_name: str, session_id: str, content: bytes, *, path: str, **kwargs: Any) -> SessionFileWriteResult

Parameters

Name Description
agent_name
Required
str

The name of the agent. Required.

session_id
Required
str

The session ID. Required.

content
Required

Required.

Keyword-Only Parameters

Name Description
path
str

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