Skip to content

feat: added multi-agent coordination example for OpenAI and Gemini #186

Merged
dhruvj07 merged 1 commit intomainfrom
feat/gemini-adk-multi-agent
Apr 16, 2025
Merged

feat: added multi-agent coordination example for OpenAI and Gemini #186
dhruvj07 merged 1 commit intomainfrom
feat/gemini-adk-multi-agent

Conversation

@dhruvj07
Copy link
Copy Markdown
Contributor

added multi-agent coordination example for OpenAI and Gemini via Javelin (research → summary → report)

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.

Hello @dhruvj07, 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!

Summary of Changes

This pull request introduces two new examples demonstrating multi-agent coordination using the Google ADK (Agent Development Kit) with Javelin. The first example, adk_gemini_agent_javelin, showcases coordination using the Gemini model, while the second, adk_openai_agent_javelin, uses the OpenAI model. Both examples implement a sequential agent that coordinates a researcher, a summarizer, and a reporter to process a user query and generate a final report. The agents leverage the Javelin API for model access and routing.

Highlights

  • Multi-Agent Coordination: Demonstrates how to create and coordinate multiple agents using the ADK to perform a complex task (research, summarize, report).
  • Javelin Integration: Shows how to integrate with the Javelin API to access language models like Gemini and GPT-4o.
  • Sequential Agent: Implements a SequentialAgent to orchestrate the execution of sub-agents in a predefined order.
  • Environment Variables: Uses environment variables (GEMINI_API_KEY, JAVELIN_API_KEY, OPENAI_API_KEY) for secure API key management.

Changelog

Click here to see the changelog
  • examples/agents/adk_gemini_agent_javelin/init.py
    • Added __init__.py to import the root_agent from agent.py.
  • examples/agents/adk_gemini_agent_javelin/agent.py
    • Created agent.py to define the Gemini-based multi-agent system.
    • Implemented a research_agent, summary_agent, and report_agent using LlmAgent and the Gemini model via Javelin.
    • Defined a root_agent as a SequentialAgent to coordinate the sub-agents.
    • Added a main function to run the agent and print the final report.
    • Utilized LiteLlm to configure the language model with Javelin API details.
    • Ensured API keys are loaded from environment variables and validated.
  • examples/agents/adk_openai_agent_javelin/init.py
    • Added __init__.py to import the root_agent from agent.py.
  • examples/agents/adk_openai_agent_javelin/agent.py
    • Created agent.py to define the OpenAI-based multi-agent system.
    • Implemented a research_agent, summary_agent, and report_agent using LlmAgent and the GPT-4o model via Javelin.
    • Defined a coordinator (aliased as root_agent) as a SequentialAgent to coordinate the sub-agents.
    • Added a main function to run the agent and print the final report.
    • Utilized LiteLlm to configure the language model with Javelin API details.
    • Ensured API keys are loaded from environment variables and validated.
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.


Agents in sequence flow,
Research, summarize, then show.
Javelin's swift route,
A report to boot,
Knowledge from the AI glow.

Footnotes

  1. 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.

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 introduces multi-agent coordination examples for OpenAI and Gemini using Javelin. The code is well-structured and demonstrates the use of LlmAgent and SequentialAgent for creating research, summary, and report agents. However, there are a few areas that could be improved for clarity and maintainability.

Summary of Findings

  • Missing Error Handling: The main functions in both agent examples lack comprehensive error handling. Consider adding try-except blocks to catch potential exceptions during agent execution and provide informative error messages.
  • Duplicated Code: The OpenAI and Gemini agent examples share a lot of code. Consider creating a base class or utility function to reduce duplication and improve maintainability.
  • Hardcoded Values: The query strings in both examples are hardcoded. Consider making them configurable via environment variables or command-line arguments.

Merge Readiness

The pull request introduces valuable examples of multi-agent coordination. However, addressing the missing error handling and code duplication issues would significantly improve the code's robustness and maintainability. I recommend addressing these issues before merging. I am unable to directly approve this pull request, and users should have others review and approve this code before merging, especially after the requested changes are made.

