Created
July 4, 2025 15:20
-
-
Save codeninja/a6e117a3480de8d32dd9ef01b519cdae to your computer and use it in GitHub Desktop.
A Google ADK Agentic team to update mongoose from version 6 to version 8.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.adk.agents import Agent | |
from google.adk.events import Event | |
from google.adk.agents.invocation_context import InvocationContext | |
from google.genai.types import Content, Part | |
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset | |
from google.adk.tools.mcp_tool import StdioConnectionParams, StreamableHTTPConnectionParams, SseConnectionParams | |
from google.adk.tools.agent_tool import AgentTool | |
from pydantic import BaseModel, Field | |
from mcp import StdioServerParameters | |
import asyncio | |
import os | |
from google.adk.agents import LlmAgent, ParallelAgent, SequentialAgent | |
from google.adk.models.anthropic_llm import Claude # Import needed for registration | |
from google.adk.models.registry import LLMRegistry # Import needed for registration | |
from google.genai import types | |
from Agents.coder_typescript.agent import TypescriptAgent | |
from Agents.coder_javascript.agent import JavascriptAgent | |
## CONFIG | |
# LLMRegistry.register(Claude) | |
# useModel = "claude-3-7-sonnet@20250219" | |
useModel = "gemini-2.5-flash" | |
repoPaths = [ | |
"/home/ubuntu/repo", | |
"/home/ubuntu/repo-2", | |
"/home/ubuntu/repo-3", | |
"/home/ubuntu/repo-4", | |
] | |
repoPrompt = """ | |
repo: | |
- describe your repositories... | |
""" | |
### end config | |
# Define the filesystem MCP server for local repository access | |
# The paths will be passed as arguments to the server | |
listFilesystem_mcp = MCPToolset( | |
connection_params=StdioConnectionParams( | |
server_params=StdioServerParameters( | |
command="npx", | |
args=[ | |
"-y", | |
"@modelcontextprotocol/server-filesystem", | |
...repoPaths | |
], | |
), | |
timeout=300, # Set a timeout for the connection | |
), | |
auth_scheme=None, | |
auth_credential=None, | |
tool_filter=["search_files", "list_allowed_directories", "list_directory", "get_file_info", "directory_tree"] # List-only access | |
) | |
roFilesystem_mcp = MCPToolset( | |
connection_params=StdioConnectionParams( | |
server_params=StdioServerParameters( | |
command="npx", | |
args=[ | |
"-y", | |
"@modelcontextprotocol/server-filesystem", | |
...repoPaths | |
], | |
), | |
timeout=300, # Set a timeout for the connection | |
), | |
auth_scheme=None, | |
auth_credential=None, | |
tool_filter=["read_multiple_files","read_file", "list_directory", "get_file_info", "directory_tree"] # Read-only access | |
) | |
lwFilesystem_mcp = MCPToolset( | |
connection_params=StdioConnectionParams( | |
server_params=StdioServerParameters( | |
command="npx", | |
args=[ | |
"-y", | |
"@modelcontextprotocol/server-filesystem", | |
...repoPaths | |
], | |
), | |
timeout=300, # Set a timeout for the connection | |
), | |
auth_scheme=None, | |
auth_credential=None, | |
tool_filter=["search_files", "list_allowed_directories", "list_directory", "get_file_info", "directory_tree", 'write_file'] # List-only access | |
) | |
rwFilesystem_mcp = MCPToolset( | |
connection_params=StdioConnectionParams( | |
server_params=StdioServerParameters( | |
command="npx", | |
args=[ | |
"-y", | |
"@modelcontextprotocol/server-filesystem", | |
...repoPaths | |
], | |
), | |
timeout=300, # Set a timeout for the connection | |
), | |
auth_scheme=None, | |
auth_credential=None, | |
) | |
sequential_thinking = MCPToolset( | |
connection_params=StdioServerParameters( | |
command='docker', | |
args= [ | |
"run", | |
"--rm", | |
"-i", | |
"mcp/sequentialthinking" | |
], | |
), | |
auth_scheme=None, | |
auth_credential=None, | |
) | |
astGrep_mcp = MCPToolset( | |
connection_params=StdioConnectionParams( | |
server_params=StdioServerParameters( | |
command="uv", | |
args=["run", "mcp-grep-server"], | |
), | |
timeout=300, # Set a timeout for the connection | |
), | |
auth_scheme=None, | |
auth_credential=None, | |
) | |
# read the mongoose migration files from ./Runbooks/mongoose/*.md | |
migratingFrom6to7Text = "" | |
with open("./Runbooks/mongoose/migratingFrom6to7.md", "r") as f: | |
migratingFrom6to7Text = f.read() | |
f.close() | |
migratingFrom7to8Text = "" | |
with open("./Runbooks/mongoose/migratingFrom7to8.md", "r") as f: | |
migratingFrom7to8Text = f.read() | |
f.close() | |
class Mongoose6to7FileAnalysisAgent(LlmAgent): | |
def __init__(self): | |
super().__init__( | |
name="Mongoose6to7FileAnalysis", | |
description="Analyze a specific JavaScript/TypeScript file for Mongoose migration issues from 6.x to 7.x.", | |
instruction=""" | |
Analyze a specific JavaScript/TypeScript file for Mongoose migration issues from 6.x to 7.x. | |
Use the file tool to read the content of the provided file path. | |
# Mongoose 6.x to 7.x Migration changes | |
``` | |
""" + migratingFrom6to7Text + """ | |
``` | |
You must compare the source code of the file with the migration changes. | |
Identify any breaking changes that affect the code as implemented. | |
Identify any code which needs to be updated to work with mongoose 7.x. | |
present the findings in a markdown report. | |
The report should include: | |
- The file path | |
- The issues found in the file, if any | |
- The suggested fixes for each issue | |
- A checklist of changes made | |
""", | |
tools=[roFilesystem_mcp], | |
sub_agents=[], | |
model=useModel, | |
output_key='mongoose6to7_analysis', | |
# generate_content_config=types.GenerateContentConfig(max_output_tokens=8096), | |
) | |
mongoose6to7_file_analysis_agent = Mongoose6to7FileAnalysisAgent() | |
mongoose6to7_file_analysis_tool = AgentTool( | |
agent=mongoose6to7_file_analysis_agent, | |
) | |
class Mongoose7to8FileAnalysisAgent(LlmAgent): | |
def __init__(self): | |
super().__init__( | |
name="Mongoose7to8FileAnalysis", | |
description="Analyze a specific JavaScript/TypeScript file for Mongoose migration issues from 7.x to 8.x.", | |
instruction=""" | |
Analyze a specific JavaScript/TypeScript file for Mongoose migration issues from 7.x to 8.x. | |
Use the file tool to read the content of the provided file path. | |
# Mongoose 7.x to 8.x Migration changes | |
``` | |
""" + migratingFrom7to8Text + """ | |
``` | |
You must compare the source code of the file with the migration changes. | |
Identify any breaking changes that affect the code as implemented. | |
Identify any code which needs to be updated to work with mongoose 7.x. | |
present the findings in a markdown report. | |
The report should include: | |
- The file path | |
- The issues found in the file, if any | |
- The suggested fixes for each issue | |
- A checklist of changes made | |
""", | |
tools=[roFilesystem_mcp], | |
sub_agents=[], | |
model=useModel, | |
output_key='mongoose7to8_analysis', | |
# generate_content_config=types.GenerateContentConfig(max_output_tokens=8096), | |
) | |
mongoose7to8_file_analysis_agent = Mongoose7to8FileAnalysisAgent() | |
mongoose7to8_file_analysis_tool = AgentTool( | |
agent=mongoose7to8_file_analysis_agent, | |
) | |
# parallelAnalysisAgent = SequentialAgent( | |
# name="ParallelFileAnalysisAgent", | |
# description="Analyze multiple JavaScript/TypeScript files in parallel for Mongoose migration issues.", | |
# sub_agents=[ | |
# mongoose6to7_file_analysis_agent, | |
# mongoose7to8_file_analysis_agent, | |
# ], | |
# ) | |
# parallelAnalysisTool = AgentTool( | |
# agent=parallelAnalysisAgent, | |
# skip_summarization=True | |
# ) | |
class RepoAnalysisAgent(LlmAgent): | |
def __init__(self): | |
super().__init__( | |
name="RepoAnalysisAgent", | |
instruction=""" | |
Your primary job is to follow user instructions and orchestrate the analysis of files, modules, folders, and more for changes necessary for mongoose 6 to 8 migrations. | |
Identify files in specified paths which that require Mongoose migration from 6.x to 7.x and 7.x to 8.x. | |
Analyze the files for Mongoose migration issues with the `FileAnalysisAgents` agent. | |
Write migration plans for each file that has issues, and save them in the same directory as the file. | |
Carry out other tasks as directed by the parent agent or the user. | |
Use tools provided to list files in the repositories and traverse directories. | |
# Making code changes (NO): | |
- Return to parent agent for code changes. | |
- You can not make changes to code or read files directly. | |
- You can not analyze files directly. | |
# When asked to analyze a repository, directory, or file: | |
- first, List the files in the repository or directory instructed. Always reference and use the full path. | |
- then, Iterate over the folders (and sub-folders) in the repository and analyze files that might need migration. | |
- then, Invoke the Mongoose analysis agents/tools which will run Mongoose 6 to 7 and 7 to 8 analysis. | |
- then, Write migration plans for each file that has issues, and save them in the same directory as the file. | |
- You may ignore __mocks__ and __tests__, unless the user specifically asks you to analyze them. | |
- Always use sequential thinking to think through your steps and feel free to adjust your plan as you go. | |
- If you encounter an error, analyze the error and try to fix it. Don't make the same mistake again. | |
- If the same error occurs repeatedly, ask the user for help. | |
# Using Planning Tools: | |
- State your current step, next step, and overall goal in the sequential thinking tool. | |
- Use the sequential thinking tool to plan your next steps and check back in with the sequential thinking tool after each major step. | |
# When searching for files: | |
- list_allowed_directories: Use this tool to list the allowed repositories and directories. | |
- Use absolute paths when referencing files or directories. | |
- When using the filesystem tool's search_files method, you should provide a simple name pattern '.md' rather than a regex. It's only meant for searching file names and folder names. | |
# Writing the report: | |
- *You MUST* provide a `content` parameter when using the filesystem tool to write files. | |
- Save the report next to the file to be changed with the prefix `migration-<filename>.md` using the filesystem tool. | |
- You MUST pass a `path` and `content` as a parameter to the filesystem tool when saving the report. | |
- The report should relate to one file. | |
- The report should be made in markdown format. | |
- The file must be saved next to the file to be changed. | |
- prefix the file with `migration-` to indicate it is a migration file. | |
- The report should include the file, the issue found, and the suggested fix, for each issue found. | |
- The report should include a checklist. | |
- If no changes are needed, no report should be made. | |
# If you encounter an error: | |
- analyze the error and try to fix it. Don't make the same mistake again. | |
- if the same error occurs repeatedly, ask the user for help. | |
When you are complete, you should report back to the parent agent with a summary of findings. | |
""", | |
tools=[ | |
lwFilesystem_mcp, | |
sequential_thinking, | |
mongoose7to8_file_analysis_tool, | |
mongoose6to7_file_analysis_tool, | |
], | |
sub_agents=[ | |
], | |
model=useModel, | |
) | |
repo_analysis_agent = RepoAnalysisAgent() | |
devInstructions = """ | |
You are bringing the code base up to date with the latest Mongoose 7.x and 8.x standards. | |
Migration plans have been written for each file (or module) that needs to be changed. | |
You should follow the migration plans and make the necessary changes to the code. | |
You should then update the migration plan with the changes made. | |
You should not remove migration plans, even if the code is updated unless directed to do so. | |
When editing a file: | |
view_file returns files with line numbers. | |
edit_file requires code as it stands in the files. | |
You must remove line numbers from the code before editing and present the code to edit as it appears in the file. | |
""" | |
typescript_agent = TypescriptAgent(devInstructions) | |
javascript_agent = JavascriptAgent(devInstructions) | |
class MongooseMigrationAgent(LlmAgent): | |
def __init__(self): | |
super().__init__( | |
name="MongooseMigrationOrchestrator", | |
instruction=""" | |
Follow all instructions provided by the user. | |
You are coordinating the analysis of JavaScript/TypeScript files in the specified repositories for Mongoose migration issues. | |
You should delegate the analysis of repositories to the RepoAnalysisAgent, which will identify files that need to be analyzed. | |
You should delegate code changes to the TypescriptAgent or the JavascriptAgent as appropriate. | |
After you get tool responses, you should show a markdown report of the analysis results, including: | |
- The repository name | |
- The file paths that were analyzed | |
- The issues found in each file, if any | |
When asked to analyze a repository: | |
- Delegate the task to the RepoAnalysisAgent. | |
- Traverse subdirectories and files in the folder. | |
When asked to make code changes: | |
- Delegate the task to the TypescriptAgent or the JavascriptAgent as appropriate. | |
- Delegate to the typescript agent for TypeScript files and the javascript agent for JavaScript files. | |
Tools: | |
- sequential thinking: Use this tool to plan your next steps and check back in with the sequential thinking tool after each major step to make sure the task is complete. | |
- filesystem: Use this tool to read, write, list, and edit files in the provided repositories. | |
""", | |
global_instruction=f""" | |
Current Directory: {os.getcwd()} | |
When asked to work in a repository, directory, or file, you should use the following absolute paths. These are the only paths you have access to: | |
g {repoPaths} | |
Team Members / Agents: | |
- Human in the loop: You can ask them for help if you get stuck or are unable to resolve an error. | |
- MongooseMigrationOrchestrator: This is you, the main agent coordinating the analysis. | |
- RepoAnalysisAgent: This agent will help you identify files that need to be analyzed for Mongoose migration issues. | |
- TypescriptAgent & JavascriptAgent: This agent will help you make code changes if needed. | |
General concerns: | |
- We must transition our code to using promises instead of callbacks with a `then().catch()` syntax. | |
- We must operate with `strictQuery: false`. It is already set globally. | |
- Focus on identifying breaking changes, including use of callbacks. | |
- We should not change any code that is not necessary to make the code work with mongoose 7.x and 8.x. | |
After you get tool responses, you should show a markdown report of the analysis results, including: | |
- The repository name | |
- The file paths that were analyzed | |
- The issues found in each file, if any | |
Migration Plans: | |
- migration plans are written in the folder of concern with the prefix `migration-<filename/module>.md`. | |
General Tools (You might have access to these tools.): | |
- sequential thinking: Use this tool to plan your next steps and check back in with the | |
- filesystem: Use this tool to read, write, list, and edit files in the provided repositories. | |
Use the migration guides provided to assist with the analysis. | |
""", | |
tools=[ | |
listFilesystem_mcp, | |
# astGrep_mcp, | |
sequential_thinking, | |
], | |
sub_agents=[ | |
repo_analysis_agent, | |
typescript_agent, | |
javascript_agent | |
], | |
model=useModel, | |
) | |
root_agent = MongooseMigrationAgent() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.adk.agents import Agent | |
from google.adk.events import Event | |
from google.adk.agents.invocation_context import InvocationContext | |
from google.genai.types import Content, Part | |
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset | |
from google.adk.tools.mcp_tool import StdioConnectionParams, StreamableHTTPConnectionParams, SseConnectionParams | |
from google.adk.tools.agent_tool import AgentTool | |
from pydantic import BaseModel, Field | |
from mcp import StdioServerParameters | |
import asyncio | |
import os | |
from google.adk.agents import LlmAgent | |
from google.adk.models.anthropic_llm import Claude # Import needed for registration | |
from google.adk.models.registry import LLMRegistry # Import needed for registration | |
from google.genai import types | |
useModel = "gemini-2.5-flash" | |
code_editor_mcp = MCPToolset( | |
connection_params=SseConnectionParams( | |
url="http://localhost:8001/sse", | |
), | |
) | |
sequential_thinking = MCPToolset( | |
connection_params=StdioServerParameters( | |
command='docker', | |
args= [ | |
"run", | |
"--rm", | |
"-i", | |
"mcp/sequentialthinking" | |
], | |
), | |
) | |
class JavascriptAgent(LlmAgent): | |
def __init__(self, specificInstructions: str | None = None): | |
if specificInstructions is not None: | |
specificInstructions = f"\n\nAdditional instructions and expectations:\n{specificInstructions}" | |
super().__init__( | |
name="JavascriptAgent", | |
instruction=f""" | |
Persona: | |
You are a Principal Javascript Engineer and have access to tools to assist you in writing code in the provided repositories. | |
Initial instructions and expectations: | |
Follow the instructions you are provided and use the tools available to you to accomplish the task. | |
Use the thinking tool to help you break down complex problems into manageable steps. | |
Always ensure that your code is well-structured, self documenting, follows best practices, and includes appropriate high level comments. | |
{specificInstructions} | |
Tools: | |
- code_editor_mcp: Use this tool to read, write, and edit files. You may run commands in the terminal with this tool. It has built in thinking capabilities to help you decide what to do next. | |
Javascript best practices: | |
- Always use 'strict mode' by adding 'use strict'; at the beginning of your scripts or functions to enforce stricter parsing and error handling. | |
- Prefer 'const' and 'let' over 'var' for variable declarations to ensure block scope and prevent accidental re-declarations. | |
- Prefer promises to Async/Await for handling asynchronous operations. | |
- Never use callbacks or `eval()`. | |
Code quality best practices: | |
- Follow a consistent coding style and adhere to established conventions | |
- Write modular, reusable, and maintainable code by breaking down complex logic into smaller functions and components. | |
- Include high-level comments to explain the purpose and functionality of code sections. | |
- Use meaningful variable and function names that accurately describe their purpose. | |
- Avoid code duplication by reusing existing functions and components. | |
""", | |
tools=[code_editor_mcp], | |
sub_agents=[], | |
model=useModel, | |
) | |
root_agent = JavascriptAgent() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.adk.agents import Agent | |
from google.adk.events import Event | |
from google.adk.agents.invocation_context import InvocationContext | |
from google.genai.types import Content, Part | |
from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset | |
from google.adk.tools.mcp_tool import StdioConnectionParams, StreamableHTTPConnectionParams, SseConnectionParams | |
from google.adk.tools.agent_tool import AgentTool | |
from pydantic import BaseModel, Field | |
from mcp import StdioServerParameters | |
import asyncio | |
import os | |
from google.adk.agents import LlmAgent | |
from google.adk.models.anthropic_llm import Claude # Import needed for registration | |
from google.adk.models.registry import LLMRegistry # Import needed for registration | |
from google.genai import types | |
useModel = "gemini-2.5-flash" | |
code_editor_mcp = MCPToolset( | |
connection_params=SseConnectionParams( | |
url="http://localhost:8001/sse", | |
), | |
) | |
sequential_thinking = MCPToolset( | |
connection_params=StdioServerParameters( | |
command='docker', | |
args= [ | |
"run", | |
"--rm", | |
"-i", | |
"mcp/sequentialthinking" | |
], | |
), | |
) | |
class TypescriptAgent(LlmAgent): | |
def __init__(self, specificInstructions: str | None = None): | |
if specificInstructions is not None: | |
specificInstructions = f"\n\nAdditional instructions and expectations:\n{specificInstructions}" | |
super().__init__( | |
name="TypescriptAgent", | |
instruction=f""" | |
You are a Principal Typescript Engineer and have access to tools to assist you in writing code in the provided repositories. | |
Initial instructions and expectations: | |
Follow the instructions you are provided and use the tools available to you to accomplish the task. | |
Use the thinking tool to help you break down complex problems into manageable steps. | |
Always ensure that your code is well-structured, self documenting, follows best practices, and includes appropriate high level comments. | |
{specificInstructions} | |
Tools: | |
- code_editor_mcp: Use this tool to read, write, and edit files. You may run commands in the terminal with this tool. It has built in thinking capabilities to help you decide what to do next. | |
Typing best practices: | |
- Use TypeScript's static typing features to define types for variables, function parameters, and return values. | |
- Create and use interfaces and type aliases to define complex types and ensure consistency across your codebase. | |
- Leverage TypeScript's type inference capabilities to reduce redundancy and improve code readability. | |
- Use generics to create reusable and flexible components and functions. | |
- Prefer async/Await for handling asynchronous operations. | |
- Never use callbacks or `eval()`. | |
Code quality best practices: | |
- Follow a consistent coding style and adhere to established conventions | |
- Write modular, reusable, and maintainable code by breaking down complex logic into smaller functions and components. | |
- Include high-level comments to explain the purpose and functionality of code sections. | |
- Use meaningful variable and function names that accurately describe their purpose. | |
- Avoid code duplication by reusing existing functions and components. | |
""", | |
tools=[code_editor_mcp], | |
sub_agents=[], | |
model=useModel, | |
) | |
root_agent = TypescriptAgent() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment