-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat: implement streaming support in to_a2a for issue #4240 #4230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ | |
| from google.genai import types as genai_types | ||
| from pydantic import BaseModel | ||
|
|
||
| from ...agents.run_config import RunConfig,StreamingMode | ||
| from ...runners import RunConfig | ||
| from ..experimental import a2a_experimental | ||
| from .part_converter import A2APartToGenAIPartConverter | ||
|
|
@@ -115,3 +116,46 @@ def convert_a2a_request_to_agent_run_request( | |
| ), | ||
| run_config=RunConfig(custom_metadata=custom_metadata), | ||
| ) | ||
|
|
||
| @a2a_experimental | ||
| def create_request_converter( | ||
| streaming_mode: StreamingMode = StreamingMode.NONE | ||
| ) -> A2ARequestToAgentRunRequestConverter: | ||
| """Creates a request converter with specified streaming mode. | ||
|
|
||
| Args: | ||
| streaming_mode: The streaming mode to use for the agent execution. | ||
|
|
||
| Returns: | ||
| A Converter function configured with the specified streaming mode. | ||
| """ | ||
| def converter( | ||
| request: RequestContext, | ||
| part_converter: A2APartToGenAIPartConverter = convert_a2a_part_to_genai_part, | ||
| )-> AgentRunRequest: | ||
|
|
||
| if not request.message: | ||
| raise ValueError('Request message cannot be None') | ||
|
|
||
| custom_metadata = {} | ||
| if request.metadata: | ||
| custom_metadata['a2a_metadata'] = request.metadata | ||
|
|
||
| output_parts = [] | ||
| for a2a_part in request.message.parts: | ||
| genai_parts = part_converter(a2a_part) | ||
| if not isinstance(genai_parts, list): | ||
| genai_parts = [genai_parts] if genai_parts else [] | ||
| output_parts.extend(genai_parts) | ||
|
|
||
| return AgentRunRequest( | ||
| user_id=_get_user_id(request), | ||
| session_id=request.context_id, | ||
| new_message=genai_types.Content( | ||
| role='user', | ||
| parts=output_parts, | ||
| ), | ||
| run_config=RunConfig(streaming_mode=streaming_mode, custom_metadata=custom_metadata), | ||
| ) | ||
|
|
||
| return converter | ||
|
Comment on lines
+121
to
+161
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This import of
RunConfigfrom...runnersshadows the one imported from...agents.run_configon the previous line. TheRunConfigfrom...agents.run_configis required for thestreaming_modeparameter introduced in this PR. This shadowing will cause a runtime error because theRunConfigfrom...runnerslikely does not supportstreaming_mode. This line should be removed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you address this.