Comment on lines +16 to +19
if not GEMINI_API_KEY:
raise ValueError("Missing GEMINI_API_KEY")
if not JAVELIN_API_KEY:
raise ValueError("Missing JAVELIN_API_KEY")
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

Consider using os.environ.get with a default value instead of raising a ValueError. This allows the program to run with a default behavior if the environment variables are not set, and provides a more graceful degradation. Also, consider logging a warning message if the environment variables are not set.

GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
JAVELIN_API_KEY = os.getenv("JAVELIN_API_KEY")

if not GEMINI_API_KEY:
    print("Warning: Missing GEMINI_API_KEY in environment, using default value.")
    GEMINI_API_KEY = "default_gemini_api_key"  # Replace with an actual default value
if not JAVELIN_API_KEY:
    print("Warning: Missing JAVELIN_API_KEY in environment, using default value.")
    JAVELIN_API_KEY = "default_javelin_api_key"  # Replace with an actual default value

Comment on lines +75 to +94
async def main():
session_service = InMemorySessionService()
session_service.create_session("gemini_multi_agent_app", "user", "sess")

runner = Runner(
agent=root_agent,
app_name="gemini_multi_agent_app",
session_service=session_service,
)

query = "role of AI in sustainable energy"
msg = Content(role="user", parts=[Part.from_text(query)])

final_answer = ""
async for event in runner.run_async("user", "sess", new_message=msg):
if event.is_final_response() and event.content:
final_answer = event.content.parts[0].text
break

print("\n--- Final Report ---\n", final_answer)
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

Consider adding a try-except block to handle potential exceptions during agent execution. This will prevent the program from crashing and provide more informative error messages.

    try:
        session_service = InMemorySessionService()
        session_service.create_session("gemini_multi_agent_app", "user", "sess")

        runner = Runner(
            agent=root_agent,
            app_name="gemini_multi_agent_app",
            session_service=session_service,
        )

        query = "role of AI in sustainable energy"
        msg = Content(role="user", parts=[Part.from_text(query)])

        final_answer = ""
        async for event in runner.run_async("user", "sess", new_message=msg):
            if event.is_final_response() and event.content:
                final_answer = event.content.parts[0].text
                break

        print("\n--- Final Report ---\n", final_answer)
    except Exception as e:
        print(f"An error occurred: {e}")

Comment on lines +77 to +97
async def main():
session_service = InMemorySessionService()
session_service.create_session("openai_multi_agent_app", "user", "sess")

runner = Runner(
agent=coordinator,
app_name="openai_multi_agent_app",
session_service=session_service,
)

# Provide user query
query = "impact of AI on global education"
msg = Content(role="user", parts=[Part.from_text(query)])

final_answer = ""
async for event in runner.run_async("user", "sess", new_message=msg):
if event.is_final_response() and event.content:
final_answer = event.content.parts[0].text
break

print("\n--- Final Report ---\n", final_answer)
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

Consider adding a try-except block to handle potential exceptions during agent execution. This will prevent the program from crashing and provide more informative error messages.

    try:
        session_service = InMemorySessionService()
        session_service.create_session("openai_multi_agent_app", "user", "sess")

        runner = Runner(
            agent=coordinator,
            app_name="openai_multi_agent_app",
            session_service=session_service,
        )

        # Provide user query
        query = "impact of AI on global education"
        msg = Content(role="user", parts=[Part.from_text(query)])

        final_answer = ""
        async for event in runner.run_async("user", "sess", new_message=msg):
            if event.is_final_response() and event.content:
                final_answer = event.content.parts[0].text
            break

        print("\n--- Final Report ---\n", final_answer)
    except Exception as e:
        print(f"An error occurred: {e}")

@abhijitjavelin abhijitjavelin self-requested a review April 16, 2025 13:47
@dhruvj07 dhruvj07 merged commit a2f3fde into main Apr 16, 2025
6 of 7 checks passed
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