RuntimeContextCustomizer
@FunctionalInterface public interface RuntimeContextCustomizer
io/agentscope/extensions/agentprotocol/RuntimeContextCustomizer.java:50–92定义运行时上下文 Customizer契约的接口。位于 io.agentscope.extensions.agentprotocol 包。核心成员包括 customize、flatten。
Hook for shaping the 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
| 方法Method | 说明Description |
|---|---|
public void customize(AgentRequest request, RuntimeContext.Builder builder) | 执行 `customize` 方法。 Adjusts the context being built for `request`. |
static public RuntimeContextCustomizer flatten(String... keys)static | 设置该参数。 Customizer that copies the listed `context.attributes` entries to top-level runtime
context keys of the same name, for tools that read a plain key such as `
ctx.get("tenant")`. |
方法详情Method Detail
customize
public void customize(AgentRequest request, RuntimeContext.Builder builder)
执行 customize 方法。
Adjusts the context being built for request.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
request | AgentRequest | 请求(类型 `AgentRequest`)。The request. |
builder | RuntimeContext.Builder | 构建器(类型 `RuntimeContext.Builder`)。The builder. |
io/agentscope/extensions/agentprotocol/RuntimeContextCustomizer.java:57flatten
static public RuntimeContextCustomizer flatten(String... keys)
设置该参数。
Customizer that copies the listed context.attributes entries to top-level runtime context keys of the same name, for tools that read a plain key such as ctx.get("tenant").
| 名称Name | 类型Type | 说明Description |
|---|---|---|
keys varargs | String... | 密钥(类型 `String...`)。The keys. |
RuntimeContextCustomizerio/agentscope/extensions/agentprotocol/RuntimeContextCustomizer.java:68–91