agentscope-ai / agentscope-ai/agentscope
[Bug]: Model card's context_size is ignored by the app service chat model factory
- Linguagem predominante
- Python
- Estrelas
- 31.6k
- Forks
- 3.5k
- Merge médio
- 1d 16h
- PRs com merge (30d)
- 103
Descrição
### Prerequisites
- [x] I have searched the existing [issues](https://github.com/agentscope-ai/agentscope/issues) and [discussions](https://github.com/agentscope-ai/agentscope/discussions), and this is not a duplicate.
- [x] This is a bug, not a usage question. (For questions, please use [Discussions](https://github.com/agentscope-ai/agentscope/discussions/new?category=general) instead.)
### Background / Description
`get_model()` in `agentscope/app/_service/_model.py` builds the chat model with only `credential`, `model` and `parameters`. The matching model card's `context_size` is never forwarded to the constructor, so every chat model silently falls back to its per-provider class default.
Model cards declare much larger windows than those defaults. For example, the DeepSeek card (`deepseek-v4-flash`) declares `context_size: 1000000`, while `DeepSeekChatModel.__init__` defaults to `65536` — about 6.5% of the real window.
This is not cosmetic. `Agent` derives every context-compression threshold from `self.model.context_size` (`agent/_agent.py`, e.g. `trigger_ratio * self.model.context_size`), so an under-reported value makes compression fire far too early. The same applies to the fallback chat model, which goes through the same factory.
Evidence that this is an oversight rather than intended: the sibling embedding path in the same package does forward it. `app/_service/_embedding.py` looks up the matching card and passes `card.context_size` into the constructor. The chat path looks up the very same card but only uses it to override `formatter.input_types`. In addition, `CONTRIBUTING.md` §Chat Model lists `context_size` as a required model card field, so the declared value is meant to be authoritative.
This affects every provider whose card value differs from the class default, not just DeepSeek — e.g. DashScope (131072 vs 10000000 for `qwen-long`) and Anthropic (200000 vs 1000000 for the Claude 5 / 4.6+ cards).
The card's `output_size` is likewise never read on the chat path.
### Error Messages
```shell
No exception is raised — the defect is silent and only manifests as premature context compression.
Observed by running the reproduction below against agentscope 2.0.8:
card declares: 1000000
constructed model has: 65536
```
### Steps to Reproduce
import inspect
from agentscope.model._deepseek import DeepSeekChatModel
### What the model card declares
for card in DeepSeekChatModel.list_models():
print(card.name, card.context_size)
### deepseek-v4-flash 1000000
### What the constructor falls back to
print(
inspect.signature(DeepSeekChatModel.__init__)
.parameters["context_size"].default
)
### 65536
### get_model() never passes it:
### model = model_cls(
### credential=credential,
### model=config.model,
### parameters=parameters,
### )
### -> `context_size` does not appear anywhere in get_model()'s source.
### Environment
- AgentScope Version: 2.0.8
- Python Version: 3.14.5
- OS: Windows 11 Pro
Guia de contribuição
Direção de pesquisa
Start at `agentscope/app/_service/_model.py` in `get_model()` where `model_cls(...)` is currently called with only `credential`, `model`, and `parameters`. Compare this with `agentscope/app/_service/_embedding.py`, which forwards `card.context_size`, and with chat model constructors such as `agentscope/model/_deepseek.py` for expected constructor fields. Verify completion by checking the factory behavior with a known card (for example `deepseek-v4-flash`) and confirming it no longer falls back to class defaults for `context_size`/`output_size`.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- backend-api-design
- Tipo de issue
- Bug
- Dificuldade
- 1/5
- Tempo estimado
- Menos de uma hora
- Status de atividade
- Ativa
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 84/100