Class Event

java.lang.Object
com.google.adk.JsonBaseModel
com.google.adk.events.Event

public class Event extends JsonBaseModel
Represents an event in a session.
  • Method Details

    • generateEventId

      public static String generateEventId()
      Returns a random event id. Agents, tools, and plugins that build events inside an invocation should use InvocationContext.newUuid() instead so the id follows its UuidProvider.
    • id

      public String id()
      The event id.
    • setId

      public void setId(String id)
    • invocationId

      public String invocationId()
      Id of the invocation that this event belongs to.
    • setInvocationId

      public void setInvocationId(String invocationId)
    • author

      public String author()
      The author of the event, it could be the name of the agent or "user" literal.
    • setAuthor

      public void setAuthor(String author)
    • content

      public Optional<com.google.genai.types.Content> content()
    • setContent

      public void setContent(@Nullable com.google.genai.types.Content content)
    • actions

      public EventActions actions()
    • setActions

      public void setActions(EventActions actions)
    • longRunningToolIds

      public Optional<Set<String>> longRunningToolIds()
      Set of ids of the long running function calls. Agent client will know from this field about which function call is long running.
    • setLongRunningToolIds

      public void setLongRunningToolIds(@Nullable Set<String> longRunningToolIds)
    • partial

      public Optional<Boolean> partial()
      partial is true for incomplete chunks from the LLM streaming response. The last chunk's partial is False.
    • setPartial

      public void setPartial(@Nullable Boolean partial)
    • turnComplete

      public Optional<Boolean> turnComplete()
    • setTurnComplete

      public void setTurnComplete(@Nullable Boolean turnComplete)
    • errorCode

      public Optional<com.google.genai.types.FinishReason> errorCode()
    • finishReason

      public Optional<com.google.genai.types.FinishReason> finishReason()
    • setErrorCode

      public void setErrorCode(@Nullable com.google.genai.types.FinishReason errorCode)
    • setFinishReason

      @Deprecated public void setFinishReason(Optional<com.google.genai.types.FinishReason> finishReason)
      Deprecated.
      Use setFinishReason(FinishReason) with finishReason.orElse(null) instead.
      Sets the finish reason from an Optional.
    • setFinishReason

      public void setFinishReason(@Nullable com.google.genai.types.FinishReason finishReason)
    • errorMessage

      public Optional<String> errorMessage()
    • setErrorMessage

      public void setErrorMessage(@Nullable String errorMessage)
    • usageMetadata

      public Optional<com.google.genai.types.GenerateContentResponseUsageMetadata> usageMetadata()
    • setUsageMetadata

      public void setUsageMetadata(@Nullable com.google.genai.types.GenerateContentResponseUsageMetadata usageMetadata)
    • avgLogprobs

      public Optional<Double> avgLogprobs()
    • setAvgLogprobs

      public void setAvgLogprobs(@Nullable Double avgLogprobs)
    • interrupted

      public Optional<Boolean> interrupted()
    • setInterrupted

      public void setInterrupted(@Nullable Boolean interrupted)
    • branch

      public Optional<String> branch()
      The branch of the event. The format is like agent_1.agent_2.agent_3, where agent_1 is the parent of agent_2, and agent_2 is the parent of agent_3. Branch is used when multiple sub-agent shouldn't see their peer agents' conversation history.
    • branch

      public void branch(@Nullable String branch)
      Sets the branch for this event.

      Format: agentA.agentB.agentC — shows hierarchy of nested agents.

      Parameters:
      branch - Branch identifier.
    • isolationScope

      @Experimental public Optional<String> isolationScope()
      Returns the isolated conversation this event belongs to, such as a delegated task, so an agent's model history can keep only events from its own scope. Returns empty when the event is not scoped. This field is internal to the framework and may change without notice.
    • setIsolationScope

      @Experimental public void setIsolationScope(@Nullable String isolationScope)
    • groundingMetadata

      public Optional<com.google.genai.types.GroundingMetadata> groundingMetadata()
      The grounding metadata of the event.
    • setGroundingMetadata

      public void setGroundingMetadata(@Nullable com.google.genai.types.GroundingMetadata groundingMetadata)
    • customMetadata

      public Optional<List<com.google.genai.types.CustomMetadata>> customMetadata()
      The custom metadata of the event.
    • setCustomMetadata

      public void setCustomMetadata(@Nullable List<com.google.genai.types.CustomMetadata> customMetadata)
    • modelVersion

      public Optional<String> modelVersion()
      The model version used to generate the response.
    • setModelVersion

      public void setModelVersion(@Nullable String modelVersion)
    • inputTranscription

      public Optional<com.google.genai.types.Transcription> inputTranscription()
      Input transcription. The transcription is independent to the model turn which means it doesn't imply any ordering between transcription and model turn.
    • setInputTranscription

      public void setInputTranscription(@Nullable com.google.genai.types.Transcription inputTranscription)
    • outputTranscription

      public Optional<com.google.genai.types.Transcription> outputTranscription()
      Output transcription. The transcription is independent to the model turn which means it doesn't imply any ordering between transcription and model turn.
    • setOutputTranscription

      public void setOutputTranscription(@Nullable com.google.genai.types.Transcription outputTranscription)
    • output

      @Experimental public Optional<Object> output()
      For a workflow node, returns the value handed to successors, distinct from content(), or empty when the event carries no node output. Holds any value Jackson can serialize, such as a JSON-native value or a Content. An event read from JSON holds the JSON-native form (a map with string keys, a list, a string, a number, or a boolean).
    • setOutput

      @Experimental public void setOutput(@Nullable Object output)
    • nodeInfo

      @Experimental public Optional<NodeInfo> nodeInfo()
      Identifies the workflow-node activation that emitted this event; outside a workflow, this value is empty or has an empty path.
    • setNodeInfo

      @Experimental public void setNodeInfo(@Nullable NodeInfo nodeInfo)
    • cacheMetadata

      public Optional<CacheMetadata> cacheMetadata()
      Context cache state of the LLM response this event carries. The next request of the same agent reads it to reuse or refresh the cache.
    • setCacheMetadata

      public void setCacheMetadata(@Nullable CacheMetadata cacheMetadata)
    • timestamp

      public long timestamp()
      The timestamp of the event.
    • setTimestamp

      public void setTimestamp(long timestamp)
    • functionCalls

      public final com.google.common.collect.ImmutableList<com.google.genai.types.FunctionCall> functionCalls()
      Returns all function calls from this event.
    • functionResponses

      public final com.google.common.collect.ImmutableList<com.google.genai.types.FunctionResponse> functionResponses()
      Returns all function responses from this event.
    • hasTrailingCodeExecutionResult

      public final boolean hasTrailingCodeExecutionResult()
      Returns whether the event has a trailing code execution result.
    • hasPendingLongRunningToolCall

      public final boolean hasPendingLongRunningToolCall()
      Returns whether this event carries a pending long-running tool call (e.g. a human-in-the-loop request) whose result is deferred until the caller supplies it later.
    • finalResponse

      public final boolean finalResponse()
      Returns true if this is a final response.
    • nodeName

      @Experimental public final Optional<String> nodeName()
      Returns the name of the workflow node that emitted this event, from NodeInfo.name(). Empty outside a workflow and on an event that carries any agent state or ends an agent. ADK Python's Event.node_name returns an empty string instead and ignores an empty agent state.
    • stringifyContent

      public final String stringifyContent()
      Converts the event content into a readable string.

      Includes text, function calls, and responses.

      Returns:
      Stringified content.
    • builder

      public static Event.Builder builder()
    • fromJson

      public static Event fromJson(String json)
      Parses an event from a JSON string.
    • toBuilder

      public Event.Builder toBuilder()
      Creates a builder pre-filled with this event's values.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object