类 ToolExecutionContext

java.lang.Object
io.agentscope.core.tool.ToolExecutionContext

public class ToolExecutionContext extends Object
Facade for passing custom POJOs to tool methods via priority-based resolution.

Two-layer architecture: External interface + Storage layer (ContextStore).

Priority chain: Call → Agent → Toolkit → Spring (highest to lowest)

Example:


 // Register custom POJO
 ToolExecutionContext context = ToolExecutionContext.builder()
     .register(new UserContext("user123"))
     .build();

 // Auto-injected by type in tool methods
 @Tool
 public ToolResultBlock myTool(UserContext ctx) {
     return ToolResultBlock.text(ctx.getUserId());
 }
 
另请参阅:
  • 方法详细资料

    • get

      public <T> T get(String key, Class<T> type)
      Retrieves an object by key and type (for multi-instance scenarios).
      类型参数:
      T - The object type
      参数:
      key - The key identifying the instance
      type - The class type to retrieve
      返回:
      The object instance, or null if not found
    • get

      public <T> T get(Class<T> type)
      Retrieves an object by type only (for singleton scenarios).
      类型参数:
      T - The object type
      参数:
      type - The class type to retrieve
      返回:
      The object instance, or null if not found
    • contains

      public boolean contains(String key, Class<?> type)
      Checks whether an object with the specified key and type exists in any store.
      参数:
      key - The key identifying the instance
      type - The class type to check
      返回:
      true if any store contains the object, false otherwise
    • contains

      public boolean contains(Class<?> type)
      Checks whether an object of the specified type exists in any store (regardless of key).
      参数:
      type - The class type to check
      返回:
      true if any store contains the object, false otherwise
    • getStores

      public List<ContextStore> getStores()
      Gets all stores in priority order.
      返回:
      Unmodifiable list of stores (never null, may be empty)
    • merge

      public static ToolExecutionContext merge(ToolExecutionContext... contexts)
      Merges multiple contexts into priority-based resolution chain.

      Earlier contexts have higher priority.

      参数:
      contexts - The contexts to merge, in priority order (highest first)
      返回:
      A new merged context
    • builder

      public static ToolExecutionContext.Builder builder()
      Creates a new builder for constructing ToolExecutionContext instances.
      返回:
      A new builder
    • empty

      public static ToolExecutionContext empty()
      Creates an empty context.
      返回:
      An empty ToolExecutionContext
    • equals

      public boolean equals(Object o)
      覆盖:
      equals 在类中 Object
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 Object
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object