Orchestrating Edge Automation with Gemini API & Custom JSON Schemas

Hello Developers,

​I wanted to share our system architecture approach at Cortex Intelligence Nexus Intel Solution, where we’ve integrated the Gemini API to handle dynamic workflow orchestration and structured data operations.

​Key Implementation Highlights:

​Schema Validation: Enforcing strict JSON Schemas across API responses to ensure structural integrity and eliminate output hallucinations during automated task execution.

​Edge & Terminal Execution: Running lightweight Python automation wrappers in isolated environments for rapid event triggers.

​Pipeline Integration: Deploying API endpoints with custom webhooks, automated build tracking, and centralized human verification loops for critical operations.

┌───────────────────────────────────────────────────────────┐

│ CINIS Edge Automation Architecture │

└─────────────────────────────┬─────────────────────────────┘

                          │

                          ▼

┌───────────────────────────────────────────────────────────┐

│ 1. Edge Execution Node (Termux / Pydroid-3 Python Engine) │

│ - Triggered by mobile terminal / local cron task │

│ - Defines Task Payload & System Context │

└─────────────────────────────┬─────────────────────────────┘

                          │ (HTTPS / API Request)

                          ▼

┌───────────────────────────────────────────────────────────┐

│ 2. Gemini API Engine (Structured Output Mode) │

│ - Enforces Pydantic / JSON Schema validation │

│ - Evaluates tasks & generates deterministic JSON data │

└─────────────────────────────┬─────────────────────────────┘

                          │ (Strict JSON Response)

                          ▼

┌───────────────────────────────────────────────────────────┐

│ 3. Centralized Human Gateway & Verification Loop │

│ - Validates execution payload │

│ - Triggers Netlify Webhooks / Deployment State Changes │

└───────────────────────────────────────────────────────────┘

import os

from typing import List

from pydantic import BaseModel, Field

from google import genai

from google.genai import types

# 1. Define strict output schema using Pydantic

class TaskStep(BaseModel):

step_number: int

action: str = Field(description="Specific automation action to execute")

requires_human_verification: bool = Field(

    description="Flag indicating if central gateway approval is required"

)

class WorkflowPlan(BaseModel):

workflow_id: str

target_environment: str

steps: List\[TaskStep\]

# 2. Initialize Gemini Client

client = genai.Client(api_key=os.environ.get(“GEMINI_API_KEY”))

# 3. Request structured output from Gemini API

prompt = “”"

Analyze the following deployment trigger:

‘Verify Netlify build hooks, validate structural integrity of build artifacts, and prepare update payload.’

“”"

response = client.models.generate_content(

model='gemini-2.5-flash',

contents=prompt,

config=types.GenerateContentConfig(

    response_mime_type="application/json",

    response_schema=WorkflowPlan,

    temperature=0.1,  # Low temperature for deterministic output

),

)

# Output strictly adheres to defined schema

print(response.text)