Skip to content

armgit / ax

Public Imported from GitHub
0

Agent Executor (AX) is Google's open agentic orchestration runtime

Go

Relocate antigravity agent source files from the examples directory (#205)

Jaana Doganb6fe49a25db6
diff --git a/cmd/ax/Dockerfile b/cmd/ax/Dockerfile
index 9f06dc7..3db2a25 100644
--- a/cmd/ax/Dockerfile
+++ b/cmd/ax/Dockerfile
@@ -46,7 +46,6 @@ RUN pip install --no-cache-dir -r /tmp/requirements.txt
# Python sidecar (with generated proto stubs), the agent it serves, and the ax
# binary built in stage 1.
COPY python/ /ax-app/python
-COPY examples/antigravity_agent/ /ax-app/examples/antigravity_agent
COPY examples/skills/ /ax/skills/
ENV SKILLS_DIR=/ax/skills
COPY --from=build /out/ax /ax-app/ax
@@ -64,5 +63,4 @@ EXPOSE 80
# the ActorTemplate `command` instead. `ax harness` forks the Python sidecar,
# which serves the HarnessService on :80.
CMD ["/ax-app/ax", "harness", \
- "--antigravity-agent-file", "/ax-app/examples/antigravity_agent/agent.py", \
"--host", "0.0.0.0", "--port", "80"]
diff --git a/cmd/ax/harness.go b/cmd/ax/harness.go
index ecd698b..cf6470a 100644
--- a/cmd/ax/harness.go
+++ b/cmd/ax/harness.go
@@ -30,9 +30,8 @@ import (
)
var (
- harnessPort int
- harnessHost string
- harnessAntigravityAgentFile string
+ harnessPort int
+ harnessHost string
)
var harnessCmd = &cobra.Command{
@@ -45,7 +44,6 @@ var harnessCmd = &cobra.Command{
func init() {
harnessCmd.Flags().IntVar(&harnessPort, "port", 50053, "Port for the HarnessService to listen on")
harnessCmd.Flags().StringVar(&harnessHost, "host", "127.0.0.1", "Host interface for the HarnessService to bind")
- harnessCmd.Flags().StringVar(&harnessAntigravityAgentFile, "antigravity-agent-file", "examples/antigravity_agent/agent.py", "Path to the agent config file the Python sidecar serves")
rootCmd.AddCommand(harnessCmd)
}
@@ -75,7 +73,6 @@ func runHarness(cmd *cobra.Command, args []string) error {
py := exec.Command("python3", "-m", "python.antigravity.harness_server",
"--host", harnessHost,
"--port", strconv.Itoa(harnessPort),
- "--agent_file", harnessAntigravityAgentFile,
)
py.Stdin = os.Stdin
py.Stdout = os.Stdout
diff --git a/examples/antigravity_agent/README.md b/examples/antigravity_agent/README.md
deleted file mode 100644
index 400de30..0000000
--- a/examples/antigravity_agent/README.md
+++ /dev/null
@@ -1,27 +0,0 @@
-# Antigravity Agent Example
-
-This directory contains a simple example of an agent built using the `google-antigravity` SDK.
-
-## Prerequisites
-
-Ensure you have Python 3.10+ installed.
-
-## Setup
-
-1. Install the required dependencies:
- ```bash
- pip install -r requirements.txt
- ```
-
-2. Set your Gemini API key in your environment:
- ```bash
- export GEMINI_API_KEY="your-api-key-here"
- ```
-
-## Running the Agent
-
-Run the agent script directly:
-
-```bash
-python agent.py
-```
diff --git a/examples/antigravity_agent/agent.py b/examples/antigravity_agent/agent.py
deleted file mode 100644
index b5bf538..0000000
--- a/examples/antigravity_agent/agent.py
+++ /dev/null
@@ -1,91 +0,0 @@
-# Copyright 2026 Google LLC
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-# NOTE ON ARCHITECTURE:
-# This file plays a dual-purpose role:
-# 1. Standalone Sandbox: Can be run directly via CLI (python agent.py "prompt") for local L2 debugging.
-# 2. Declarative Config Module: Exposes 'agent_config' globally, which python/antigravity/harness_server.py
-# dynamically imports to serve this agent over production gRPC.
-
-import asyncio
-
-import sys
-from google.antigravity import LocalAgentConfig
-from google.antigravity.connections.local import LocalConnectionStrategy
-from google.antigravity.conversation.conversation import Conversation
-from google.antigravity.tools.tool_runner import ToolRunner
-from google.antigravity.types import Text, Thought, ToolCall
-
-# 1. Define a custom local python tool
-def get_weather(city: str) -> str:
- """Retrieves the current weather report for a specified city.
-
- Args:
- city (str): The name of the city for which to retrieve the weather report.
-
- Returns:
- str: Weather report status and details.
- """
- # Output to stderr so it does not pollute the stdout stream capture
- sys.stderr.write(f"\n[PYTHON TOOL get_weather executed for city: {city}]\n")
- sys.stderr.flush()
- c = city.lower()
- if "new york" in c or "nyc" in c:
- return "The weather in New York is sunny with a temperature of 25 degrees Celsius (77 degrees Fahrenheit)."
- elif "san francisco" in c or "sf" in c:
- return "The weather in San Francisco is foggy with a temperature of 16 degrees Celsius (60.8 degrees Fahrenheit)."
- else:
- return f"Weather information for '{city}' is not available."
-
-# 2. Expose agent_config globally for harness_server.py config loading
-agent_config = LocalAgentConfig(
- system_instructions="You are a helpful agent. Use the get_weather tool to answer weather questions.",
- tools=[get_weather]
-)
-
-# Expose the L2 configuration strategy factory for custom loaders
-strategy_factory = lambda: LocalConnectionStrategy(tool_runner=ToolRunner(tools=[get_weather]))
-
-async def main():
- # 3. Initialize the local connection strategy
- strategy = strategy_factory()
-
- # 4. Create the stateful conversation session
- print("Starting stateful Antigravity conversation (L2 API)...")
- async with Conversation.create(strategy) as conversation:
- prompt = sys.argv[1] if len(sys.argv) > 1 else None
- if not prompt:
- raise ValueError("Please provide a prompt for your agent. Usage: python agent.py <prompt>")
-
- # 5. Send query and receive streaming ChatResponse
- response = await conversation.chat(prompt)
-
- # 6. Stream semantic chunks (Thoughts, Text, and ToolCalls) in real-time
- async for chunk in response.chunks:
- if isinstance(chunk, Text):
- sys.stdout.write(chunk.text)
- sys.stdout.flush()
- elif isinstance(chunk, Thought):
- # Display thought process in comment style
- sys.stdout.write(f"\n[Thinking]: {chunk.text}")
- sys.stdout.flush()
- elif isinstance(chunk, ToolCall):
- sys.stdout.write(f"\n[Tool Call]: {chunk.name} with args {chunk.args}\n")
- sys.stdout.flush()
- print()
-
-if __name__ == "__main__":
- asyncio.run(main())
-
-
diff --git a/examples/antigravity_agent/requirements.txt b/examples/antigravity_agent/requirements.txt
deleted file mode 100644
index 48da6dd..0000000
--- a/examples/antigravity_agent/requirements.txt
+++ /dev/null
@@ -1 +0,0 @@
-google-antigravity
diff --git a/internal/harness/antigravity.go b/internal/harness/antigravity.go
index 7de9ec6..c178183 100644
--- a/internal/harness/antigravity.go
+++ b/internal/harness/antigravity.go
@@ -38,10 +38,10 @@ type AntigravityHarness struct {
}
// NewAntigravityHarness creates a new AntigravityHarness with a configurable address.
-// Address defaults to "localhost:50053" (gRPC TCP connection).
+// Address defaults to "127.0.0.1:50053" (gRPC TCP connection).
func NewAntigravityHarness(address string) *AntigravityHarness {
if address == "" {
- address = "localhost:50053"
+ address = "127.0.0.1:50053"
}
return &AntigravityHarness{
address: address,
diff --git a/manifests/README.md b/manifests/README.md
index 653d2c7..e04fd43 100644
--- a/manifests/README.md
+++ b/manifests/README.md
@@ -101,8 +101,7 @@ kubectl port-forward -n ax rs/ax-server 8494:8494
### 3. Test End-to-End
Run an execution targeting the port-forwarded server. The default `antigravity`
-harness serves the example `examples/antigravity_agent/agent.py`, which exposes
-a `get_weather` tool.
+harness has an embedded weather agent that exposes a `get_weather` tool.
```bash
ax exec --server=localhost:8494 --input="what's the weather in NYC?"
diff --git a/manifests/ax-deployment.yaml b/manifests/ax-deployment.yaml
index 4e58608..d15f4b9 100644
--- a/manifests/ax-deployment.yaml
+++ b/manifests/ax-deployment.yaml
@@ -55,7 +55,6 @@ spec:
# environment are specified here. `ax harness` forks the Antigravity Python
# sidecar, which serves on port 80 because substrate DNATs workerPodIP:80.
command: ["/ax-app/ax", "harness",
- "--antigravity-agent-file", "/ax-app/examples/antigravity_agent/agent.py",
"--host", "0.0.0.0", "--port", "80"]
env:
- name: GEMINI_API_KEY
diff --git a/python/antigravity/harness_server.py b/python/antigravity/harness_server.py
index 257edb7..d592027 100644
--- a/python/antigravity/harness_server.py
+++ b/python/antigravity/harness_server.py
@@ -13,14 +13,12 @@
# limitations under the License.
# NOTE ON ARCHITECTURE:
-# This is a generic, reusable gRPC server that does not define tools or personas.
-# Instead, it dynamically imports any agent configuration file (defaulting to examples/antigravity_agent/agent.py)
-# passed via the --agent_file CLI argument, then hosts it over the AX HarnessService protocol.
+# This gRPC server implements the AX HarnessService protocol. It embeds the
+# Antigravity weather agent logic directly, serving it over production gRPC.
import argparse
import asyncio
-import importlib.util
import logging
import os
import sys
@@ -31,25 +29,34 @@ from google.protobuf.struct_pb2 import Struct
from python.proto import ax_pb2
from python.proto import ax_pb2_grpc
from python.proto import content_pb2
-from google.antigravity import Agent, AgentConfig
+from google.antigravity import Agent, AgentConfig, LocalAgentConfig
from google.antigravity.types import Text, Thought, ToolCall
-# Global placeholder for loaded agent config
-loaded_config: AgentConfig | None = None
+# 1. Define the custom weather tool
+def get_weather(city: str) -> str:
+ """Retrieves the current weather report for a specified city.
-def load_agent_config(agent_file: str) -> AgentConfig:
- print(f"Loading agent config from {agent_file}...")
- spec = importlib.util.spec_from_file_location("agent_module", agent_file)
- if spec is None or spec.loader is None:
- raise FileNotFoundError(f"Could not find or load agent file: {agent_file}")
- agent_module = importlib.util.module_from_spec(spec)
- spec.loader.exec_module(agent_module)
-
- config = getattr(agent_module, "agent_config", None)
- if not config:
- raise ValueError(f"No 'agent_config' found in {agent_file}")
- print("Agent config loaded successfully.")
- return config
+ Args:
+ city (str): The name of the city for which to retrieve the weather report.
+
+ Returns:
+ str: Weather report status and details.
+ """
+ sys.stderr.write(f"\n[PYTHON TOOL get_weather executed for city: {city}]\n")
+ sys.stderr.flush()
+ c = city.lower()
+ if "new york" in c or "nyc" in c:
+ return "The weather in New York is sunny with a temperature of 25 degrees Celsius (77 degrees Fahrenheit)."
+ elif "san francisco" in c or "sf" in c:
+ return "The weather in San Francisco is foggy with a temperature of 16 degrees Celsius (60.8 degrees Fahrenheit)."
+ else:
+ return f"Weather information for '{city}' is not available."
+
+# 2. Define the static agent config
+loaded_config = LocalAgentConfig(
+ system_instructions="You are a helpful agent. Use the get_weather tool to answer weather questions.",
+ tools=[get_weather]
+)
def _has_credentials(config: AgentConfig | None) -> bool:
"""Checks if Gemini credentials are set either in env or config."""
@@ -287,26 +294,6 @@ async def serve(host: str, port: int):
finally:
await servicer.cleanup()
-def resolve_localhost():
- """Ensure `localhost` resolves to 127.0.0.1.
-
- Substrate actors run under gVisor with no runtime-injected /etc/hosts.
- The antigravity SDK dials localharness at ws://localhost:<port>/
- and Python's resolver needs `localhost` in /etc/hosts.
- """
- try:
- try:
- with open("/etc/hosts", "r") as f:
- if "localhost" in f.read():
- return
- except FileNotFoundError:
- pass
- with open("/etc/hosts", "a") as f:
- f.write("127.0.0.1\tlocalhost\n")
- except OSError as e:
- print(f"WARNING: could not ensure localhost in /etc/hosts: {e}", file=sys.stderr)
-
-
def enhance_config_from_env(config) -> None:
skills_dir = os.environ.get("SKILLS_DIR")
if skills_dir and os.path.isdir(skills_dir):
@@ -320,21 +307,12 @@ def enhance_config_from_env(config) -> None:
def main():
parser = argparse.ArgumentParser(description="Antigravity gRPC Harness Server")
- parser.add_argument("--agent_file", default="examples/antigravity_agent/agent.py", help="Path to the agent config file")
parser.add_argument("--port", type=int, default=50053, help="Port to bind the server to")
parser.add_argument("--host", default="localhost", help="Host to bind the server to")
args = parser.parse_args()
-
- resolve_localhost()
-
- # Load the agent config globally
+
global loaded_config
- try:
- loaded_config = load_agent_config(args.agent_file)
- enhance_config_from_env(loaded_config)
- except Exception as e:
- print(f"ERROR: Failed to load agent config: {e}", file=sys.stderr)
- sys.exit(1)
+ enhance_config_from_env(loaded_config)
asyncio.run(serve(args.host, args.port))