-
Notifications
You must be signed in to change notification settings - Fork 405
a2a skeleton for a2a with adk begginer #227
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?
Conversation
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.
Summary of Changes
Hello @svchk12, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a foundational, beginner-friendly skeleton project for Agent-to-Agent (A2A) communication, leveraging the Agent Development Kit (ADK). It aims to simplify the initial setup for new developers by providing a clear, minimalist example of a microservice architecture composed of interconnected agents, complete with a gateway and specialized sub-agents.
Highlights
- New Skeleton Project: Introduces a complete, runnable skeleton project (
a2a_skeleton
) demonstrating Agent-to-Agent (A2A) communication and the Agent Development Kit (ADK) concepts, designed for beginners. - Microservice Architecture: Implements a multi-agent system showcasing inter-agent communication, including a
gateway
for external requests, agenerate_contents_agent
for content creation, asearch_agent
for information retrieval, and ahost_agent
for agent management and routing. - Comprehensive Documentation: Provides detailed
README.md
files for the overall project and each sub-agent, covering project overview, structure, installation steps (usinguv
), execution instructions, and usage examples. - Core Agent Functionality: Demonstrates how to build and connect different types of agents (LLM-based for content generation and search, and a host agent for routing and discovery) within the A2A framework, including session management and streaming responses.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces an excellent skeleton project for A2A and ADK, which will be very helpful for beginners. The overall structure is logical and well-organized. My review identifies a few critical issues that could cause the services to crash, along with other recommendations to align the code with best practices and make it more robust and easier to understand.
raise | ||
|
||
async def cancel(self, context: RequestContext, event_queue: EventQueue): | ||
raise ServerError(error=UnsupportedOperationError()) |
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.
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.
Here's how you might modify it:
from a2a.utils.errors import ServerError
async def cancel(self, context: RequestContext, event_queue: EventQueue):
"""Cancels an ongoing operation."""
raise ServerError(error=UnsupportedOperationError())
The reason UnsupportedOperationError is wrapped inside ServerError is to standardize error responses according to the JSON-RPC specification.
UnsupportedOperationError itself contains the code, message, and data fields that align with the JSON-RPC error format. By raising ServerError with UnsupportedOperationError as its payload, the system ensures that any specific operational error (like an unsupported action) is consistently presented to the client in a predictable and uniform JSON-RPC error structure. This centralizes error handling and simplifies how clients process various server-side issues.
) | ||
|
||
HOST = os.getenv('HOST') | ||
PORT = int(os.getenv('PORT')) |
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.
Calling int(os.getenv('PORT'))
is unsafe. If the PORT
environment variable is not set, os.getenv('PORT')
will return None
, and int(None)
will raise a TypeError
, crashing the application on startup. You should provide a default value to os.getenv
to prevent this.
PORT = int(os.getenv('PORT')) | |
PORT = int(os.getenv('PORT', '8002')) |
raise | ||
|
||
async def cancel(self, context: RequestContext, event_queue: EventQueue): | ||
raise ServerError(error=UnsupportedOperationError()) |
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.
) | ||
|
||
HOST = os.getenv('HOST') | ||
PORT = int(os.getenv('PORT')) |
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.
Calling int(os.getenv('PORT'))
is unsafe. If the PORT
environment variable is not set, os.getenv('PORT')
will return None
, and int(None)
will raise a TypeError
, crashing the application on startup. You should provide a default value to os.getenv
to prevent this.
PORT = int(os.getenv('PORT')) | |
PORT = int(os.getenv('PORT', '8003')) |
async def send_message(request: Request): | ||
data = await request.json() | ||
#session_id = data.get("session_id", "default") | ||
query = data.get("query", {}) |
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.
The default value for query
is an empty dictionary ({}
), but the curl
example and subsequent usage expect a string. If the query
field is missing from the request body, passing the empty dictionary to the agent will likely cause issues. The default value should be an empty string ""
to handle missing queries gracefully.
query = data.get("query", {}) | |
query = data.get("query", "") |
logger.info(f"invoke 진입전 ") | ||
async for event in self.agent.invoke(query, session_id, task.id, user_id): | ||
event_dict = event.dict() | ||
text = event_dict['content']['parts'][0]['text'] |
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.
Accessing nested dictionary keys like event_dict['content']['parts'][0]['text']
is fragile and can lead to KeyError
or IndexError
if the event structure is not what's expected. It's safer to access these values through the pydantic model attributes on the event
object itself, and add checks to ensure event.content
and event.content.parts
are not empty.
text = event_dict['content']['parts'][0]['text'] | |
text = event.content.parts[0].text if event.content and event.content.parts else "" |
except Exception as e : | ||
raise | ||
yield {"error": "LLM이 올바른 포맷/에이전트 이름을 반환하지 못했습니다."} |
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.
The invoke
method's error handling is problematic: The except Exception as e: raise
block is inside the retry loop, preventing the retry from happening. Also, the yield {"error": ...}
after the loop is not a valid A2A
event. Instead, you should raise a specific exception that the executor can catch and handle gracefully.
for part in event_dict["artifact"]["parts"]: | ||
text = part['text'] |
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.
The loop for part in event_dict["artifact"]["parts"]:
overwrites the text
variable in each iteration. If an artifact has multiple parts, only the text from the last part will be preserved. You should concatenate the text from all parts.
text=""
for part in event_dict["artifact"]["parts"]:
if part.get('text'):
text += part['text']
logger.info(f"invoke 진입전 ") | ||
async for event in self.agent.invoke(query, session_id, task.id, user_id): | ||
event_dict = event.dict() | ||
text = event_dict['content']['parts'][0]['text'] |
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.
Accessing nested dictionary keys like event_dict['content']['parts'][0]['text']
is fragile and can lead to KeyError
or IndexError
if the event structure is not what's expected. It's safer to access these values through the pydantic model attributes on the event
object itself, and add checks to ensure event.content
and event.content.parts
are not empty.
text = event_dict['content']['parts'][0]['text'] | |
text = event.content.parts[0].text if event.content and event.content.parts else "" |
A Beginner-Friendly Skeleton Example for A2A and ADK
While there are many excellent samples available, newcomers often find it quite challenging to get started with Agent-to-Agent (A2A) communication and the Agent Development Kit (ADK).
To address this, I've created a simple skeleton example designed for ease of use by absolute beginners. My hope is that this will help make agent development more accessible to everyone, fostering broader adoption and innovation within the A2A ecosystem.
This minimalist example aims to provide a clear and immediate starting point, demonstrating the core mechanics of agent interaction without overwhelming complexity.