feat: Add Azure Container Apps Dynamic Sessions executor#2214
feat: Add Azure Container Apps Dynamic Sessions executor#2214ndamulelonemakh wants to merge 4 commits intohuggingface:mainfrom
Conversation
…ote executor. - keep Azure dependencies optional - add docs and usage example - add mocked unit tests for execution, files, and auth behavior
…ort and update token provider
VANDRANKI
left a comment
There was a problem hiding this comment.
This is a solid, well-scoped addition. The architecture follows the existing RemotePythonExecutor pattern cleanly and the test coverage is genuinely thorough. A few observations:
Token caching
The closure-based caching in _default_token_provider_factory has a minor race condition: two concurrent threads could both see cached_token is None or expires < now + 5min as True and both call credential.get_token(). No corruption occurs (both writes are valid tokens and the last write wins), but you get one unnecessary extra call. A threading.Lock around the refresh block would fix it if this executor is ever used from a multi-threaded agent.
download_file path encoding
urllib.parse.quote(remote_path) uses safe="/" by default, so a path like ../../sensitive passes through with slashes intact. Azure's API should reject such traversals server-side, but urllib.parse.quote(remote_path, safe="") would be more defensive on the client side.
Final-answer + traceback interaction
In run_code_raise_errors, if FINAL_ANSWER_EXCEPTION in stderr is true but deserialization fails (the except Exception: pass branch), execution falls through to the "Traceback" in stderr check. If a traceback is also present it raises AgentError rather than propagating the final answer. This seems like a reasonable fallback, but it might be worth a comment to explain the intent - it surprised me on first read.
Test highlights
test_default_token_provider_factory_raises_helpful_error_without_azure_extra is excellent - patching builtins.__import__ is the right way to test the lazy import guard. The request-shape test (test_run_code_raise_errors_posts_expected_request) also pins the exact URL structure, which will catch any accidental API version or query-param regressions.
Overall the implementation is correct, the optional-dependency wiring is done right (lazy import inside the factory, eager import only for requests which is already a core dep), and the documentation example is clear. The concerns above are minor.
What does this PR do?
Adds a new
AzureDynamicSessionsExecutor(alongsideE2BExecutor,ModalExecutor,DockerExecutor,WasmExecutor) so agents can run code in Azure Container Apps Dynamic Sessions — a managed, sandboxed Python runtime with persistent session state.Highlights
smolagents.azure_executors.AzureDynamicSessionsExecutor, exported from the top-level package.azure.identity.DefaultAzureCredentialby default, with:managed_identity_client_id=...kwarg, orAZURE_SESSIONS_MANAGED_IDENTITY_CLIENT_IDenv var, oraccess_token_providercallable (noazure-identityrequired)./mnt/datavolume.azureoptional dependency (pip install 'smolagents[azure]'), included inall.AgentError, file ops, cleanup, and managed-identity wiring.docs/source/en/reference/python_executors.md.Before submitting
Who can review?
@aymeric-roucher