agentscope-ai / agentscope-ai/agentscope-runtime
[Bug] BaseResponse.created_at shares class-level default across all instances
- Lingua principale
- Python
- Stelle
- 863
- Fork
- 168
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
## 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.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.