pyagy 0.7.1__py3-none-any.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.
- pyagy/__init__.py +8 -0
- pyagy/__main__.py +4 -0
- pyagy/bootstrap.py +232 -0
- pyagy/cli.py +789 -0
- pyagy/context.py +622 -0
- pyagy/gemini_wire.py +683 -0
- pyagy/models.py +246 -0
- pyagy/multi_agents.py +1538 -0
- pyagy/prompts/__init__.py +0 -0
- pyagy/prompts/static_system_prefix.txt +153 -0
- pyagy/prompts/system_prompt.py +458 -0
- pyagy/prompts/tool_declarations.json +558 -0
- pyagy/task_manager.py +851 -0
- pyagy/tools/__init__.py +325 -0
- pyagy/tools/agent_tools.py +192 -0
- pyagy/tools/command_tools.py +148 -0
- pyagy/tools/file_tools.py +243 -0
- pyagy/tools/interaction_tools.py +182 -0
- pyagy/transcript.py +707 -0
- pyagy-0.7.1.dist-info/METADATA +64 -0
- pyagy-0.7.1.dist-info/RECORD +24 -0
- pyagy-0.7.1.dist-info/WHEEL +4 -0
- pyagy-0.7.1.dist-info/entry_points.txt +2 -0
- pyagy-0.7.1.dist-info/licenses/LICENSE +201 -0
pyagy/__init__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"""Antigravity CLI (agy 1.5.14) wire-compatible mode built on pycodex."""
|
|
2
|
+
|
|
3
|
+
from pycodex.utils.compat import importlib_metadata
|
|
4
|
+
|
|
5
|
+
try:
|
|
6
|
+
__version__ = importlib_metadata.version("pyagy")
|
|
7
|
+
except importlib_metadata.PackageNotFoundError: # pragma: no cover - uninstalled checkout
|
|
8
|
+
__version__ = "0.7.1"
|
pyagy/__main__.py
ADDED
pyagy/bootstrap.py
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"""Bootstrap AGY CLI sessions from ~/.codex/config.toml."""
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, replace
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
import os
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
import typing
|
|
8
|
+
import uuid
|
|
9
|
+
|
|
10
|
+
from pycodex.bootstrap import LOCAL_RESPONSES_SERVER_API_KEY_ENV, configure_loguru
|
|
11
|
+
from pycodex.config import CodexConfig
|
|
12
|
+
from pycodex.context import ContextConfig
|
|
13
|
+
from pycodex.tools.base_tool import BaseTool
|
|
14
|
+
from pycodex.utils.codex_config import DEFAULT_CODEX_CONFIG_PATH
|
|
15
|
+
from pycodex.utils.http_headers import build_http_headers
|
|
16
|
+
from responses_server.config import CompatServerConfig
|
|
17
|
+
|
|
18
|
+
from .gemini_wire import AgyManagedResponseServer, AgyResponsesModelClient
|
|
19
|
+
from .models import normalize_effort_level
|
|
20
|
+
from .multi_agents import AgyMultiAgentController, AgySessionNode
|
|
21
|
+
from .prompts.system_prompt import default_app_data_dir
|
|
22
|
+
from .tools import SearchHandler
|
|
23
|
+
from .transcript import AgyTranscriptStore, RestoredConversation, find_latest_conversation_id
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class AgyBootstrappedSession:
|
|
28
|
+
root_node: "AgySessionNode"
|
|
29
|
+
controller: "AgyMultiAgentController"
|
|
30
|
+
owned_server: "AgyManagedResponseServer"
|
|
31
|
+
codex_config: "CodexConfig"
|
|
32
|
+
compat_config: "CompatServerConfig"
|
|
33
|
+
|
|
34
|
+
async def close(self) -> "None":
|
|
35
|
+
try:
|
|
36
|
+
await self.controller.close_all()
|
|
37
|
+
finally:
|
|
38
|
+
self.owned_server.stop()
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def build_agy_session(
|
|
42
|
+
config_path: "typing.Union[str, Path]" = DEFAULT_CODEX_CONFIG_PATH,
|
|
43
|
+
profile: "typing.Optional[str]" = None,
|
|
44
|
+
cwd: "typing.Optional[Path]" = None,
|
|
45
|
+
model_override: "typing.Optional[str]" = None,
|
|
46
|
+
explicit_effort: "typing.Optional[str]" = None,
|
|
47
|
+
app_data_dir: "typing.Optional[Path]" = None,
|
|
48
|
+
global_config_dir: "typing.Optional[Path]" = None,
|
|
49
|
+
additional_workspaces: "typing.Sequence[Path]" = (),
|
|
50
|
+
conversation_id: "typing.Optional[str]" = None,
|
|
51
|
+
continue_latest: "bool" = False,
|
|
52
|
+
resume_conversation_id: "typing.Optional[str]" = None,
|
|
53
|
+
timeout_seconds: "float" = 300.0,
|
|
54
|
+
search_handler: "typing.Optional[SearchHandler]" = None,
|
|
55
|
+
clock: "typing.Optional[typing.Callable[[], datetime]]" = None,
|
|
56
|
+
codex_config: "typing.Optional[CodexConfig]" = None,
|
|
57
|
+
context_config: "typing.Optional[ContextConfig]" = None,
|
|
58
|
+
toolset: "typing.Optional[typing.Sequence[str]]" = None,
|
|
59
|
+
extra_tools: "typing.Sequence[BaseTool]" = (),
|
|
60
|
+
enable_rollout_recording: "bool" = False,
|
|
61
|
+
) -> "AgyBootstrappedSession":
|
|
62
|
+
configure_loguru()
|
|
63
|
+
codex_cfg = (
|
|
64
|
+
codex_config
|
|
65
|
+
if codex_config is not None
|
|
66
|
+
else CodexConfig.from_env(config_path=config_path, profile=profile)
|
|
67
|
+
)
|
|
68
|
+
provider_cfg = codex_cfg.provider
|
|
69
|
+
if provider_cfg.compat_api != "gemini":
|
|
70
|
+
raise ValueError(
|
|
71
|
+
f"pyagy requires a provider with compat_api='gemini' in {codex_cfg.path}, "
|
|
72
|
+
f"got compat_api={provider_cfg.compat_api!r}"
|
|
73
|
+
)
|
|
74
|
+
if explicit_effort is not None:
|
|
75
|
+
normalize_effort_level(explicit_effort)
|
|
76
|
+
|
|
77
|
+
resolved_cwd = (cwd if cwd is not None else Path.cwd()).expanduser().resolve()
|
|
78
|
+
resolved_app_data = (
|
|
79
|
+
app_data_dir.expanduser() if app_data_dir is not None else default_app_data_dir()
|
|
80
|
+
)
|
|
81
|
+
config_effort = provider_cfg.reasoning_effort
|
|
82
|
+
effective_context_config = (
|
|
83
|
+
context_config
|
|
84
|
+
if context_config is not None
|
|
85
|
+
else replace(
|
|
86
|
+
codex_cfg.context,
|
|
87
|
+
cwd=resolved_cwd,
|
|
88
|
+
model_auto_compact_token_limit=None,
|
|
89
|
+
include_permissions_instructions=False,
|
|
90
|
+
include_skills_instructions=False,
|
|
91
|
+
include_environment_context=False,
|
|
92
|
+
code_mode_only=False,
|
|
93
|
+
)
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
restored: "typing.Optional[RestoredConversation]" = None
|
|
97
|
+
if continue_latest and resume_conversation_id is not None:
|
|
98
|
+
raise ValueError("cannot specify both --continue and --conversation")
|
|
99
|
+
if continue_latest:
|
|
100
|
+
target_conv_id = find_latest_conversation_id(resolved_app_data, cwd=resolved_cwd)
|
|
101
|
+
restored = AgyTranscriptStore.load_conversation(
|
|
102
|
+
resolved_app_data, target_conv_id, clock=clock
|
|
103
|
+
)
|
|
104
|
+
elif resume_conversation_id is not None:
|
|
105
|
+
restored = AgyTranscriptStore.load_conversation(
|
|
106
|
+
resolved_app_data, resume_conversation_id, clock=clock
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
effective_conv_id = (
|
|
110
|
+
restored.conversation_id
|
|
111
|
+
if restored is not None
|
|
112
|
+
else (conversation_id or str(uuid.uuid4()))
|
|
113
|
+
)
|
|
114
|
+
effective_model = (
|
|
115
|
+
model_override
|
|
116
|
+
or (restored.model if restored is not None and restored.model else None)
|
|
117
|
+
or provider_cfg.model
|
|
118
|
+
or "gemini-3.1-pro-high"
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
upstream_headers = build_http_headers(
|
|
122
|
+
provider_cfg.http_headers, provider_cfg.env_http_headers
|
|
123
|
+
)
|
|
124
|
+
compat_cfg = replace(
|
|
125
|
+
CompatServerConfig.from_base_url(
|
|
126
|
+
provider_cfg.base_url,
|
|
127
|
+
api_key_env=provider_cfg.api_key_env,
|
|
128
|
+
model_provider=provider_cfg.provider_name,
|
|
129
|
+
outcomming_api="gemini",
|
|
130
|
+
http_headers=upstream_headers,
|
|
131
|
+
),
|
|
132
|
+
timeout_seconds=timeout_seconds,
|
|
133
|
+
)
|
|
134
|
+
owned_server = AgyManagedResponseServer(compat_cfg)
|
|
135
|
+
owned_server.start()
|
|
136
|
+
|
|
137
|
+
try:
|
|
138
|
+
os.environ.setdefault(LOCAL_RESPONSES_SERVER_API_KEY_ENV, "dummy")
|
|
139
|
+
local_provider = replace(
|
|
140
|
+
provider_cfg,
|
|
141
|
+
model=effective_model,
|
|
142
|
+
base_url=owned_server.base_url,
|
|
143
|
+
api_key_env=LOCAL_RESPONSES_SERVER_API_KEY_ENV,
|
|
144
|
+
http_headers={},
|
|
145
|
+
env_http_headers={},
|
|
146
|
+
responses_lite_override=False,
|
|
147
|
+
)
|
|
148
|
+
model_client = AgyResponsesModelClient(
|
|
149
|
+
config=local_provider,
|
|
150
|
+
timeout_seconds=timeout_seconds,
|
|
151
|
+
session_id=effective_conv_id,
|
|
152
|
+
config_effort=config_effort,
|
|
153
|
+
explicit_effort=explicit_effort,
|
|
154
|
+
)
|
|
155
|
+
controller = AgyMultiAgentController(
|
|
156
|
+
app_data_dir=resolved_app_data,
|
|
157
|
+
root_model_client=model_client,
|
|
158
|
+
context_config=effective_context_config,
|
|
159
|
+
compat_config=compat_cfg,
|
|
160
|
+
global_config_dir=global_config_dir,
|
|
161
|
+
config_effort=config_effort,
|
|
162
|
+
explicit_effort=explicit_effort,
|
|
163
|
+
search_handler=search_handler,
|
|
164
|
+
clock=clock,
|
|
165
|
+
)
|
|
166
|
+
root_node = AgySessionNode(
|
|
167
|
+
conversation_id=effective_conv_id,
|
|
168
|
+
cwd=resolved_cwd,
|
|
169
|
+
app_data_dir=resolved_app_data,
|
|
170
|
+
model_client=model_client,
|
|
171
|
+
context_config=effective_context_config,
|
|
172
|
+
controller=controller,
|
|
173
|
+
compat_config=compat_cfg,
|
|
174
|
+
parent_conversation_id=None,
|
|
175
|
+
role="root",
|
|
176
|
+
type_name="root",
|
|
177
|
+
additional_workspaces=additional_workspaces,
|
|
178
|
+
global_config_dir=global_config_dir,
|
|
179
|
+
toolset=toolset,
|
|
180
|
+
config_effort=config_effort,
|
|
181
|
+
explicit_effort=explicit_effort,
|
|
182
|
+
initial_history=restored.history if restored is not None else (),
|
|
183
|
+
last_reported_model_display=(
|
|
184
|
+
restored.last_reported_model_display if restored is not None else None
|
|
185
|
+
),
|
|
186
|
+
anchored_user_messages=(
|
|
187
|
+
restored.anchored_user_messages if restored is not None else None
|
|
188
|
+
),
|
|
189
|
+
pending_post_user_messages=(
|
|
190
|
+
(restored.restart_notice_message,) if restored is not None else ()
|
|
191
|
+
),
|
|
192
|
+
initial_step_counter=(
|
|
193
|
+
restored.step_counter if restored is not None else None
|
|
194
|
+
),
|
|
195
|
+
initial_user_requests=(
|
|
196
|
+
restored.user_requests if restored is not None else ()
|
|
197
|
+
),
|
|
198
|
+
initial_parent_messages=(
|
|
199
|
+
restored.parent_messages if restored is not None else ()
|
|
200
|
+
),
|
|
201
|
+
initial_spawned_subagents=(
|
|
202
|
+
restored.spawned_subagents if restored is not None else ()
|
|
203
|
+
),
|
|
204
|
+
initial_anchor_tokens=(
|
|
205
|
+
restored.anchor_tokens if restored is not None else 0
|
|
206
|
+
),
|
|
207
|
+
initial_anchor_history_len=(
|
|
208
|
+
restored.anchor_history_len if restored is not None else None
|
|
209
|
+
),
|
|
210
|
+
search_handler=search_handler,
|
|
211
|
+
clock=clock,
|
|
212
|
+
extra_tools=extra_tools,
|
|
213
|
+
enable_rollout_recording=enable_rollout_recording,
|
|
214
|
+
)
|
|
215
|
+
controller.register_node(root_node)
|
|
216
|
+
if restored is not None:
|
|
217
|
+
root_node.transcript_store.record_system_message_file(
|
|
218
|
+
content=restored.restart_notice_message.text,
|
|
219
|
+
sender="system",
|
|
220
|
+
priority="MESSAGE_PRIORITY_LOW",
|
|
221
|
+
)
|
|
222
|
+
except BaseException:
|
|
223
|
+
owned_server.stop()
|
|
224
|
+
raise
|
|
225
|
+
|
|
226
|
+
return AgyBootstrappedSession(
|
|
227
|
+
root_node=root_node,
|
|
228
|
+
controller=controller,
|
|
229
|
+
owned_server=owned_server,
|
|
230
|
+
codex_config=codex_cfg,
|
|
231
|
+
compat_config=compat_cfg,
|
|
232
|
+
)
|