类 RuntimeContext

java.lang.Object
io.agentscope.core.agent.RuntimeContext

public class RuntimeContext extends Object
Per-call metadata for an agent run: session-scoped fields plus a thread-safe attribute bag and an optional ToolExecutionContext (tool-POJO / DI layer).

Attributes are not persisted. Hooks and tools may read and update the same instance for the duration of a single call.

  • 方法详细资料

    • empty

      public static RuntimeContext empty()
      Shallow, mutable empty context (null session fields, empty attribute maps, no tool context).
    • getSessionId

      public String getSessionId()
    • getUserId

      public String getUserId()
    • getAgentState

      public AgentState getAgentState()
      Returns the call-scoped AgentState for this run, or null when accessed outside of an active call(). Prefer this over agent.getAgentState() from middlewares and tools so the correct session's state is used under concurrency.
    • setAgentState

      public void setAgentState(AgentState agentState)
      Installs the call-scoped AgentState. Called by the agent at call entry; not part of the public tool/middleware contract.
    • resolveAgentState

      public static AgentState resolveAgentState(RuntimeContext ctx, Agent fallbackAgent)
      Resolves the live AgentState for the current call, preferring the call-scoped state carried on ctx (concurrency-safe) and falling back to fallbackAgent's state only when the context carries none. Middlewares and tools should use this instead of calling agent.getAgentState() directly, which is not call-scoped under concurrency.
      参数:
      ctx - the per-call runtime context (may be null)
      fallbackAgent - the agent to fall back to (may be null)
      返回:
      the resolved AgentState, or null if neither source provides one
    • getToolExecutionContext

      public ToolExecutionContext getToolExecutionContext()
      Returns the tool execution context provided at build time, if any.

      Does not include runtime attribute projections; use asToolExecutionContext().

    • get

      public <T> T get(String key)
    • put

      public void put(String key, Object value)
    • get

      public <T> T get(Class<T> type)
    • put

      public <T> void put(Class<T> type, T value)
    • get

      public <T> T get(String key, Class<T> type)
    • put

      public <T> void put(String key, Class<T> type, T value)
    • builder

      public static RuntimeContext.Builder builder(RuntimeContext source)
    • getExtra

      public Map<String,Object> getExtra()
      View of string-keyed attributes; mutating the returned map affects this context.

      Typed get(Class) values are not included; use type-based accessors.

    • asToolExecutionContext

      public ToolExecutionContext asToolExecutionContext()
      Merges this context's data into a ToolExecutionContext for tool invocations.

      Order: this instance is registered and exposed first (highest priority in ToolExecutionContext.merge(io.agentscope.core.tool.ToolExecutionContext...), then a ContextStore for typed and string attributes, then stores from the nested getToolExecutionContext() (if any).

    • builder

      public static RuntimeContext.Builder builder()