[Feature]: Add framework-level feedback context and memory calibration extension points
Feature request
Problem
We are building a production application on AgentScope Java 2.0.3 with HarnessAgent. We need to collect thumbs up or thumbs down feedback for individual assistant messages. A dislike may include a reason and an explicit correction supplied by the user. The goal is to improve future responses and eventually calibrate long-term memory without allowing an incorrect response to become a durable memory.
There is currently no product-level API that models message feedback and feeds approved feedback back into runtime context. The training FeedbackRequest type is not a suitable online product abstraction for this use case.
Constraints
Feedback must not be sent as a synthetic user message. It must not start another HarnessAgent run or acquire the current session generation lock. The application should persist feedback asynchronously and make approved, bounded feedback context available during a later invocation. The normal memory flush and consolidation lifecycle should remain owned by AgentScope.
Directly editing memory files or automatically overwriting memory after one dislike would be unsafe. Feedback text is untrusted user input and needs scope isolation, size limits, expiry, conflict handling, approval, and revocation.
Proposed extension
Could AgentScope provide an optional generic extension point similar to the following conceptual API?
public interface FeedbackContextProvider {
List<FeedbackContext> getContexts(FeedbackContextRequest request);
}
public record FeedbackContextRequest(
String userId,
String tenantId,
String agentId,
String sessionId,
int maxItems,
int maxTokens) {}
A framework-supplied middleware could call the provider during the system prompt phase, append a bounded structured context, and degrade to a no-op when the provider fails. The application would own the database, HTTP endpoint, audit workflow, approval policy, and storage implementation. Only application-approved contexts would be returned.
The extension should ideally support:
- user and agent scoped context
- maximum item and token budgets
- expiration and versioning
- no-op behavior when no provider is configured
- no blocking of the main agent invocation
- clear placement in core, harness, or extensions
Alternatives considered
- Send feedback as a synthetic user message. This pollutes the transcript and can corrupt memory extraction.
- Start an isolated agent thread for every feedback action. This adds unnecessary sessions, loses the original execution semantics, and still does not define safe memory governance.
- Keep everything application-specific. This works locally, but a small generic provider and middleware contract could be useful for other AgentScope applications without imposing a database or UI model.
Relationship to existing memory work
This proposal does not replace MemoryConsolidator or the HarnessAgent memory cleanup work discussed in #2930. It is an upstream extension point for external feedback context. The application can use the official memory configuration and maintenance lifecycle while keeping feedback candidates in an application-owned review store.
Questions
- Is feedback context and memory calibration an appropriate framework-level extension point?
- Should the provider and middleware live in agentscope-core, agentscope-harness, or an extension module?
- Is RuntimeContext the right place to obtain user, tenant, agent, and session scope?
- Should this be related to the existing training feedback DTO, or remain a separate online runtime concept?
We would be happy to implement a small test-driven PR after maintainers confirm the API boundary and module placement. The proposed PR would contain only generic interfaces, a default no-op implementation, middleware behavior, tests, and documentation. It would not include application database tables, REST APIs, UI, or tenant-specific policy.
Environment
- AgentScope Java 2.0.3
- HarnessAgent
- Java 17
Issue Evaluation
Category: enhancement | Status: Evaluated — no new framework hook needed; module placement is a maintainer call (verified against main @ 8ca0080)
Your four questions, answered from the code.
-
Is a new extension point needed? No — the seam you describe already exists.
MiddlewareBaseexposes a dedicated system-prompt pipeline hook,onSystemPrompt(Agent, RuntimeContext, String) -> Mono<String>(agentscope-core/src/main/java/io/agentscope/core/middleware/MiddlewareBase.java:158), applied once percall()viaReActAgent.seedSystemMsg→applySystemPromptMiddlewares(agentscope-core/src/main/java/io/agentscope/core/ReActAgent.java:761-808). It is registered withReActAgent.Builder.middleware(...)(ReActAgent.java:4963) /HarnessAgent.Builder.middleware(...)(HarnessAgent.java:1602), ordered byorder()descending. So an application-ownedFeedbackContextMiddleware implements MiddlewareBaseneeds zero framework changes today — that is the "Alternatives considered #3" path, and it is fully supported rather than a workaround. Existing first-party precedents for exactly this shape:TaskReminderMiddleware,DynamicSkillMiddleware(core) andWorkspaceContextMiddleware,PlanModeMiddleware(harness). -
Where would a first-party version live? Determinable from the current layering: the interface + default no-op belongs in
agentscope-core(io.agentscope.core.middleware) only if the project wants to own it, while concrete provider implementations follow the established pattern ofagentscope-extensions-mem/*(Mem0 / Bailian / ReMe live outside core and implement the coreLongTermMemorySPI). If the intent is to compose withMEMORY.mdand workspace budgeting,agentscope-harnessis the natural host, since the memory lifecycle you explicitly want to stay framework-owned (MemoryFlushMiddleware→MemoryFlushManager→MemoryConsolidator) is harness-only and is not a prompt-injection point. -
Is
RuntimeContextthe right scope source? Partially.userIdandsessionIdare first-class (RuntimeContext.getUserId()/getSessionId());agentIdis reachable from theAgentargument passed into the hook, not from the context.tenantIdis absent — it only exists if an application puts it in the attribute bag (put/get) or via an extension customizer (e.g. the agent-protocolRuntimeContextCustomizer). As written,FeedbackContextRequesttherefore over-promises on one of its four fields; a first-party record should either droptenantIdor define how it is resolved. -
Relationship to the training
FeedbackRequest? Keep it separate.io.agentscope.core.training.backend.dto.FeedbackRequest(msgIds,reward,taskId,runId, inagentscope-extensions-training) is consumed only byTrinityClient.feedback(...)in the offline RL pipeline — it has no online prompt path and does not carry corrections or approval state. The nearest online analogue is the coreLongTermMemorySPI (record(List<Msg>)/retrieve(Msg)), which your proposal deliberately is not, because you need "reviewed, bounded, expiring context" rather than "durable memory write".
Design blockers a first-party SPI would have to settle (all concrete, none fatal):
- Failure isolation.
applySystemPromptMiddlewarescomposes withflatMapand has noonErrorResume, so a throwing provider currently fails the whole agent call. Your "degrade to a no-op when the provider fails" requirement has to be implemented inside the middleware, not assumed from the pipeline. - Budget enforcement. The hook receives no token budget;
maxItems/maxTokensmust be enforced by the middleware itself.WorkspaceContextMiddleware.onSystemPrompt(estimateTokens+maxContextTokenstrimming) is the only in-repo precedent to copy. - Blocking I/O. The hook runs on the call path once per
call(); a provider doing DB/HTTP calls mustsubscribeOn(Schedulers.boundedElastic())the same wayWorkspaceContextMiddlewareandMemoryFlushMiddlewaredo. - Untrusted text. Approval/revocation is your side's job (correctly), but the framework would also need a delimiter/escaping convention for correction text entering the system prompt — prompt-injection surface is not addressed anywhere today.
Feasibility: feasible, low-risk, additive. Compatibility: non-breaking as long as the default is "no provider configured → no-op". Priority: low-medium for the framework — the capability gap is real, but there is already a supported path for it, so the question is whether the project wants to standardize the contract, not whether users are blocked.
No bot-generated PR here: the only framework-visible decision is whether to adopt a first-party SPI at all (and where), which is a maintainer call. If maintainers want a starter patch (interface + no-op default + middleware + tests + docs, exactly as you scoped it), a maintainer can reply /approve on this issue and it will be generated against the points above.
@wahllllll — you offered to send a test-driven PR; the shortest unblocked route today is the app-owned middleware, so you can prototype without waiting on this decision.
Automated evaluation by github-manager-bot
Status: 72 h feedback window expired — no automated PR will be generated, the proposal window here is closed
The evaluation CTA above (5756146304, posted 2026-09-21T06:11:46Z) reached its 72-hour feedback limit at 2026-09-24T06:11:46Z with no own-line /approve, /revise, or /reject command in the thread, so per our workflow we skip PR generation and no competing PR will be filed from this proposal window. No action is needed from anyone.
This is a timing stand-down, not a verdict on the idea. The evaluation stands as recorded: the seam you asked about already exists today — MiddlewareBase.onSystemPrompt(Agent, RuntimeContext, String) (agentscope-core/src/main/java/io/agentscope/core/middleware/MiddlewareBase.java:158), applied per call() through ReActAgent.seedSystemMsg → applySystemPromptMiddlewares and registered via ReActAgent.Builder.middleware(...) / HarnessAgent.Builder.middleware(...). An application-owned FeedbackContextMiddleware therefore needs zero framework changes, with TaskReminderMiddleware / WorkspaceContextMiddleware / PlanModeMiddleware as first-party shapes to copy.
What remains genuinely undecided is the framework-level question this issue posed — whether the project wants to own a first-party contract for "reviewed, bounded, expiring" context injection, and in which module. That is a maintainer call, not a gap we can close by filing a PR: a starter SPI (interface + no-op default + middleware + tests + docs) would still have to settle the four points named in the evaluation, none of which are answered by the existing hook alone:
- Failure isolation —
applySystemPromptMiddlewarescomposes withflatMapand has noonErrorResume, so a throwing provider fails the whole agent call; "degrade to a no-op" must live inside the middleware. - Budget enforcement — the hook receives no token budget;
maxItems/maxTokensmust be enforced by the middleware, withWorkspaceContextMiddleware(estimateTokens+maxContextTokens) the only in-repo precedent. - Blocking I/O — a provider doing DB/HTTP work must
subscribeOn(Schedulers.boundedElastic())the wayWorkspaceContextMiddlewareandMemoryFlushMiddlewaredo. - Untrusted text — there is no delimiter/escaping convention for correction text entering the system prompt; the prompt-injection surface is unaddressed today.
If a maintainer decides the project should own the contract after all, a one-line approve reply on this issue is enough to have the spec regenerated and a PR drafted against the four points above; the window closing now only means the bot stops waiting. In the meantime the app-owned middleware path is unblocked and can be prototyped without waiting on this decision.
Automated by github-manager-bot
Closing this: the evaluation above concluded that no new framework hook is needed, and the 72-hour proposal window has expired. Happy to reopen if a maintainer wants to revisit the module-placement question.