Skip to main content

Overview

Execute Google Cloud Run functions from AgentFlow for serverless AI processing and automation. Build custom logic that scales automatically and integrates with Google Cloud services.

Prerequisites

Google Cloud Account

Active GCP account with billing enabled

Cloud Run Access

Permissions to deploy Cloud Run services

gcloud CLI

Install and configure gcloud CLI

AgentFlow Admin

Admin access required

Step 1: Setup Google Cloud Run Function

Install Prerequisites

1

Install gcloud CLI

2

Authenticate

3

Enable APIs

Create Cloud Run Function

1

Initialize Project

2

Create main.py

3

Create requirements.txt

4

Create Dockerfile

Deploy to Cloud Run

1

Build Container

2

Deploy Service

3

Get Service URL

Output: https://agentflow-processor-xyz-uc.a.run.app

Step 2: Setup Authentication

Create Service Account

Generate Auth Token


Step 3: Create AI Connection in AgentFlow

Manual Configuration

  1. Admin DashboardAI ModelsAdd Model
  2. Basic Info:
    • Name: Cloud Run AI Processor
    • Model ID: cloud-run-function-executor
    • Description: Serverless AI processing via Google Cloud Run
  3. API Settings:
    • Endpoint: https://agentflow-processor-xyz-uc.a.run.app/process
    • Method: POST
  4. Headers:
  5. Request Schema:
  6. Response Path: data.result
  7. Save

Step 4: Import via YAML

YAML Configuration

Create cloud-run-function-config.yaml:

Import Process

  1. Update all {{placeholder}} values
  2. Admin DashboardAI ModelsImport Model
  3. Upload YAML
  4. Enter credentials
  5. Import

Step 5: Assign to Group

  1. Admin DashboardGroups
  2. Select group (e.g., “Development Team”)
  3. Manage Models → Enable Cloud Run Function
  4. Configure:
    • Execution Limit: 10,000/day
    • Timeout: 5 minutes
    • Priority: High
  5. Save

Step 6: Use in Chat

Trigger Functions

  1. ChatNew Conversation
  2. Select Cloud Run AI Processor
  3. Send message

Example Use Cases


Advanced Function Examples

Image Processing Function

Data Processing Function

Translation Function


Scaling & Performance

Auto-Scaling Configuration

Performance Optimization

1

Cold Start Reduction

  • Use minimum instances (min-instances=1)
  • Optimize container size
  • Implement connection pooling
2

Memory Optimization

3

CPU Allocation

4

Concurrency Tuning

Regional Deployment

Deploy to multiple regions:

Monitoring & Logging

Cloud Logging

View logs:

Cloud Monitoring

Setup alerts:

Custom Metrics


Security Best Practices

Authentication

Always require authentication for sensitive endpoints

Service Accounts

Use least-privilege service accounts

Secrets Management

Store secrets in Secret Manager, not environment variables

Network Security

Use VPC connectors for private resources

Input Validation

Validate and sanitize all inputs

Audit Logging

Enable Cloud Audit Logs

Using Secret Manager


Cost Optimization

Pricing Breakdown

Optimization Strategies

1

Right-Size Resources

Match CPU/memory to actual needs
2

Minimize Cold Starts

Use min-instances only when necessary
3

Optimize Container

Reduce image size and dependencies
4

Cache Responses

Implement caching for repeated queries
5

Batch Processing

Process multiple items per request

Troubleshooting

Causes:
  • Cold start timeout
  • Resource limits exceeded
  • Deployment issues
Fix:
  • Increase timeout
  • Add min-instances
  • Check deployment logs
Cause: Rate limit exceededFix:
  • Increase max-instances
  • Implement request queuing
  • Distribute across regions
Symptoms: OOM errors in logsFix:
  • Increase memory allocation
  • Optimize code for memory efficiency
  • Implement streaming for large data
Check:
  • Service account permissions
  • Token validity
  • IAM policies
Fix: Regenerate credentials

CI/CD Integration

GitHub Actions Deployment


Next Steps

LangChain Agents

Build AI agents with tools

Workflow Automation

Combine with n8n workflows

OpenAI Assistants

Advanced AI agents

Analytics

Monitor function performance