Method updates following another api review meeting#47757
Conversation
There was a problem hiding this comment.
Pull request overview
This PR rolls back the Python-specific disk-based file helper methods on the hosted-agents sub-client of azure-ai-projects, following an architecture review. The custom download_session_file_to_path, download_code_to_path, download_session_file_as_bytes, download_code_as_bytes methods and the upload_session_file overload accepting a file_path are removed in favor of the emitted methods: download_session_file, download_code, and upload_session_file(content=bytes). The previously private _upload_session_file is promoted to public, and samples plus generated API metadata are updated accordingly.
Changes:
- Remove the disk I/O helper methods and the
file_path/overload-basedupload_session_filefrom the_patch_agentscustomization layer (sync + async). - Rename generated operations (
download_code_as_bytes→download_code,download_session_file_as_bytes→download_session_file,_upload_session_file→upload_session_file) and their request builders, with matching updates toapi.md,api.metadata.yml, andapiview-properties.json. - Update hosted-agent samples to read file bytes manually and call the streamlined methods.
Note (outside PR scope): tests/sessions/test_agent_session_files_crud.py, its async counterpart, and docs/public-methods.md still reference the removed methods (download_session_file_as_bytes, download_session_file_to_path, download_code_to_path); these were not updated in this PR and would break/be out of sync.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
operations/_patch_agents.py |
Removes disk-based helpers/overloads; leaves hashlib/os/Path imports now unused |
aio/operations/_patch_agents_async.py |
Async counterpart of the same removal; same now-unused imports |
operations/_operations.py |
Renames generated download/upload methods and request builders |
aio/operations/_operations.py |
Async rename of the same generated methods and imports |
samples/.../sample_sessions_files_upload_download.py |
Reads bytes and calls upload_session_file(content=...) / download_session_file |
samples/.../sample_sessions_files_upload_download_async.py |
Async version of the sample update |
samples/.../sample_create_hosted_agent_from_code.py |
Uses download_code + in-memory sha256; stale "streaming" comment |
samples/.../sample_create_hosted_agent_from_code_async.py |
Async version; same stale comment |
apiview-properties.json |
Updates cross-language method mappings and version |
api.md / api.metadata.yml |
Regenerated API surface and hash |
After further consultation with the architects, we decided to roll back the Python support for file upload/download to/from disk.
This means that instead of these 4 methods on the .agent sub-client:
We'll just use the two emitted ones:
It also means we remove the upload_session_file overload that accepted
file_path: Union[str, "os.PathLike[str]"], and just leave the emitted method that acceptscontent: bytes. In future releases, this will expand to supportcontent: Union[bytes, IO[bytes]].This PR also includes renaming "agent_session_id" input argument in session file method to just "session_id", to match the argument name in session methods.
This PR also includes reverting to the original "path" input argument name when uploading a session file. I previously did a client rename of this to "remote_path", since I had hand-written method to upload from file on disk, and it had an input argument name "file_path". At the time I wanted it to be clear what's the local path for upload and the remove path (in the session sandbox) where the file is written. Since I removed the upload session file from disk method, there is no longer a need to make that distinction. So I'm reverting back to the original name as used in REST APIs.
This PR also include flattening the method
create_version_from_code, and simplifyingcodeto be of typeIO[bytes]only.