Dev/agentstudio: add AgentStudio modules for managed agents#157
Conversation
Add a complete AgentStudio SDK package under dashscope/agentstudio/ that wraps the AgentStudio managed-agent HTTP API with sync and async clients, SSE streaming, automatic pagination, @tool decorator with SessionToolRunner, and comprehensive error handling. Wire-format types (content blocks, stop_reason, session status) are aligned with the AGENTSTUDIO API protocol specification. Includes unit tests for pagination, protocol types, tool runner, skills, and tool decorator, plus a sample script. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Rename _transport to transport (remove protected-access pattern) - Fix E501 line-too-long across all resource/transport/type files - Remove unused imports (Optional, json, field, logger, Mapping, Future) - Fix duplicate docstring in files.py, shorten long docstrings - Replace lambda with functools.partial in tools.py - Remove purely-passthrough __init__ methods in params.py - Add StrEnum compatibility shim for Python < 3.11 in constants.py - Fix pytest fixtures with name= parameter to avoid W0621 - Reference @tool params in return values to avoid W0613 - Add noqa: F401 for re-exports in types/__init__.py Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…stop_reason/session_status properties - Remove tools.py (@tool decorator, SessionToolRunner, DispatchedTool) server ToolConfigType only supports builtin_toolkit/mcp_toolkit - Restore user_custom_tool_result event constructor (function_call_output) - Add Vaults & Credentials resources (CRUD + archive) - Add region parameter to Client (default cn-beijing, was hardcoded) - Remove AGENTSTUDIO_DEFAULT_WORKSPACE="trial" fallback, workspace is now required when base_url is not provided - Add Message.stop_reason and Message.session_status properties - Add logging to transport (logger.warning on HTTP errors) - Add test_agentstudio_models.py (14 tests for vault/credential/agent) - Remove test_agentstudio_tools.py and test_agentstudio_runner.py - Fix test_agentstudio_protocol.py and test_agentstudio_skills.py Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… explicit - Remove unused _new_request_id() and import uuid from transport.py - Fix __del__ to wrap is_closed check in try/except for interpreter shutdown safety - Make version a required kwarg in agents.update() instead of auto-retrieving - Move stream error handling from session_events into transport retry loop - Add unit tests for agents.update version contract Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces the AgentStudio sub-SDK for the DashScope Python client, adding comprehensive synchronous and asynchronous resources for managing agents, environments, files, sessions, skills, and vaults. The review feedback highlights a few key issues: the pagination helper in the Files resource incorrectly uses the 'page' parameter instead of 'after_id', which could break pagination; the 'AsyncTransport.close' method attempts to synchronously close an 'httpx.AsyncClient', which will raise an AttributeError; and the 'Session.agent_id' property needs to be robust enough to handle cases where the agent is represented as a string rather than an Agent object.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
- Fix files.py fetch_next to use after_id instead of page for IdCursorPage - Remove dead sync close() body in AsyncTransport (AsyncClient has no sync close) - Handle string agent values in Session.agent_id property Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Remove after_id/before_id from FileListParams and IdCursorPage class (server Files endpoint only accepts page cursor) - Remove keyword from VaultListParams (server does not accept it) - Add resources field to SessionCreateParams for file mounting at session creation - Add wall-clock idle_timeout (300s) to EventStream/AsyncEventStream so the iterator unblocks when the server only sends keepalive frames (httpx read timeout gets reset by keepalive, blocking forever) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The previous Timer-based approach closed the response on idle, but httpx_sse.EventSource.iter_sse() does not unblock when response.close() is called from another thread — the foreground loop stayed stuck. Drain iter_sse() on a background thread and pull events through a queue with timeout in the foreground. On idle, close the response and return; the background thread is a daemon and will be reaped. Also lower the default from 300s to 120s. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Description
Add
dashscope.agentstudiosubmodule — a full-featured Python SDK for AgentStudio managed agents.Key capabilities: sync/async clients, CRUD for Agents/Sessions/Environments/Files/Skills/Vaults/Credentials, SSE streaming with typed events, auto-pagination, file upload with progress callbacks, and a structured exception hierarchy.
Security Considerations: No API keys or credentials exposed. All secrets are passed via environment variables or constructor parameters.
Type of Change
Component(s) Affected
Checklist
Testing