Package com.google.genkit.ai.agent
Interface AgentApi<S>
- Type Parameters:
S- the type of custom session state
- All Known Implementing Classes:
Agent
public interface AgentApi<S>
AgentApi is the typed facade interface exposed by an agent, providing snapshot retrieval, abort,
identification, and chat-client creation.
-
Method Summary
Modifier and TypeMethodDescriptionAttempts to abort a snapshot that is currently inSnapshotStatus.PENDINGstate.chat()Creates a freshAgentChatfor a new conversation, using a default action context built from the registry the agent was defined in.Creates anAgentChatseeded frominit(snapshotId / sessionId / inline state), using a default action context built from the registry the agent was defined in.chat(ActionContext ctx) Creates a freshAgentChatfor a new conversation.chat(ActionContext ctx, AgentInit<S> init) Creates anAgentChatseeded frominit(snapshotId / sessionId / inline state).Retrieves a session snapshot by snapshot ID or session ID.loadChat(GetSnapshotRequest lookup) Loads a snapshot and hydrates anAgentChatwhose next send resumes it, using a default action context built from the registry the agent was defined in.loadChat(ActionContext ctx, GetSnapshotRequest lookup) Loads a snapshot and hydrates anAgentChatwhose next send resumes it.ref()Returns a lightweight reference to this agent.
-
Method Details
-
chat
Creates a freshAgentChatfor a new conversation, using a default action context built from the registry the agent was defined in.This is the convenience overload for the common case. Use
chat(ActionContext)when you need to supply request-scoped context (e.g. auth / user info that tools should observe).- Returns:
- a new chat
-
chat
Creates anAgentChatseeded frominit(snapshotId / sessionId / inline state), using a default action context built from the registry the agent was defined in.- Parameters:
init- the seed init (may benullfor a fresh chat)- Returns:
- a new chat
-
loadChat
Loads a snapshot and hydrates anAgentChatwhose next send resumes it, using a default action context built from the registry the agent was defined in.- Parameters:
lookup- which snapshot to load (by snapshotId or sessionId)- Returns:
- a hydrated chat
-
chat
Creates a freshAgentChatfor a new conversation.- Parameters:
ctx- the action context used to run each turn- Returns:
- a new chat
-
chat
Creates anAgentChatseeded frominit(snapshotId / sessionId / inline state).- Parameters:
ctx- the action context used to run each turninit- the seed init (may benullfor a fresh chat)- Returns:
- a new chat
-
loadChat
Loads a snapshot and hydrates anAgentChatwhose next send resumes it.- Parameters:
ctx- the action context used to run each turnlookup- which snapshot to load (by snapshotId or sessionId)- Returns:
- a hydrated chat
-
getSnapshotData
Retrieves a session snapshot by snapshot ID or session ID.- Parameters:
req- the request specifying which snapshot to retrieve- Returns:
- the matching session snapshot, or
nullif not found
-
abort
Attempts to abort a snapshot that is currently inSnapshotStatus.PENDINGstate.If the snapshot is already in a terminal state, returns that state unchanged. If the snapshot does not exist, returns
null.- Parameters:
snapshotId- the ID of the snapshot to abort- Returns:
- the resulting
SnapshotStatus, ornullif the snapshot was not found
-
ref
AgentRef ref()Returns a lightweight reference to this agent.- Returns:
- an
AgentRefcarrying the agent's name and description
-