google-antigravity 0.1.2__py3-none-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. google/antigravity/__init__.py +41 -0
  2. google/antigravity/agent.py +244 -0
  3. google/antigravity/agent_test.py +1003 -0
  4. google/antigravity/bin/__init__.py +0 -0
  5. google/antigravity/bin/localharness.exe +0 -0
  6. google/antigravity/connections/__init__.py +15 -0
  7. google/antigravity/connections/connection.py +237 -0
  8. google/antigravity/connections/connection_test.py +103 -0
  9. google/antigravity/connections/local/__init__.py +35 -0
  10. google/antigravity/connections/local/local_connection.py +1728 -0
  11. google/antigravity/connections/local/local_connection_config.py +192 -0
  12. google/antigravity/connections/local/local_connection_test.py +4408 -0
  13. google/antigravity/connections/local/localharness_pb2.py +391 -0
  14. google/antigravity/connections/local/test_utils.py +131 -0
  15. google/antigravity/connections/local/test_utils_test.py +153 -0
  16. google/antigravity/connections/local/types.py +107 -0
  17. google/antigravity/conversation/conversation.py +382 -0
  18. google/antigravity/conversation/conversation_test.py +1065 -0
  19. google/antigravity/hooks/__init__.py +60 -0
  20. google/antigravity/hooks/hook_runner.py +283 -0
  21. google/antigravity/hooks/hook_runner_test.py +531 -0
  22. google/antigravity/hooks/hooks.py +288 -0
  23. google/antigravity/hooks/hooks_test.py +107 -0
  24. google/antigravity/hooks/policy.py +904 -0
  25. google/antigravity/hooks/policy_test.py +1056 -0
  26. google/antigravity/mcp/__init__.py +15 -0
  27. google/antigravity/mcp/bridge.py +279 -0
  28. google/antigravity/mcp/bridge_test.py +556 -0
  29. google/antigravity/tools/tool_context.py +105 -0
  30. google/antigravity/tools/tool_context_test.py +183 -0
  31. google/antigravity/tools/tool_runner.py +315 -0
  32. google/antigravity/tools/tool_runner_test.py +687 -0
  33. google/antigravity/triggers/__init__.py +29 -0
  34. google/antigravity/triggers/helpers.py +123 -0
  35. google/antigravity/triggers/helpers_test.py +132 -0
  36. google/antigravity/triggers/trigger_runner.py +139 -0
  37. google/antigravity/triggers/trigger_runner_test.py +197 -0
  38. google/antigravity/triggers/triggers.py +78 -0
  39. google/antigravity/triggers/triggers_test.py +93 -0
  40. google/antigravity/types.py +1209 -0
  41. google/antigravity/types_test.py +1503 -0
  42. google/antigravity/utils/__init__.py +15 -0
  43. google/antigravity/utils/interactive.py +353 -0
  44. google/antigravity/utils/interactive_test.py +408 -0
  45. google_antigravity-0.1.2.dist-info/METADATA +316 -0
  46. google_antigravity-0.1.2.dist-info/RECORD +49 -0
  47. google_antigravity-0.1.2.dist-info/WHEEL +5 -0
  48. google_antigravity-0.1.2.dist-info/licenses/LICENSE +202 -0
  49. google_antigravity-0.1.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,41 @@
