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.

@FunctionalInterface public interface RuntimeContextCustomizer
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

    Modifier and Type
    Method
    Description
    void
    customize(AgentRequest request, io.agentscope.core.agent.RuntimeContext.Builder builder)
    Adjusts the context being built for request.
    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").
  • Method Details

    • customize

      void customize(AgentRequest request, io.agentscope.core.agent.RuntimeContext.Builder builder)
      Adjusts the context being built for request. Called once per run — on submit and again on every resume.
    • flatten

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

      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 like agentId by naming an attribute after one.