Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/google/adk/flows/llm_flows/base_llm_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ def get_author_for_event(llm_response):
id=Event.new_id(),
invocation_id=invocation_context.invocation_id,
author=get_author_for_event(llm_response),
custom_metadata=invocation_context.run_config.custom_metadata,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The invocation_context.run_config is of type Optional[RunConfig] and could be None. Accessing custom_metadata directly could lead to an AttributeError. It's safer to use getattr to avoid this potential runtime error.

Suggested change
custom_metadata=invocation_context.run_config.custom_metadata,
custom_metadata=getattr(invocation_context.run_config, 'custom_metadata', None),

)

async with Aclosing(
Expand Down Expand Up @@ -438,6 +439,7 @@ async def _run_one_step_async(
invocation_id=invocation_context.invocation_id,
author=invocation_context.agent.name,
branch=invocation_context.branch,
custom_metadata=invocation_context.run_config.custom_metadata,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to the previous comment, invocation_context.run_config can be None. Using getattr provides a safer way to access custom_metadata and prevents a potential AttributeError.

Suggested change
custom_metadata=invocation_context.run_config.custom_metadata,
custom_metadata=getattr(invocation_context.run_config, 'custom_metadata', None),

)
async with Aclosing(
self._call_llm_async(
Expand Down
2 changes: 2 additions & 0 deletions src/google/adk/models/lite_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,8 @@ async def _get_content(

content_objects = []
for part in parts:
if part.thought:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The thought attribute on a types.Part object is optional. To prevent a potential AttributeError if a part doesn't have this attribute, it's safer to use getattr(part, 'thought', False) for the check.

Suggested change
if part.thought:
if getattr(part, 'thought', False):

continue
if part.text:
if len(parts) == 1:
return part.text
Expand Down