agentscope-ai / agentscope-ai/agentscope
[Bug]: structured output reply loses model usage
- Lingua principale
- Python
- Stelle
- 31.6k
- Fork
- 3.5k
- Merge medio
- 1g 16h
- PR unite (30g)
- 103
Descrizione
## 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.
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- backend
- Tipo di issue
- Bug
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Stato di attività
- Attiva
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 75/100