Interface RuntimeContextCustomizer
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
RuntimeContext of an Agent Protocol task run.
The store always exposes the caller's context.attributes as one map under AgentProtocolConstants.RUNTIME_CONTEXT_ATTRIBUTES_KEY, which cannot collide with framework keys.
Register customizer beans (ordered with @Order) to go further — promote selected
attributes to their own keys, translate them into typed values, or derive attributes of your own:
@Bean
RuntimeContextCustomizer tenantContext() {
return (request, builder) -> {
String tenant = request.attributeString("tenant");
if (tenant != null) {
builder.put(TenantInfo.class, tenantService.load(tenant));
}
};
}
Customizers run after the namespaced injection and in bean order, so a later one overrides an
earlier one. They are trusted: unlike flatten(String...), a hand-written customizer may
write any key, including framework-reserved ones.
-
Method Summary
Modifier and TypeMethodDescriptionvoidcustomize(AgentRequest request, io.agentscope.core.agent.RuntimeContext.Builder builder) Adjusts the context being built forrequest.static RuntimeContextCustomizerCustomizer that copies the listedcontext.attributesentries to top-level runtime context keys of the same name, for tools that read a plain key such asctx.get("tenant").
-
Method Details
-
customize
Adjusts the context being built forrequest. Called once per run — on submit and again on every resume. -
flatten
Customizer that copies the listedcontext.attributesentries to top-level runtime context keys of the same name, for tools that read a plain key such asctx.get("tenant").Only the listed names are copied, and names the framework itself reads (see
AgentProtocolConstants.isReservedRuntimeContextKey(String)) are skipped with a warning, so a caller cannot hijack routing keys likeagentIdby naming an attribute after one.
-