Package com.google.genkit.ai.agent
Class AgentSessionContext
java.lang.Object
com.google.genkit.ai.agent.AgentSessionContext
AgentSessionContext binds a
Session to the current thread so that prompts, middleware,
and tools can access the active session without passing it through every call frame.
A ThreadLocal is used for binding; the context is always cleared after run(com.google.genkit.ai.agent.Session<?>, java.lang.Runnable) or
call(com.google.genkit.ai.agent.Session<?>, java.util.function.Supplier<T>) returns (even if the body throws).
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TExecutesbodywithsessionbound to the current thread context and returns the result.static Session<?> current()Returns theSessioncurrently bound to this thread, ornullif none.static ArtifactStoreReturns the current session viewed as anArtifactStore, ornullif no session is bound to this thread.static voidExecutesbodywithsessionbound to the current thread context.
-
Method Details
-
run
Executesbodywithsessionbound to the current thread context. Clears the binding when the body returns or throws.- Parameters:
session- the session to bind (must not be null)body- the runnable to execute
-
call
Executesbodywithsessionbound to the current thread context and returns the result. Clears the binding when the body returns or throws.- Type Parameters:
T- the return type- Parameters:
session- the session to bind (must not be null)body- the supplier to execute- Returns:
- the value returned by
body
-
current
Returns theSessioncurrently bound to this thread, ornullif none.- Returns:
- the current session, or null
-
currentArtifactStore
Returns the current session viewed as anArtifactStore, ornullif no session is bound to this thread.- Returns:
- the current session as an
ArtifactStore, or null
-