AS AgentScopeAPI 手册 / API Reference

RuntimeContextCustomizer

@FunctionalInterface public interface RuntimeContextCustomizer
源码Source 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.

参数Parameters
名称Name类型Type说明Description
requestAgentRequest请求(类型 `AgentRequest`)。The request.
builderRuntimeContext.Builder构建器(类型 `RuntimeContext.Builder`)。The builder.
源码Source io/agentscope/extensions/agentprotocol/RuntimeContextCustomizer.java:57

flatten

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").

参数Parameters
名称Name类型Type说明Description
keys varargsString...密钥(类型 `String...`)。The keys.
返回Returns RuntimeContextCustomizer
返回RuntimeContextCustomizer。Returns runtime context customizer.
源码Source io/agentscope/extensions/agentprotocol/RuntimeContextCustomizer.java:68–91
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.