Skip to content

chore: refactors hello world example#566

Open
msampathkumar wants to merge 8 commits into
mainfrom
sampath_helloworld
Open

chore: refactors hello world example#566
msampathkumar wants to merge 8 commits into
mainfrom
sampath_helloworld

Conversation

@msampathkumar
Copy link
Copy Markdown

Description

This pull request refactors the Hello World agent sample and test client to align with the latest A2A Python SDK v1.0 patterns, improving modularity for documentation rendering, runtime clarity, and overall code maintainability.

  • AgentExecutor: used TaskUpdater class to simply updates to EventQueue
  • Client: re-arrange imports to user visibility

updated the code-sample to make import visible in user facing code snippet
@msampathkumar
Copy link
Copy Markdown
Author

Sharing test-logs

$ date
Fri May 15 00:31:24 CEST 2026
$ python test_client.py 
Initializes the A2ACardResolver instance with an HTTP client

Successfully fetched the public agent card:
====================================================
                     AgentCard                      
====================================================
--- General ---
Name        : Hello World Agent
Description : Just a hello world agent
Version     : 0.0.1

--- Interfaces ---
  [0] http://127.0.0.1:9999  (JSONRPC)

--- Capabilities ---
Streaming           : True
Push notifications  : False
Extended agent card : True

--- I/O Modes ---
Input  : text/plain
Output : text/plain

--- Skills ---
----------------------------------------------------
  ID          : hello_world
  Name        : Returns hello world
  Description : just returns hello world
  Tags        : hello world
  Example     : hi
  Example     : hello world
====================================================

--- Public Agent Card - Non-Streaming Call ---

Initializing a non-streaming client.
Response:
task {
  id: "993c64d2-223b-409b-86d4-20f60d057508"
  context_id: "ac0809eb-15c2-4dc0-8f0a-ede60043deeb"
  status {
    state: TASK_STATE_COMPLETED
    message {
      message_id: "0abb39b3-9f5b-4a7c-916d-6e15d533836e"
      role: ROLE_AGENT
      parts {
        text: "Request is completed!"
      }
    }
    timestamp {
      seconds: 1778797889
      nanos: 129454000
    }
  }
  artifacts {
    artifact_id: "e277355b-7f92-43de-81e1-e4d5feb826de"
    parts {
      text: "Hello, World! I have received your request (Say hello.)"
      media_type: "text/plain"
    }
  }
  history {
    message_id: "1fc12616-a1aa-4354-8325-9c7311456130"
    context_id: "ac0809eb-15c2-4dc0-8f0a-ede60043deeb"
    task_id: "993c64d2-223b-409b-86d4-20f60d057508"
    role: ROLE_USER
    parts {
      text: "Say hello."
    }
  }
  history {
    message_id: "51bf8d48-ea16-41bf-9152-4a9965a5f13c"
    role: ROLE_AGENT
    parts {
      text: "Processing request..."
    }
  }
}


--- Public Agent Card - Streaming Call ---

Initializing a streaming client.
Response:
task {
  id: "2ba4d092-e7db-46d5-b24d-69d97afd046e"
  context_id: "587f906a-7158-48db-9721-cdf592083a90"
  status {
    state: TASK_STATE_SUBMITTED
  }
  history {
    message_id: "1fc12616-a1aa-4354-8325-9c7311456130"
    context_id: "587f906a-7158-48db-9721-cdf592083a90"
    task_id: "2ba4d092-e7db-46d5-b24d-69d97afd046e"
    role: ROLE_USER
    parts {
      text: "Say hello."
    }
  }
}

status_update {
  task_id: "2ba4d092-e7db-46d5-b24d-69d97afd046e"
  context_id: "587f906a-7158-48db-9721-cdf592083a90"
  status {
    state: TASK_STATE_WORKING
    message {
      message_id: "434e2050-96b0-4891-b845-2ca925aa40b6"
      role: ROLE_AGENT
      parts {
        text: "Processing request..."
      }
    }
    timestamp {
      seconds: 1778797889
      nanos: 141284000
    }
  }
}

artifact_update {
  task_id: "2ba4d092-e7db-46d5-b24d-69d97afd046e"
  context_id: "587f906a-7158-48db-9721-cdf592083a90"
  artifact {
    artifact_id: "ba71abee-0cb5-4d9e-85e2-e927e7fbb150"
    parts {
      text: "Hello, World! I have received your request (Say hello.)"
      media_type: "text/plain"
    }
  }
}

status_update {
  task_id: "2ba4d092-e7db-46d5-b24d-69d97afd046e"
  context_id: "587f906a-7158-48db-9721-cdf592083a90"
  status {
    state: TASK_STATE_COMPLETED
    message {
      message_id: "41bc3c20-ba83-4c3b-a286-ba2685607c34"
      role: ROLE_AGENT
      parts {
        text: "Request is completed!"
      }
    }
    timestamp {
      seconds: 1778797889
      nanos: 141317000
    }
  }
}


--- Extended Agent Card - Non-Streaming Call ---

Successfully fetched the authenticated extended agent card:
====================================================
                     AgentCard                      
====================================================
--- General ---
Name        : Hello World Agent - Extended Edition
Description : The full-featured hello world agent for authenticated users.
Version     : 0.0.2

--- Interfaces ---
  [0] http://127.0.0.1:9999  (JSONRPC)

--- Capabilities ---
Streaming           : True
Push notifications  : False
Extended agent card : True

--- I/O Modes ---
Input  : text/plain
Output : text/plain

--- Skills ---
----------------------------------------------------
  ID          : hello_world
  Name        : Returns hello world
  Description : just returns hello world
  Tags        : hello world
  Example     : hi
  Example     : hello world
----------------------------------------------------
  ID          : super_hello_world
  Name        : Returns a SUPER Hello World
  Description : A more enthusiastic greeting, only for authenticated users.
  Tags        : hello world, super, extended
  Example     : super hi
  Example     : give me a super hello
====================================================

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the HelloWorldAgent and its executor to utilize the TaskUpdater utility for managing task statuses and artifacts. It also updates test_client.py by moving imports into the main function and enhancing console output. The review feedback suggests using str.join() for more idiomatic string concatenation and replacing the generic Exception with NotImplementedError in the cancel method.

Comment thread samples/python/agents/helloworld/agent_executor.py Outdated
Comment thread samples/python/agents/helloworld/agent_executor.py Outdated
@sokoliva sokoliva self-requested a review May 15, 2026 08:03
Comment on lines +58 to +60
query = ' '.join(
part.text for part in context.message.parts if part.text
)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lets utilize get_text_parts helper

Comment thread samples/python/agents/helloworld/test_client.py
async for chunk in streaming_response:
print('Response chunk:')
print('Response:')
async for chunk in streaming_client.send_message(request):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The reason we put print('Response chunk:') inside the response iteration from send_message was to display the difference between streaming and non-streaming. Can we somehow make the difference between streaming and non-streaming obvious in the stdout?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

In the tutorial, we have both streaming and non-stream snippets, one after the other.

To make it easy to identify the differences in ClientConfig, I am keep this pattern.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In non-streaming response comes as a one chunk, in streaming we get multiple chunks. With this setup this is not visible. Can we somehow make that obvious?

print('\n--- Public Agent Card - Streaming Call ---')
# --8<-- [start:message_stream]
print('\nInitializing a streaming client.')
streaming_config = ClientConfig(streaming=True)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Suggested change
streaming_config = ClientConfig(streaming=True)
streaming_config = ClientConfig(streaming=True) # Enable streaming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants