agentscope-ai / agentscope-ai/agentscope
[Bug]: Context compression aborts the agent on recoverable structured-output schema validation errors
- Linguagem predominante
- Python
- Estrelas
- 31.5k
- Forks
- 3.5k
- Merge médio
- 1d 23h
- PRs com merge (30d)
- 95
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
When an agent reaches the context-compression threshold, `Agent._compress_context_impl()` calls `ChatModelBase.generate_structured_output()` with the compression summary schema.
A model can return an almost valid tool call whose field name deviates slightly from the schema (for example, `task_over` instead of the required `task_overview`). The resulting `jsonschema.ValidationError` is propagated immediately and aborts the entire agent invocation.
This happened in a long-running agent using the default `SummarySchema`. All other required fields were present; only `task_overview` was misspelled.
### Actual behavior
- `jsonschema.validate()` raises `ValidationError`.
- The error is not included in `_get_retryable_exceptions()`, so `generate_structured_output()` does not retry.
- `_compress_context_impl()` retries only when `context_overflow=True`; a schema-validation failure is re-raised.
- The whole agent invocation terminates.
### Expected behavior
Structured-output validation failures should be treated as recoverable format errors. AgentScope should retry a small number of times with concise validation feedback (missing/invalid fields and the expected schema). Only exhausted retries should raise a typed compression/structured-output error.
A one-field format deviation should not terminate a long-running agent. The retry should be generic rather than adding a special-case alias for one observed typo.
### Relevant code paths
- `agentscope/agent/_config.py`: `SummarySchema`
- `agentscope/model/_base.py`: `generate_structured_output()` and schema validation
- `agentscope/agent/_agent.py`: `_compress_context_impl()`
### Error Messages
```shell
'task_overview' is a required property
Failed validating 'required' in schema:
required:
- task_overview
- current_state
- important_discoveries
- next_steps
- context_to_preserve
Model tool-call input:
{
"task_over": "...",
"current_state": "...",
"important_discoveries": "...",
"next_steps": "...",
"context_to_preserve": "..."
}
```
### Steps to Reproduce
1. Configure an agent with context compression enabled and enough context to exceed `trigger_ratio`.
2. Make the compression model return a `generate_structured_output` tool call with this input:
```json
{
"task_over": "task summary",
"current_state": "current state",
"important_discoveries": "discoveries",
"next_steps": "next steps",
"context_to_preserve": "context"
}
```
3. Run:
```python
await agent.compress_context()
```
4. Observe that the first `jsonschema.ValidationError` escapes immediately and the agent is aborted, even when model retries are configured.
A regression test can use a mock model that returns an invalid summary on the first structured-output call and a valid summary on the second. The expected result is two calls and successful compression; the current behavior raises after the first call.
### Environment
- AgentScope Version: 2.0.5
- Python Version: 3.12
- OS: macOS
- Model: qwen3.7-max
- Streaming: enabled
Guia de contribuição
Avaliação
Esta issue ainda não foi avaliada.