8000 [Question] Why do you need check of `event.content and event.content.parts`, both? · Issue #1543 · google/adk-python · GitHub
[go: up one dir, main page]

Skip to content
[Question] Why do you need check of event.content and event.content.parts, both? #1543
Open
@ygicp

Description

@ygicp

In the tutorial on Agent Team, I discovered a condition :
if event.content and event.content.parts. The class definition of google.genai.Content is as follows (as of 20 June 2025 IST):

class Content(_common.BaseModel):
  """Contains the multi-part content of a message."""

  parts: Optional[list[Part]] = Field(
      default=None,
      description="""List of parts that constitute a single message. Each part may have
      a different IANA MIME type.""",
  )
  role: Optional[str] = Field(
      default=None,
      description="""Optional. The producer of the content. Must be either 'user' or
      'model'. Useful to set for multi-turn conversations, otherwise can be
      empty. If role is not specified, SDK will determine the role.""",
  )

There is not a separate validation, but it is safe to assume that there will not be any response which has a role, but no parts.

Now even if you do encounter a possibility where out of user or model (as role field) , only role is set, then is not it a vague design from the genai repo? I mean there is a role but empty list as output. Do you think a model_after_validator is required either in event, or in google.genai.types.Content?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0