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
https://agentflow-processor-xyz-uc.a.run.appStep 2: Setup Authentication
Create Service Account
Generate Auth Token
Step 3: Create AI Connection in AgentFlow
Manual Configuration
- Admin Dashboard → AI Models → Add Model
-
Basic Info:
- Name:
Cloud Run AI Processor - Model ID:
cloud-run-function-executor - Description:
Serverless AI processing via Google Cloud Run
- Name:
-
API Settings:
- Endpoint:
https://agentflow-processor-xyz-uc.a.run.app/process - Method: POST
- Endpoint:
-
Headers:
-
Request Schema:
-
Response Path:
data.result - Save
Step 4: Import via YAML
YAML Configuration
Createcloud-run-function-config.yaml:
Import Process
- Update all
{{placeholder}}values - Admin Dashboard → AI Models → Import Model
- Upload YAML
- Enter credentials
- Import
Step 5: Assign to Group
- Admin Dashboard → Groups
- Select group (e.g., “Development Team”)
- Manage Models → Enable Cloud Run Function
- Configure:
- Execution Limit: 10,000/day
- Timeout: 5 minutes
- Priority: High
- Save
Step 6: Use in Chat
Trigger Functions
- Chat → New Conversation
- Select Cloud Run AI Processor
- 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
| Resource | Cost |
|---|---|
| CPU | $0.00002400/vCPU-second |
| Memory | $0.00000250/GiB-second |
| Requests | $0.40/million requests |
| Networking | $0.12/GB egress |
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
503 Service Unavailable
503 Service Unavailable
429 Too Many Requests
429 Too Many Requests
Cause: Rate limit exceededFix:
- Increase max-instances
- Implement request queuing
- Distribute across regions
Memory Exceeded
Memory Exceeded
Symptoms: OOM errors in logsFix:
- Increase memory allocation
- Optimize code for memory efficiency
- Implement streaming for large data
Authentication Failed
Authentication Failed
Check:
- Service account permissions
- Token validity
- IAM policies