1
+ # Copyright 2026 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Google Antigravity SDK for building AI agents."""
16
+
17
+ from google.antigravity.agent import Agent
18
+ from google.antigravity.connections.connection import AgentConfig
19
+ from google.antigravity.connections.local.local_connection_config import LocalAgentConfig
20
+ from google.antigravity.tools.tool_context import ToolContext
21
+ from google.antigravity.types import CapabilitiesConfig
22
+ from google.antigravity.types import GeminiConfig
23
+ from google.antigravity.types import GenerationConfig
24
+ from google.antigravity.types import ModelConfig
25
+ from google.antigravity.types import ModelEntry
26
+ from google.antigravity.types import ThinkingLevel
27
+ from google.antigravity.types import UsageMetadata
28
+
29
+ __all__ = [
30
+ "Agent",
31
+ "AgentConfig",
32
+ "LocalAgentConfig",
33
+ "ToolContext",
34
+ "CapabilitiesConfig",
35
+ "GeminiConfig",
36
+ "GenerationConfig",
37
+ "ModelConfig",
38
+ "ModelEntry",
39
+ "ThinkingLevel",
40
+ "UsageMetadata",
41
+ ]
@@ -0,0 +1,244 @@
1
+ # Copyright 2026 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Layer 1 API for Antigravity SDK."""
16
+
17
+ import contextlib
18
+ import logging
19
+ from typing import cast
20
+
21
+ from google.antigravity import types
22
+ from google.antigravity.connections import connection as connection_module
23
+ from google.antigravity.conversation import conversation
24
+ from google.antigravity.hooks import hook_runner
25
+ from google.antigravity.hooks import hooks
26
+ from google.antigravity.hooks import policy
27
+ from google.antigravity.mcp import bridge
28
+ from google.antigravity.tools import tool_context
29
+ from google.antigravity.tools import tool_runner
30
+ from google.antigravity.triggers import trigger_runner
31
+ from google.antigravity.triggers import triggers as triggers_lib
32
+
33
+
34
+ __all__ = ["Agent"]
35
+
36
+
37
+ class Agent:
38
+ """High-level Agent API for simplified interaction."""
39
+
40
+ def __init__(self, config: connection_module.AgentConfig):
41
+ """Initializes the Agent.
42
+
43
+ Args:
44
+ config: Declarative agent configuration.
45
+ """
46
+ self._config = config.model_copy(deep=True)
47
+ if self._config.response_schema:
48
+ # The response_schema is validated/stringified in AgentConfig.
49
+ self._config.capabilities.finish_tool_schema_json = cast(
50
+ str, self._config.response_schema
51
+ )
52
+ self._strategy = None
53
+ self._conversation = None
54
+ self._tool_runner = None
55
+ self._hook_runner = None
56
+ self._trigger_runner = None
57
+ self._mcp_bridge = None
58
+ # Use the original config (not self._config) for hooks and triggers:
59
+ # model_copy(deep=True) creates new objects, breaking reference equality
60
+ # for user-provided hooks/triggers. The list() snapshot prevents the
61
+ # caller from mutating our copy, while preserving object identity.
62
+ self._pending_hooks = list(config.hooks)
63
+ self._pending_triggers = list(config.triggers)
64
+ self._exit_stack = contextlib.AsyncExitStack()
65
+
66
+ def register_hook(self, hook: hooks.Hook):
67
+ """Registers a hook by inferring its type.
68
+
69
+ Args:
70
+ hook: The hook to register.
71
+ """
72
+ if not self._hook_runner:
73
+ self._pending_hooks.append(hook)
74
+ return
75
+ self._hook_runner.register_hook(hook)
76
+
77
+ def register_trigger(self, trigger: triggers_lib.Trigger):
78
+ """Registers a trigger.
79
+
80
+ Cannot be called after the agent has started.
81
+
82
+ Args:
83
+ trigger: The trigger function to register.
84
+
85
+ Raises:
86
+ RuntimeError: If the agent has already started.
87
+ """
88
+ if self._trigger_runner:
89
+ raise RuntimeError(
90
+ "Cannot register triggers after the agent has started."
91
+ )
92
+ self._pending_triggers.append(trigger)
93
+
94
+ async def __aenter__(self) -> "Agent":
95
+ """Starts the agent session.
96
+
97
+ Returns:
98
+ The started Agent instance.
99
+ """
100
+ logging.info("Starting Agent session")
101
+ try:
102
+ self._hook_runner = hook_runner.HookRunner()
103
+
104
+ # Register pending hooks
105
+ for hook in self._pending_hooks:
106
+ self._hook_runner.register_hook(hook)
107
+ self._pending_hooks.clear()
108
+
109
+ # Apply policies
110
+ active_policies = list(self._config.policies)
111
+ cfg = self._config.capabilities
112
+ read_only_tools = set(types.BuiltinTools.read_only())
113
+ # enabled_tools and disabled_tools are mutually exclusive
114
+ # (enforced by CapabilitiesConfig validation).
115
+ if cfg.enabled_tools is not None:
116
+ active_tools = set(cfg.enabled_tools)
117
+ elif cfg.disabled_tools is not None:
118
+ active_tools = set(types.BuiltinTools) - set(cfg.disabled_tools)
119
+ else:
120
+ active_tools = set(types.BuiltinTools)
121
+ has_write_tools = bool(active_tools - read_only_tools)
122
+ has_mcp_servers = bool(self._config.mcp_servers)
123
+ has_tool_decide_hook = bool(self._hook_runner.pre_tool_call_decide_hooks)
124
+
125
+ if (
126
+ (has_write_tools or has_mcp_servers)
127
+ and not active_policies
128
+ and not has_tool_decide_hook
129
+ ):
130
+ raise ValueError(
131
+ "Write tools or MCP servers are enabled without a safety policy. "
132
+ "Add policies=[policy.allow_all()] to approve all tool calls, "
133
+ "or policies=[policy.deny_all(), policy.allow('tool_name')] "
134
+ "to selectively allow specific tools."
135
+ )
136
+
137
+ if active_policies:
138
+ self._hook_runner.register_hook(
139
+ policy.enforce(
140
+ active_policies, mcp_servers=self._config.mcp_servers
141
+ )
142
+ )
143
+
144
+ all_tools = list(self._config.tools)
145
+ # Connect MCP servers
146
+ if self._config.mcp_servers:
147
+ logging.info("Connecting to MCP servers...")
148
+ self._mcp_bridge = bridge.McpBridge()
149
+ self._exit_stack.push_async_callback(self._mcp_bridge.stop)
150
+
151
+ for server_cfg in self._config.mcp_servers:
152
+ await self._mcp_bridge.connect(server_cfg)
153
+ all_tools.extend(self._mcp_bridge.tools)
154
+
155
+ self._tool_runner = tool_runner.ToolRunner(tools=all_tools)
156
+
157
+ self._strategy = self._config.create_strategy(
158
+ tool_runner=self._tool_runner,
159
+ hook_runner=self._hook_runner,
160
+ )
161
+
162
+ logging.info("Starting connection and creating conversation...")
163
+ self._conversation = await self._exit_stack.enter_async_context(
164
+ conversation.Conversation.create(self._strategy)
165
+ )
166
+
167
+ # Start triggers via TriggerRunner.
168
+ if self._pending_triggers:
169
+ logging.info("Starting triggers...")
170
+ self._trigger_runner = await self._exit_stack.enter_async_context(
171
+ trigger_runner.TriggerRunner(
172
+ triggers=list(self._pending_triggers),
173
+ connection=self.conversation.connection,
174
+ )
175
+ )
176
+ self._pending_triggers.clear()
177
+
178
+ # Wire ToolContext into ToolRunner so tools can access
179
+ # conversation capabilities (same pattern as TriggerRunner).
180
+ if self._tool_runner:
181
+ ctx = tool_context.ToolContext(self.conversation.connection)
182
+ self._tool_runner.set_context(ctx)
183
+
184
+ return self
185
+ except Exception:
186
+ logging.exception("Failed to start Agent session, cleaning up...")
187
+ await self._exit_stack.aclose()
188
+ raise
189
+
190
+ async def __aexit__(self, exc_type, exc_val, exc_tb):
191
+ """Stops the agent session.
192
+
193
+ Args:
194
+ exc_type: The exception type, if any.
195
+ exc_val: The exception value, if any.
196
+ exc_tb: The traceback, if any.
197
+ """
198
+ logging.info("Stopping Agent session")
199
+ return await self._exit_stack.__aexit__(exc_type, exc_val, exc_tb)
200
+
201
+ async def chat(self, prompt: types.Content) -> types.ChatResponse:
202
+ """Sends a prompt and returns the final response.
203
+
204
+ Args:
205
+ prompt: The user prompt or content to send.
206
+
207
+ Returns:
208
+ The final response from the agent.
209
+ """
210
+ return await self.conversation.chat(prompt)
211
+
212
+ @property
213
+ def is_started(self) -> bool:
214
+ """Whether the agent session has been started."""
215
+ return self._conversation is not None
216
+
217
+ @property
218
+ def conversation(self) -> conversation.Conversation:
219
+ """Returns the active Conversation session.
220
+
221
+ Use this for advanced session introspection: history, turn count,
222
+ compaction indices, usage, or direct send/receive_steps control.
223
+ For most use cases, prefer chat() instead.
224
+
225
+ Raises:
226
+ RuntimeError: If the agent session has not been started.
227
+ """
228
+ if not self._conversation:
229
+ raise RuntimeError(
230
+ "Agent session not started. Use 'async with Agent(...)'."
231
+ )
232
+ return self._conversation
233
+
234
+ @property
235
+ def conversation_id(self) -> str | None:
236
+ """Returns the conversation identifier assigned by the runtime.
237
+
238
+ Available after the session has started and at least one message has
239
+ been exchanged. Pass this value back via SessionConfig.conversation_id
240
+ to resume from a saved session. Returns None before the session starts.
241
+ """
242
+ if not self._conversation:
243
+ return None
244
+ return self._conversation.conversation_id or None