agentscope-ai / agentscope-ai/agentscope
[Feature]: Add per-agent control for Studio data reporting
- Ngôn ngữ chính
- Python
- Star
- 31.6k
- Fork
- 3.5k
- Merge trung bình
- 1 ngày 16 giờ
- Pull request đã merge (30 ngày)
- 103
Mô tả
## Feature Request: Add per-agent control for Studio data reporting
**Is your feature request related to a problem? Please describe.**
Currently, when AgentScope Studio is connected via `_equip_as_studio_hooks()`, the `as_studio_forward_message_pre_print_hook` is registered as a class-level hook that applies to **all** Agent instances. This causes two main issues:
1. **Performance Impact**: The hook makes a synchronous HTTP request (`requests.post`) to Studio on every `print()` call. This blocking network I/O can significantly slow down agent execution, especially when:
- Network latency is high
- Studio server responds slowly
- Agents generate frequent messages
- The retry mechanism (up to 3 retries) kicks in on failures
```python
# Current implementation in _studio_hooks.py - blocking call
res = requests.post(
f"{studio_url}/trpc/pushMessage",
json={...},
)
res.raise_for_status()
```
2. **No per-agent control**: There is no way to disable Studio data reporting for individual agents while keeping it enabled for others. The only workaround (`set_console_output_enabled(False)`) also disables console output.
**Describe the solution you'd like**
1. **Add per-agent control flag** in `AgentBase`:
```python
class AgentBase:
def __init__(self, ..., enable_studio_reporting: bool = True):
...
self._enable_studio_reporting = enable_studio_reporting
def set_studio_reporting_enabled(self, enabled: bool) -> None:
"""Enable or disable Studio data reporting for this agent instance."""
self._enable_studio_reporting = enabled
```
2. **Make the reporting asynchronous** to avoid blocking agent execution:
```python
import asyncio
from concurrent.futures import ThreadPoolExecutor
_executor = ThreadPoolExecutor(max_workers=4)
def as_studio_forward_message_pre_print_hook(
self: AgentBase,
kwargs: dict[str, Any],
studio_url: str,
run_id: str,
) -> None:
# Check if studio reporting is disabled for this agent
if getattr(self, "_enable_studio_reporting", True) is False:
return
if self._disable_console_output:
return
msg = kwargs["msg"]
message_data = msg.to_dict()
# Non-blocking: submit to thread pool
_executor.submit(
_send_to_studio,
studio_url,
run_id,
getattr(self, "_reply_id", shortuuid.uuid()),
getattr(self, "name", msg.name),
isinstance(self, UserAgent),
message_data,
)
def _send_to_studio(studio_url, run_id, reply_id, reply_name, is_user, message_data):
"""Background task to send message to studio."""
# ... existing retry logic ...
```
**Describe alternatives you've considered**
1. **Using `set_console_output_enabled(False)`**: Disables reporting but also disables console output.
2. **Using `asyncio.create_task()`**: Would require the hook to be async-aware, which may need changes to the hook execution mechanism.
3. **Using a message queue**: Buffer messages and send them in batches, reducing network overhead but adding complexity.
**Additional context**
Use cases for this feature:
- **Performance-critical agents**: Agents in production that need low latency responses
- **High-frequency agents**: Agents that generate many messages where network overhead accumulates
- **Privacy-sensitive agents**: Agents handling data that should not be sent to Studio
- **Offline/unreliable network**: Avoid blocking when Studio is unreachable
The async approach would also prevent the current issue where a slow or unresponsive Studio server can cause agent timeouts or degraded user experience.
Hướng dẫn đóng góp
Đánh giá
Issue này chưa được đánh giá.