Skip to content
Open
Changes from all 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
31 changes: 20 additions & 11 deletions python/packages/kagent-adk/src/kagent/adk/_a2a.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,23 @@ async def test(self, task: str):
content = types.Content(role="user", parts=[types.Part(text=task)])
# Key Concept: run_async executes the agent logic and yields Events.
# We iterate through events to find the final answer.
async for event in runner.run_async(
user_id=USER_ID,
session_id=SESSION_ID,
new_message=content,
):
# You can uncomment the line below to see *all* events during execution
# print(f" [Event] Author: {event.author}, Type: {type(event).__name__}, Final: {event.is_final_response()}, Content: {event.content}")

# Key Concept: is_final_response() marks the concluding message for the turn.
jsn = event.model_dump_json()
logger.info(f" [Event] {jsn}")
try:
async for event in runner.run_async(
user_id=USER_ID,
session_id=SESSION_ID,
new_message=content,
):
# You can uncomment the line below to see *all* events during execution
# print(f" [Event] Author: {event.author}, Type: {type(event).__name__}, Final: {event.is_final_response()}, Content: {event.content}")

# Key Concept: is_final_response() marks the concluding message for the turn.
jsn = event.model_dump_json()
logger.info(f" [Event] {jsn}")
finally:
# Ensure proper cleanup of any async resources
try:
# Close any open connections or resources
if hasattr(runner, 'close'):
await runner.close()
Comment on lines +142 to +143
Copy link

Copilot AI Oct 20, 2025

Choose a reason for hiding this comment

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

Using hasattr for dynamic method checking is less reliable than using a proper protocol or interface. Consider defining a proper cleanup interface or checking for a specific type that guarantees the close method exists.

Suggested change
if hasattr(runner, 'close'):
await runner.close()
await runner.close()

Copilot uses AI. Check for mistakes.
except Exception as cleanup_error:
logger.warning(f"Error during cleanup: {cleanup_error}")