Connect GitHub to Google Cloud with Developer Connect

1. Introduction

In this codelab, you will create a secure connection to a GitHub repository using Developer Connect and use that connection to directly deploy an agent using Agent Runtime on Gemini Enterprise Agent Platform.

Developer Connect establishes connectivity by walking you through permissions, authorization, authentication, and networking configurations to non-Google developer tools. This provides a direct, native way to pull your application code into Google Cloud services.

For this codelab, we will utilize a Developer Connect Git Repository Connection to directly deploy an agent using Agent Runtime on Gemini Enterprise Agent Platform. Developer Connect supports GitHub, GitHub Enterprise, Bitbucket Cloud, Bitbucket Data Center, Gitlab and GitLab Enterprise. In this codelab, we will walk through a connection to GitHub.

What you'll do

  • Create a basic agent on Agent Runtime and push it to GitHub
  • Use Developer Connect to link your GitHub repository to Google Cloud
  • Deploy the agent on Agent Runtime using your connected repository natively
  • Invoke and test your deployed remote agent

What you'll need

  • A web browser such as Chrome
  • A Google Cloud project with billing enabled
  • A GitHub account and a Personal Access Token (classic) with repository access

This codelab is for developers of all levels, including beginners. The resources managed in this codelab are mostly serverless APIs and should cost under $1.

2. Before you begin

Create a Google Cloud Project

  1. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.
  2. Make sure that billing is enabled for your Cloud project. Learn how to check if billing is enabled on a project.

Start Cloud Shell

  1. Click Activate Cloud Shell at the top of the Google Cloud console.
  2. Once connected to Cloud Shell, verify your authentication:
    gcloud auth list
    
  3. Confirm your project is configured:
    export PROJECT_ID=$(gcloud config get-value project)
    
  4. If your project is not set as expected, set it:
    export PROJECT_ID=<YOUR_PROJECT_ID>
    gcloud config set project $PROJECT_ID
    

Enable APIs

Run this command to enable all the required APIs for Developer Connect and Vertex AI:

gcloud services enable \
  developerconnect.googleapis.com \
  aiplatform.googleapis.com

3. Prepare the Agent Source Code

First, you'll create a new GitHub repository to hold your agent source code, and add a simple Python reasoning agent to it.

  1. Log in to your GitHub account.
  2. Create a new, private repository called devconnect-agent.
  3. Do not initialize it with a README or .gitignore.

Create the agent files locally

Back in your Cloud Shell terminal, create a directory for your agent and define its dependencies:

mkdir -p devconnect-agent/test
cd devconnect-agent

Create a requirements.txt file in the test directory specifying the Agent Runtime libraries:

cat <<EOF > test/requirements.txt
google-cloud-aiplatform[agent_engines]
EOF

Create a my_agent.py file in the test directory. This script defines a simple agent answering list queries:

cat <<EOF > test/my_agent.py
class MyAgent:

  def query_none(self):
    return None

  def query_list(self):
    return [1, 2, 3]

  def register_operations(self):
    return {
        "": ["query_none", "query_list"],
    }

agent = MyAgent()
EOF

Push the code to GitHub

Initialize a Git repository and push your code to your newly created GitHub repository.

Replace `<YOUR_GITHUB_USERNAME>` with your GitHub username and `<YOUR_GITHUB_TOKEN>` with your Personal Access Token.

git init
git branch -M main
git add .
git commit -m "Initial commit of agent source"
git remote add origin https://<YOUR_GITHUB_TOKEN>@github.com/<YOUR_GITHUB_USERNAME>/devconnect-agent.git
git push -u origin main

4. Configure Developer Connect

Now that your repository is on GitHub, Developer Connect will securely link your Google Cloud project to it.

Set up IAM permissions

Authorize Developer Connect to access your Google Cloud project by generating a service identity.

gcloud beta services identity create \
    --service=developerconnect.googleapis.com \
    --project=$PROJECT_ID

You can create the connection and link using either the Google Cloud console or the gcloud CLI.

Option 1: Using the Google Cloud console

  1. In the Google Cloud console, navigate to Developer Connect.
  2. Click Connect under GitHub
  3. Name your Connection my-github-connection and select it in us-central1
  4. Follow the prompts to authorize the Developer Connect GitHub app.
  5. Select the devconnect-agent repository to link it to your project.

Option 2: Using the gcloud CLI

Run the following commands in Cloud Shell to link your GitHub repository.

First, you will need to grant the Developer Connect service account access to Secret Manager.

