agentscope-ai / agentscope-ai/agentscope
[Bug]: RealtimeAgent does not reconnect for text input after disconnect
- Vorherrschende Sprache
- Python
- Sterne
- 31.5k
- Forks
- 3.5k
- Ø Merge
- 1 T. 23 Std.
- Gemergte PRs (30 T.)
- 95
Beschreibung
## Background / Description
`RealtimeAgent` reconnects a disconnected provider when the next audio frame arrives, but text input does not use the same reconnect path.
After a provider timeout, `RealtimeAgent.send()` appends the text message to `state.context` and then calls `model.push_text()`. The realtime adapter raises `ModelDisconnectedError("Not connected.")`, so no reconnect occurs and the message remains in context even though it was not delivered.
This affects direct `agent.send("...")` calls and `ControlFrameType.TEXT` frames. A later audio reconnect includes the undelivered text in the generated conversation-history instructions, which can duplicate or reorder the user's input when it is retried.
Expected behavior: text input should reconnect a supported provider and be delivered once, or fail without recording an undelivered message.
Actual behavior: it raises and leaves the failed message in agent context.
## Error Messages
```shell
agentscope.realtime.ModelDisconnectedError: Not connected.
```
After the exception, the submitted text is still present in `agent.state.context`.
## Steps to Reproduce
1. Create a `RealtimeAgent` with a provider whose `supports_text_input` is `True` (OpenAI or Gemini).
2. Connect the agent and let the provider session end, or simulate a `SessionEndedEvent`.
3. Wait until the agent marks itself disconnected.
4. Call `await agent.send("hello")`, or send a transport text control frame.
5. Observe `ModelDisconnectedError("Not connected.")`.
6. Inspect `agent.state.context`; the undelivered `"hello"` message is present.
A deterministic test can use the existing scripted realtime-model test double and make `push_text()` reject calls while disconnected.
## Environment
- AgentScope Version: 2.0.8 (`main` at `0fe41c07`)
- Python Version: 3.12.14
- OS: macOS 26.6.2 arm64
## 中文
`RealtimeAgent` 会在下一帧音频到达时重连已经断开的 provider,但文本输入没有经过相同的重连路径。
provider 超时后,`RealtimeAgent.send()` 会先把文本写入 `state.context`,再调用 `model.push_text()`。realtime adapter 随后抛出 `ModelDisconnectedError("Not connected.")`,因此连接没有恢复,文本也没有送达,但失败的消息已经留在上下文中。
该问题同时影响直接调用 `agent.send("...")` 和 `ControlFrameType.TEXT`。之后由音频触发重连时,未送达文本会进入 conversation-history instructions;用户重试后可能造成输入重复或顺序错误。
预期行为:支持文本输入的 provider 应在发送前重连并且只接收一次文本;如果失败,不应记录未送达消息。
### 复现步骤
1. 使用 `supports_text_input=True` 的 provider(OpenAI 或 Gemini)创建 `RealtimeAgent`。
2. 连接后让 provider session 结束,或模拟 `SessionEndedEvent`。
3. 等待 agent 标记为断线。
4. 调用 `await agent.send("hello")`,或发送 transport 文本控制帧。
5. 可以观察到 `ModelDisconnectedError("Not connected.")`。
6. 检查 `agent.state.context`,可以看到未送达的 `"hello"` 仍在其中。
Beitragsleitfaden
Bewertung
Dieses Issue wurde noch nicht bewertet.