agentscope-ai / agentscope-ai/agentscope
[Bug]: structured output reply loses model usage
- Langage dominant
- Python
- Étoiles
- 31.6k
- Forks
- 3.5k
- Merge moyen
- 1 j 16 h
- PR mergées (30 j)
- 103
Description
## Problem
When `Agent.reply(..., structured_schema=...)` generates a structured output, the returned `Msg.usage` is `None` even when the model responses contain token usage.
```text
Model call 1: usage = 80 input / 40 output
Model call 2: usage = 100 input / 50 output
|
v
Current reply context: usage = 180 input / 90 output
|
v
Final structured Msg: usage = None <-- usage is lost while rebuilding it
```
Ordinary text replies expose usage correctly, but structured-output replies do not.
## Reproduction
```python
result = await agent.reply(
UserMsg(name="user", content="Weather in Hangzhou?"),
structured_schema=WeatherReport,
)
assert result.structured_output is not None
assert result.usage is not None # Fails with the current implementation
```
No exception is raised. The issue is that usage already recorded for the current reply is not propagated to the final structured-output message.
## Expected behavior
The returned structured-output `Msg.usage` should contain the accumulated usage from every model call in the current reply, including input, output, and cache tokens.
## Impact
Applications that use `Msg.usage` for token, cost, or model-call metrics receive an incorrect empty value for structured-output replies.
## Scope
This is a Python Agent message-construction issue. It does not require changes to model adapters, usage accumulation, or public API design.
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Start by tracing the `Agent.reply(..., structured_schema=...)` code path to where the structured `Msg` is rebuilt from model call results. Compare this path with normal text replies and inspect where usage totals are accumulated versus where the final message object is created; the usage copy is likely missing there. Run the reproduction snippet from the issue to confirm the failure, then re-run it to verify `result.usage` is populated with accumulated input/output/cache counts in the final structured response. Done when structured replies and ordinary replies expose matching usage propagation behavior.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- backend
- Type d'issue
- Bug
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Activité
- Active
- Clarté
- Clairement spécifiée
- Accessibilité débutants
- 75/100