# Get the service account
SERVICE_ACCOUNT=$(gcloud beta services identity create \
    --service=developerconnect.googleapis.com \
    --project=$PROJECT_ID \
    --format="value(email)")

# Grant access to Secret Manager
gcloud projects add-iam-policy-binding $PROJECT_ID \
    --member="serviceAccount:$SERVICE_ACCOUNT" \
    --role="roles/secretmanager.admin"
# 1. Create the general Developer Connect connection to GitHub
gcloud developer-connect connections create my-github-connection \
    --location=us-central1 \
    --github-config-app=developer-connect
# 2. Link your specific agent repository to the connection
# Replace <YOUR_GITHUB_USERNAME> with your actual GitHub username
gcloud developer-connect connections git-repository-links create devconnect-agent \
    --connection=my-github-connection \
    --location=us-central1 \
    --clone-uri=https://github.com/<YOUR_GITHUB_USERNAME>/devconnect-agent.git

5. Deploy the Agent from Developer Connect

With your repository securely connected, you can directly deploy an Agent Runtime agent leveraging the Developer Connect link natively.

Deploy the Agent Runtime

Create and run a Python script locally in Cloud Shell to deploy your agent using the Vertex AI SDK.

cd ~
cat <<EOF > deploy.py
import vertexai

PROJECT_ID = "$PROJECT_ID"
LOCATION = "us-central1"

vertexai.init(project=PROJECT_ID, location=LOCATION)
client = vertexai.Client(project=PROJECT_ID, location=LOCATION)

# Define the full URI string for the Developer Connect repository link
repo_link = f"projects/{PROJECT_ID}/locations/{LOCATION}/connections/my-github-connection/gitRepositoryLinks/devconnect-agent"

print("Deploying to Agent Runtime from Developer Connect...")

remote_agent = client.agent_engines.create(
    config={
        "developer_connect_source": {
            "git_repository_link": repo_link,
            "revision": "main",
            "dir": "test",
        },
        "entrypoint_module": "my_agent",
        "entrypoint_object": "agent",
        "requirements_file": "requirements.txt",
        "class_methods": [
            {"name": "query_list", "api_mode": ""}
        ],
        "display_name": "DevConnect Agent",
    },
)

print(f"Agent Runtime deployed successfully: {remote_agent.api_resource.name}")
EOF

Configure the default application credentials in gcloud.

gcloud auth application-default login

Run the deployment script. Note that this architecture allows Vertex AI to bypass local execution scopes entirely and build the remote agent image from source.

python3 deploy.py

Test the Agent

Once deployment finishes, run a script to query your agent endpoint.

cat <<EOF > invoke.py
import vertexai

PROJECT_ID = "$PROJECT_ID"
LOCATION = "us-central1"

client = vertexai.Client(project=PROJECT_ID, location=LOCATION)

# Retrieve the latest reasoning engine
engines = list(client.agent_engines.list())
if engines:
    agent = client.agent_engines.get(name=engines[0].api_resource.name)
    print("Invoking remote agent via endpoint...")
    # NOTE: Invoking remote agent
    response = agent.query_list()
    print(f"Agent response: {response}")
else:
    print("No deployment found.")
EOF

python3 invoke.py

You should see output similar to:

Invoking remote agent via endpoint...
Agent response: [1, 2, 3]

6. Clean up

To avoid ongoing charges to your Google Cloud account, delete the resources created during this codelab.

Clean up the Developer Connect and Agent Runtime resources:

cat <<EOF > cleanup.py
import vertexai

PROJECT_ID = "$PROJECT_ID"
LOCATION = "us-central1"

client = vertexai.Client(project=PROJECT_ID, location=LOCATION)

for engine in client.agent_engines.list():
    print(f"Deleting {engine.api_resource.name}")
    engine.delete()
EOF

python3 cleanup.py

Clean up Developer Connect resources:

gcloud developer-connect connections git-repository-links delete devconnect-agent \
    --connection=my-github-connection \
    --location=us-central1 \
    --quiet

gcloud developer-connect connections delete my-github-connection \
    --location=us-central1 \
    --quiet

7. Congratulations

Congratulations! You securely established a GitHub repository integration using Developer Connect and natively deployed an AI agent directly from your source tree.

What you've learned

  • Configured a Google Cloud project with Developer Connect and Vertex AI
  • Securely stored a Personal Access Token into Secret Manager
  • Generated Developer Connect connections explicitly via the gcloud CLI
  • Created a Vertex AI Agent Runtime instance programmatically, using the developer_connect_source object mapping.

Next steps

Reference docs