Class ActionContext

java.lang.Object
com.google.genkit.core.ActionContext

public class ActionContext extends Object
ActionContext provides context for action execution including tracing and flow information. It is passed to all action executions and carries request-scoped state.
  • Constructor Details

    • ActionContext

      public ActionContext(SpanContext spanContext, String flowName, String spanPath, Registry registry, String sessionId, String threadName)
      Creates a new ActionContext.
      Parameters:
      spanContext - the tracing span context, may be null
      flowName - the name of the enclosing flow, may be null
      spanPath - the current span path for tracing
      registry - the Genkit registry
      sessionId - the session ID for multi-turn conversations
      threadName - the thread name for grouping related requests
    • ActionContext

      public ActionContext(SpanContext spanContext, String flowName, String spanPath, Registry registry)
      Creates a new ActionContext.
      Parameters:
      spanContext - the tracing span context, may be null
      flowName - the name of the enclosing flow, may be null
      spanPath - the current span path for tracing
      registry - the Genkit registry
    • ActionContext

      public ActionContext(SpanContext spanContext, String flowName, Registry registry)
      Creates a new ActionContext.
      Parameters:
      spanContext - the tracing span context, may be null
      flowName - the name of the enclosing flow, may be null
      registry - the Genkit registry
    • ActionContext

      public ActionContext(Registry registry)
      Creates a new ActionContext with default values.
      Parameters:
      registry - the Genkit registry
  • Method Details

    • getSpanContext

      public SpanContext getSpanContext()
      Returns the tracing span context.
      Returns:
      the span context, or null if tracing is not active
    • getFlowName

      public String getFlowName()
      Returns the name of the enclosing flow, if any.
      Returns:
      the flow name, or null if not in a flow context
    • getSpanPath

      public String getSpanPath()
      Returns the current span path for tracing.
      Returns:
      the span path, or null if not in a traced context
    • getRegistry

      public Registry getRegistry()
      Returns the Genkit registry.
      Returns:
      the registry
    • getSessionId

      public String getSessionId()
      Returns the session ID for multi-turn conversations.
      Returns:
      the session ID, or null if not set
    • getThreadName

      public String getThreadName()
      Returns the thread name for grouping related requests.
      Returns:
      the thread name, or null if not set
    • withFlowName

      public ActionContext withFlowName(String flowName)
      Creates a new ActionContext with a different flow name.
      Parameters:
      flowName - the new flow name
      Returns:
      a new ActionContext with the updated flow name
    • withSpanContext

      public ActionContext withSpanContext(SpanContext spanContext)
      Creates a new ActionContext with a different span context.
      Parameters:
      spanContext - the new span context
      Returns:
      a new ActionContext with the updated span context
    • withSpanPath

      public ActionContext withSpanPath(String spanPath)
      Creates a new ActionContext with a different span path.
      Parameters:
      spanPath - the new span path
      Returns:
      a new ActionContext with the updated span path
    • withSessionId

      public ActionContext withSessionId(String sessionId)
      Creates a new ActionContext with a session ID.
      Parameters:
      sessionId - the session ID
      Returns:
      a new ActionContext with the session ID
    • withThreadName

      public ActionContext withThreadName(String threadName)
      Creates a new ActionContext with a thread name.
      Parameters:
      threadName - the thread name
      Returns:
      a new ActionContext with the thread name
    • builder

      public static ActionContext.Builder builder()
      Creates a builder for ActionContext.
      Returns:
      a new builder