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. -
Method Summary
Modifier and TypeMethodDescriptionstatic ActionContext.Builderbuilder()Creates a builder for ActionContext.Returns the name of the enclosing flow, if any.Returns the Genkit registry.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.withFlowName(String flowName) Creates a new ActionContext with a different flow name.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) 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
-
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
-
builder
Creates a builder for ActionContext.- Returns:
- a new builder
-