agentscope-ai / agentscope-ai/agentscope-java

[Bug]:在MiddlewareBase的onAgent中,agent参数没有getRuntimeContext

未關閉
#1,672 4 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
area/core/agent bug
主要語言
Java
星號
5.6k
分支
1.3k
平均合併
4 天 12 小時
30 天內合併 PR
77

描述

**Describe the bug**
The `Agent` object passed as a parameter into the `onAgent` method of `MiddlewareBase` lacks the `getRuntimeContext()` method (or the runtime context is null/inaccessible). This prevents middleware implementations from accessing or modifying the runtime context during the agent's execution lifecycle.

**To Reproduce**
Steps to reproduce the behavior:

1. Implement a custom middleware by implementing the `MiddlewareBase` interface.
2. Override the `onAgent` method and attempt to access the runtime context via the `agent` parameter:
```java
@Override
public Flux onAgent(Agent agent, AgentInput input, Function> next) {
// Attempting to get runtime context here fails or returns null
// e.g., agent.getRuntimeContext()
return next.apply(input);
}
```
3. Register this middleware and trigger an agent execution.
4. See the missing method error or null pointer exception.

**Expected behavior**
The `Agent` parameter provided in the `onAgent` middleware hook should expose a valid `getRuntimeContext()` method (or equivalent API), allowing developers to retrieve and manipulate the runtime context for purposes like logging, tracing, or modifying agent behavior dynamically.

**Error messages**
`[Please paste the exact compilation error, NullPointerException, or missing method exception stack trace here]`

**Environment (please complete the following information):**

- AgentScope-Java Version: `2.0.0-RC1`
- Java Version: `25`
- OS: `Windows`

**Additional context**
This issue blocks the implementation of custom middleware that relies on runtime context (e.g., for security checks, multi-tenant isolation, or dynamic prompt injection as mentioned in the AgentScope 2.0 middleware documentation). Any workaround or timeline for fixing this API gap would be highly appreciated.

Image

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。