agentscope-ai / agentscope-ai/agentscope-runtime
[Bug] BaseResponse.created_at shares class-level default across all instances
- 主要语言
- Python
- 星标
- 863
- 派生
- 168
- PR 合并指标
- 30 天内没有已合并 PR
描述
## Description
`BaseResponse.created_at` uses a class-level default value, causing all instances to share the same timestamp evaluated at module import time.
## Steps to reproduce
Send two consecutive chat messages and inspect `created_at` on each `BaseResponse`.
```
import time
from agentscope_runtime.engine.schemas.agent_schemas import BaseResponse
if __name__ == "__main__":
# 实测
a = BaseResponse()
print(f" 第 1 个实例 (sleep 前): {a.created_at}")
time.sleep(2)
b = BaseResponse()
print(f" 第 2 个实例 (sleep 2s 后): {b.created_at}")
print()
print(f" 差值: {b.created_at - a.created_at}s | 相同? {a.created_at == b.created_at}")
```
## Expected
Each response has its own creation timestamp.
## Actual
All responses have the identical `created_at` value.
## Root cause
```python
# agent_schemas.py line 888
created_at: int = int(datetime.now().timestamp())
Pydantic evaluates the = expression once at class definition time, so every instance inherits the same stale value.
Fix
created_at: int = Field(
default_factory=lambda: int(datetime.now().timestamp()),
)
default_factory defers evaluation to instance creation time.
贡献指南
评估
这个 Issue 还没有评估数据。