Agent Starter Pack

repository·main·Indexed 27 days ago

https://github.com/googlecloudplatform/agent-starter-pack

A Python package and CLI (v0.41.3) providing production-ready templates for Generative AI agents on Google Cloud. It automates infrastructure provisioning via Terraform, CI/CD setup, observability, and security. The tool supports Go, Java, and Python agent projects, offering features for local development (playground), load testing, and deployment to Cloud Run, GKE, or Agent Engine.

Tokens
47K
Snippets
111
Records
261
Agent score
90%

What's inside agent-starter-pack

  1. Overview of Remote Template workflow

    main

    The Remote Template system follows a five-step process to transform a Git repository into a deployable application:

    1. Fetching: Retrieves the template repository from Git.
    2. Version locking: Automatically uses the exact starter pack version specified by the template to ensure compatibility.
    3. Applying: Uses intelligent defaults based on the repository structure.
    4. Merging: Combines template files with the base agent infrastructure.
    5. Generating: Produces a complete, production-ready agent project.
  2. Overview of Agent Starter Pack features

    main

    The Agent Starter Pack is designed to accelerate the development of production-ready agents on Google Cloud. Key capabilities include:

    • Pre-built Templates: Rapidly launch agents using patterns like ReAct, RAG, multi-agent, and Live Multimodal API.
    • Experimentation & Evaluation: Iterate on agent performance using integrated Vertex AI evaluation and an interactive testing playground.
    • Production Deployment: Deploy to Cloud Run or Agent Engine with built-in monitoring, observability, and CI/CD.
    • Extensibility: Customize existing templates or build new ones from scratch.
  3. Project Structure for Go Agents

    main

    A standard Go agent project generated by this template follows this structure:

    • main.go: Application entry point.
    • agent/agent.go: Core agent implementation logic.
    • e2e/: Contains integration/ and load_test/ directories.
    • deployment/terraform/: Infrastructure as Code (Terraform).
    • go.mod: Go module definition.
    • Dockerfile: Container build instructions.
    • Makefile: Common development commands.
  4. Understand the Agent Starter Pack value proposition

    main

    The Agent Starter Pack is designed to bridge the 'production gap' between a Generative AI prototype and a production-ready agent. It provides a template foundation so developers can focus on core agent logic while the starter pack handles the 'last mile' requirements.

    Core Agent Focus (Your Responsibility)

    • Prompts and LLM interactions
    • Business logic integration
    • Agent orchestration (e.g., Google ADK, LangGraph, Agent2Agent (A2A))
    • Tools and data source definitions

    Starter Pack Foundation (Provided by Template)

    • Deployment & Operations: API server, serving options, CI/CD pipelines, Infrastructure as Code (IaC), and testing.
    • Observability: Logging, tracing, and monitoring dashboards.
    • Evaluation: Vertex AI Evaluation integration.
    • Data & UI: Storage connections, vector stores, and a UI playground.
    • Security: Implementation of GCP security best practices.
  5. Understand the Deployment Workflow

    main

    The project follows a structured CI/CD workflow to ensure safe and reliable deployments:

    1. CI Pipeline: Triggered on pull request creation/update. Runs unit and integration tests.
    2. Staging CD Pipeline: Triggered on merge to main. Builds/pushes container to Artifact Registry, deploys to the staging environment, and performs automated load testing.
    3. Production Deployment: Triggered after successful staging deployment. Requires manual approval before deploying the same container image to the production environment.
  6. Create a new agent project

    main

    You can initialize a new agent project using either a traditional pip workflow or the uvx command for a single-command setup without a permanent installation.

    Using pip

    1. Create and activate a virtual environment.
    2. Install the agent-starter-pack package.
    3. Run the create command.

    Using uvx

    Run the create command directly using uvx to download and execute the latest version immediately.

    # 1. Create and activate a virtual environment
    python -m venv .venv
    source .venv/bin/activate
    
    # 2. Install the package
    pip install agent-starter-pack
    
    # 3. Run the create command
    agent-starter-pack create
    # This single command downloads and runs the latest version
    uvx agent-starter-pack create
  7. Disable prompt-response logging in deployed environments

    main

    Prompt-response logging is enabled by default in Terraform-managed environments (dev, staging, prod). Use one of the following methods to disable it.

    For Cloud Run Deployments

    Method 1: Terraform (Permanent) Edit deployment/terraform/[dev/]service.tf to set the environment variable to false:

    env {
      name  = "OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"
      value = "false"
    }

    Then apply the changes:

    cd deployment/terraform
    terraform apply -var-file=vars/[dev/staging/prod].tfvars

    Method 2: gcloud CLI (Temporary) Update the service directly. Note that this will be reverted on the next Terraform apply:

    gcloud run services update YOUR_SERVICE_NAME \
      --update-env-vars OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=false \
      --region=YOUR_REGION \
      --project=YOUR_PROJECT_ID

    For Agent Engine Deployments

    Modify app_utils/deploy.py to set the environment variable to false:

    # Remove or set to "false"
    env_vars["OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT"] = "false"

    Then redeploy using:

    make deploy
  8. Test Cloud Run deployment

    main

    To test an agent deployed to Cloud Run, retrieve the SERVICE_URL from deployment_metadata.json.

    1. Testing Notebook: Use jupyter notebook notebooks/adk_app_testing.ipynb.
    2. Python Script: Use requests to create a session via the /apps/<agent-directory>/users/<user_id>/sessions endpoint, then send messages to the /run_sse endpoint using an identity token for authorization.
    3. Playground: Run make playground.
    import json
    import requests
    
    SERVICE_URL = "YOUR_SERVICE_URL"  # From deployment_metadata.json
    ID_TOKEN = !gcloud auth print-identity-token -q
    headers = {"Content-Type": "application/json", "Authorization": f"Bearer {ID_TOKEN[0]}"}
    
    # Step 1: Create a session
    user_id = "test_user"
    session_resp = requests.post(
        f"{SERVICE_URL}/apps/<your-agent-directory>/users/{user_id}/sessions",
        headers=headers,
        json={"state": {}}
    )
    session_id = session_resp.json()["id"]
    
    # Step 2: Send a message
    message_resp = requests.post(
        f"{SERVICE_URL}/run_sse",
        headers=headers,
        json={
            "app_name": "<your-agent-directory>",
            "user_id": user_id,
            "session_id": session_id,
            "new_message": {"role": "user", "parts": [{"text": "Hello!"}]},
            "streaming": True
        },
        stream=True
    )
    
    for line in message_resp.iter_lines():
        if line and line.decode().startswith("data: "):
            print(json.loads(line.decode()[6:]))
  9. Deploy infrastructure and set up CI/CD via CLI

    main
    The recommended method to provision Google Cloud infrastructure and configure the CI/CD pipeline for your agent is to use the agent-starter-pack setup-cicd command executed from the root of your project. This automates the application of Terraform configurations found in the deployment directory.
    agent-starter-pack setup-cicd
  10. Create a Remote Template

    main

    Remote templates allow you to package custom agent logic, dependencies, and infrastructure into a Git repository for others to reuse.

    Requirements

    • pyproject.toml (Required): Must be at the repository root. It defines Python dependencies and optional [tool.agent-starter-pack] configuration.
    • uv.lock (Recommended): Include this for reproducible builds and exact dependency versions.

    Quick Start Workflow

    1. Structure: Create a directory containing pyproject.toml, an app/ directory (or custom agent_directory), and a README.md.
    2. Configure: Define base_template and settings in pyproject.toml.
    3. Logic: Implement your agent in app/agent.py.
    4. Test: Use uvx agent-starter-pack create <name> -a local@./<path-to-template>.
    5. Publish: Push your repository to a Git provider (e.g., GitHub).
    6. Share: Users can then run uvx agent-starter-pack create <name> -a <git-url>.