Package com.google.genkit.core
Class ActionContext
java.lang.Object
com.google.genkit.core.ActionContext
ActionContext provides context for action execution including tracing and flow information. It is
passed to all action executions and carries request-scoped state.
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionActionContext(Registry registry) Creates a new ActionContext with default values.ActionContext(SpanContext spanContext, String flowName, Registry registry) Creates a new ActionContext.ActionContext(SpanContext spanContext, String flowName, String spanPath, Registry registry) Creates a new ActionContext.ActionContext(SpanContext spanContext, String flowName, String spanPath, Registry registry, String sessionId, String threadName) Creates a new ActionContext.ActionContext(SpanContext spanContext, String flowName, String spanPath, Registry registry, String sessionId, String threadName, Map<String, Object> context) Creates a new ActionContext.ActionContext(SpanContext spanContext, String flowName, String spanPath, Registry registry, String sessionId, String threadName, Map<String, Object> context, Object resumed, Object originalInput) Creates a new ActionContext including resume-awareness fields. -
Method Summary
Modifier and TypeMethodDescriptionstatic ActionContext.Builderbuilder()Creates a builder for ActionContext.Returns the request-scoped user context.Returns the name of the enclosing flow, if any.Returns the tool request's original input (before any restart-replaced input), mirroring GoToolContext.OriginalInput.Returns the Genkit registry.Returns the resume metadata attached when this action is being re-invoked after an interrupt/restart, ornullon a normal invocation.Returns the session ID for multi-turn conversations.Returns the tracing span context.Returns the current span path for tracing.Returns the thread name for grouping related requests.booleanReturnstrueif this action is being re-invoked after an interrupt/restart (i.e.withContext(Map<String, Object> context) Creates a new ActionContext with the given request-scoped user context.withFlowName(String flowName) Creates a new ActionContext with a different flow name.withResumed(Object resumed, Object originalInput) Creates a new ActionContext carrying resume-awareness for a restarted tool call.withSessionId(String sessionId) Creates a new ActionContext with a session ID.withSpanContext(SpanContext spanContext) Creates a new ActionContext with a different span context.withSpanPath(String spanPath) Creates a new ActionContext with a different span path.withThreadName(String threadName) Creates a new ActionContext with a thread name.
-
Constructor Details
-
ActionContext
public ActionContext(SpanContext spanContext, String flowName, String spanPath, Registry registry, String sessionId, String threadName, Map<String, Object> context) Creates a new ActionContext.- Parameters:
spanContext- the tracing span context, may be nullflowName- the name of the enclosing flow, may be nullspanPath- the current span path for tracingregistry- the Genkit registrysessionId- the session ID for multi-turn conversationsthreadName- the thread name for grouping related requestscontext- the request-scoped user context (e.g.{"auth": {...}}), may be null
-
ActionContext
public ActionContext(SpanContext spanContext, String flowName, String spanPath, Registry registry, String sessionId, String threadName, Map<String, Object> context, Object resumed, Object originalInput) Creates a new ActionContext including resume-awareness fields.- Parameters:
spanContext- the tracing span context, may be nullflowName- the name of the enclosing flow, may be nullspanPath- the current span path for tracingregistry- the Genkit registrysessionId- the session ID for multi-turn conversationsthreadName- the thread name for grouping related requestscontext- the request-scoped user context (e.g.{"auth": {...}}), may be nullresumed- the resume metadata attached when this action is being re-invoked after an interrupt/restart (mirrors JSToolRunOptions.resumed/ GoToolContext.Resumed);nullon a normal (non-resumed) invocationoriginalInput- the tool request's original input (before any restart-replaced input); mirrors GoToolContext.OriginalInput;nullwhen not resuming
-
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 nullflowName- the name of the enclosing flow, may be nullspanPath- the current span path for tracingregistry- the Genkit registrysessionId- the session ID for multi-turn conversationsthreadName- the thread name for grouping related requests
-
ActionContext
Creates a new ActionContext.- Parameters:
spanContext- the tracing span context, may be nullflowName- the name of the enclosing flow, may be nullspanPath- the current span path for tracingregistry- the Genkit registry
-
ActionContext
Creates a new ActionContext.- Parameters:
spanContext- the tracing span context, may be nullflowName- the name of the enclosing flow, may be nullregistry- the Genkit registry
-
ActionContext
Creates a new ActionContext with default values.- Parameters:
registry- the Genkit registry
-
-
Method Details
-
getSpanContext
Returns the tracing span context.- Returns:
- the span context, or null if tracing is not active
-
getFlowName
Returns the name of the enclosing flow, if any.- Returns:
- the flow name, or null if not in a flow context
-
getSpanPath
Returns the current span path for tracing.- Returns:
- the span path, or null if not in a traced context
-
getRegistry
Returns the Genkit registry.- Returns:
- the registry
-
getSessionId
Returns the session ID for multi-turn conversations.- Returns:
- the session ID, or null if not set
-
getThreadName
Returns the thread name for grouping related requests.- Returns:
- the thread name, or null if not set
-
getContext
Returns the request-scoped user context.This is the
contextobject injected by callers (such as the Dev UI "Execution context" panel or the reflection/serving layers), e.g.{"auth": {"user": "alice"}}. It is threaded through the run so tools and flows can read it viagetContext().- Returns:
- the user context map, or null if not set
-
getResumed
Returns the resume metadata attached when this action is being re-invoked after an interrupt/restart, ornullon a normal invocation.Mirrors JS
ToolRunOptions.resumedand GoToolContext.Resumed: a restart-aware tool can inspect this to distinguish a fresh call from a resumed one and read the client-supplied approval/confirmation payload.- Returns:
- the resumed metadata value, or
nullif this is not a resumed invocation
-
isResumed
public boolean isResumed()Returnstrueif this action is being re-invoked after an interrupt/restart (i.e.getResumed()is non-null).- Returns:
- whether this is a resumed invocation
-
getOriginalInput
Returns the tool request's original input (before any restart-replaced input), mirroring GoToolContext.OriginalInput.nullwhen not resuming or when the original input was not preserved.- Returns:
- the original input, or
null
-
withFlowName
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
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
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
Creates a new ActionContext with a session ID.- Parameters:
sessionId- the session ID- Returns:
- a new ActionContext with the session ID
-
withThreadName
Creates a new ActionContext with a thread name.- Parameters:
threadName- the thread name- Returns:
- a new ActionContext with the thread name
-
withContext
Creates a new ActionContext with the given request-scoped user context.- Parameters:
context- the user context map (e.g.{"auth": {...}}), may be null- Returns:
- a new ActionContext with the updated user context
-
withResumed
Creates a new ActionContext carrying resume-awareness for a restarted tool call.- Parameters:
resumed- the resume metadata value (from the restart part'smetadata.resumed); may benulloriginalInput- the tool request's original input; may benull- Returns:
- a new ActionContext with the resume-awareness fields set
-
builder
Creates a builder for ActionContext.- Returns:
- a new builder
-