Class SandboxIsolationKey

java.lang.Object
io.agentscope.harness.agent.sandbox.SandboxIsolationKey

public final class SandboxIsolationKey extends Object
Immutable key that uniquely identifies a sandbox state slot for a given IsolationScope.

Use resolve(io.agentscope.harness.agent.IsolationScope, io.agentscope.core.agent.RuntimeContext, java.lang.String) to obtain a key from a RuntimeContext. The result is Optional.empty() when the required context field is absent (e.g., USER scope without a userId), meaning state lookup should be skipped.

  • Method Details

    • resolve

      public static Optional<SandboxIsolationKey> resolve(IsolationScope scope, io.agentscope.core.agent.RuntimeContext ctx, String agentId)
      Resolves an isolation key from the given scope, runtime context, and agent ID.

      Resolution rules:

      • SESSION – requires a non-null sessionId; value = sessionId. Returns empty if absent.
      • USER – uses userId when present. When userId is absent, falls back to SESSION scope using the sessionId. Returns empty only when both userId and sessionId are absent.
      • AGENT – value = agentId (always present).
      • GLOBAL – value = "__global__" (always present).
      • null scope – treated as USER.
      Parameters:
      scope - the desired isolation scope; null defaults to USER
      ctx - the runtime context for the current call; may be null
      agentId - the agent name resolved at build time; must not be null
      Returns:
      resolved key, or empty if the required context field is absent
    • getScope

      public IsolationScope getScope()
      Returns the isolation scope.
      Returns:
      scope
    • getValue

      public String getValue()
      Returns the discriminating value within the scope (e.g. session id, user id, agent name).
      Returns:
      value string
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object