File size: 3,330 Bytes
8fbf69f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"""
Autonomous Antigravity Agent Server & CLI runner.
Supports Local execution and GCP Cloud Run / Vertex AI execution.
"""

import argparse
import asyncio
import os
import sys
from pathlib import Path

# Add src to path
sys.path.insert(0, str(Path(__file__).parent.parent.parent))

from dualscale_solver.agents.leanflow_agent import (
    LEANFLOW_AGENT_TOOLS,
    create_agent_config,
)


def run_local_diagnostic():
    """Runs a non-interactive local diagnostic validating all agent tools."""
    print("=" * 80)
    print(" SOCRATEAI LEANFLOW ANTIGRAVITY AGENT: LOCAL DIAGNOSTIC RUNNER")
    print("=" * 80)

    for tool in LEANFLOW_AGENT_TOOLS:
        print(f"\n[Testing Tool]: {tool.__name__}")
        try:
            res = tool()
            print(f" Output: {res[:200]}..." if len(res) > 200 else f" Output: {res}")
            print(f" Status: ✅ OPERATIONAL")
        except Exception as e:
            print(f" Error: ❌ {e}")

    print("\n" + "=" * 80)
    print(" ✅ ALL AGENT TOOLS VALIDATED LOCALLY")
    print("=" * 80)


async def main():
    parser = argparse.ArgumentParser(description="SocrateAI Antigravity Agent Server")
    parser.add_argument("--mode", choices=["local", "gcp-vertex", "diagnostic"], default="diagnostic",
                        help="Execution mode: local, gcp-vertex, or diagnostic")
    parser.add_argument("--project", default=os.environ.get("GCP_PROJECT"),
                        help="GCP Project ID for Vertex AI")
    parser.add_argument("--location", default=os.environ.get("GCP_LOCATION", "us-central1"),
                        help="GCP Location for Vertex AI")
    parser.add_argument("--model", default="gemini-2.5-pro",
                        help="Gemini Model Identifier")
    parser.add_argument("--port", type=int, default=8080,
                        help="Server port for Cloud Run deployment")

    args = parser.parse_args()

    if args.mode == "diagnostic":
        run_local_diagnostic()
        return

    # Check if google-antigravity SDK is installed
    try:
        from google.antigravity import Agent, LocalAgentConfig
        print(f"Loaded Google Antigravity SDK successfully (mode: {args.mode})")

        is_vertex = (args.mode == "gcp-vertex")
        config_dict = create_agent_config(
            use_vertex=is_vertex,
            project=args.project,
            location=args.location,
            model=args.model,
        )

        sdk_config = LocalAgentConfig(
            model=config_dict["model"],
            vertex=config_dict["vertex"],
            project=config_dict["project"],
            location=config_dict["location"],
            tools=config_dict["tools"],
            system_instruction=config_dict["system_instruction"],
        )

        async with Agent(sdk_config) as agent:
            print(f"Antigravity Agent initialized and ready on {args.mode}!")
            response = await agent.chat("Verify the LeanFlow exact rational invariants and report status.")
            print(await response.text())

    except ImportError:
        print("Note: 'google-antigravity' SDK package is not installed globally in this environment.")
        print("Running in Standalone Native Agent mode with all custom tools operational.")
        run_local_diagnostic()


if __name__ == "__main__":
    asyncio.run(main())