python-codex 0.6.0__py3-none-any.whl → 0.6.2__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.
- pycodex/__init__.py +4 -4
- pycodex/agent.py +28 -9
- pycodex/bootstrap.py +10 -12
- pycodex/cli.py +0 -14
- pycodex/context.py +43 -32
- pycodex/events.py +20 -11
- pycodex/model.py +16 -7
- pycodex/prompts/models.json +14 -0
- pycodex/protocol.py +18 -0
- pycodex/runtime.py +49 -54
- pycodex/tools/__init__.py +9 -10
- pycodex/tools/clock_tool.py +57 -7
- pycodex/tools/exec_runtime.py +29 -78
- pycodex/tools/exec_tool.py +2 -6
- pycodex/utils/compat.py +41 -0
- pycodex/utils/dotenv.py +0 -7
- pycodex/utils/event_helpers.py +5 -9
- pycodex/utils/history.py +79 -20
- pycodex/utils/session_persist.py +133 -36
- pycodex/utils/skill_catalog.py +18 -0
- python_codex-0.6.2.dist-info/METADATA +216 -0
- {python_codex-0.6.0.dist-info → python_codex-0.6.2.dist-info}/RECORD +33 -32
- responses_server/app.py +3 -1
- responses_server/config.py +6 -1
- responses_server/gemini_api.py +336 -0
- responses_server/messages_api.py +9 -1
- responses_server/request_translation.py +6 -0
- responses_server/stream_router.py +15 -0
- responses_server/tools/web_search.py +3 -0
- responses_server/transport.py +75 -19
- pycodex/tools/request_user_input_tool.py +0 -82
- python_codex-0.6.0.dist-info/METADATA +0 -352
- {python_codex-0.6.0.dist-info → python_codex-0.6.2.dist-info}/WHEEL +0 -0
- {python_codex-0.6.0.dist-info → python_codex-0.6.2.dist-info}/entry_points.txt +0 -0
- {python_codex-0.6.0.dist-info → python_codex-0.6.2.dist-info}/licenses/LICENSE +0 -0
pycodex/__init__.py
CHANGED
|
@@ -42,7 +42,6 @@ from .tools import (
|
|
|
42
42
|
ApplyPatchTool,
|
|
43
43
|
BaseTool,
|
|
44
44
|
ClockManager,
|
|
45
|
-
ClockTool,
|
|
46
45
|
CodeModeManager,
|
|
47
46
|
ExecCommandTool,
|
|
48
47
|
ExecTool,
|
|
@@ -54,10 +53,11 @@ from .tools import (
|
|
|
54
53
|
ReadFileTool,
|
|
55
54
|
Registry,
|
|
56
55
|
RequestPermissionsTool,
|
|
57
|
-
RequestUserInputTool,
|
|
58
56
|
SendMessageTool,
|
|
57
|
+
SetPeriodTool,
|
|
59
58
|
ShellCommandTool,
|
|
60
59
|
ShellTool,
|
|
60
|
+
SleepTool,
|
|
61
61
|
SpawnAgentTool,
|
|
62
62
|
ToolContext,
|
|
63
63
|
ToolRegistry,
|
|
@@ -84,7 +84,6 @@ __all__ = [
|
|
|
84
84
|
"AssistantMessage",
|
|
85
85
|
"BaseTool",
|
|
86
86
|
"ClockManager",
|
|
87
|
-
"ClockTool",
|
|
88
87
|
"create_agent_runtime_environment",
|
|
89
88
|
"CodeModeManager",
|
|
90
89
|
"CodexConfig",
|
|
@@ -105,7 +104,6 @@ __all__ = [
|
|
|
105
104
|
"Registry",
|
|
106
105
|
"ReadFileTool",
|
|
107
106
|
"RequestPermissionsTool",
|
|
108
|
-
"RequestUserInputTool",
|
|
109
107
|
"ModelResponse",
|
|
110
108
|
"ModelEvent",
|
|
111
109
|
"PlanStore",
|
|
@@ -118,8 +116,10 @@ __all__ = [
|
|
|
118
116
|
"ResponsesModelClient",
|
|
119
117
|
"ResponsesProviderConfig",
|
|
120
118
|
"SendMessageTool",
|
|
119
|
+
"SetPeriodTool",
|
|
121
120
|
"ShellCommandTool",
|
|
122
121
|
"ShellTool",
|
|
122
|
+
"SleepTool",
|
|
123
123
|
"SpawnAgentTool",
|
|
124
124
|
"ToolCall",
|
|
125
125
|
"ToolContext",
|
pycodex/agent.py
CHANGED
|
@@ -13,6 +13,7 @@ from .events import (
|
|
|
13
13
|
CompactFailedEvent,
|
|
14
14
|
CompactStartedEvent,
|
|
15
15
|
Event,
|
|
16
|
+
MessagesAddedEvent,
|
|
16
17
|
ModelCalledEvent,
|
|
17
18
|
ModelCompletedEvent,
|
|
18
19
|
ModelEvent,
|
|
@@ -118,6 +119,7 @@ class Agent:
|
|
|
118
119
|
self._configure_recording(session_id, session_file_path)
|
|
119
120
|
self._last_total_usage_tokens: "typing.Union[int, None]" = None
|
|
120
121
|
self._idle: "typing.Union[asyncio.Event, None]" = None
|
|
122
|
+
self._active_turn_id: "typing.Union[str, None]" = None
|
|
121
123
|
self.is_shutdown = False
|
|
122
124
|
self.accepts_input = True
|
|
123
125
|
self._stop_requested = False
|
|
@@ -209,7 +211,7 @@ class Agent:
|
|
|
209
211
|
def ask(self, text: "str") -> "TurnResult":
|
|
210
212
|
from .utils.async_bridge import run_async
|
|
211
213
|
|
|
212
|
-
return run_async(self.run_turn([text]))
|
|
214
|
+
return run_async(self.run_turn([UserMessage(text)]))
|
|
213
215
|
|
|
214
216
|
def _configure_recording(
|
|
215
217
|
self,
|
|
@@ -260,8 +262,8 @@ class Agent:
|
|
|
260
262
|
self._idle = None
|
|
261
263
|
|
|
262
264
|
async def run_turn(
|
|
263
|
-
self,
|
|
264
|
-
|
|
265
|
+
self, messages: "typing.Iterable[typing.Union[UserMessage, AgentMessage, ToolResult]]",
|
|
266
|
+
turn_id: "typing.Union[str, None]" = None,
|
|
265
267
|
) -> "TurnResult":
|
|
266
268
|
if self.is_shutdown:
|
|
267
269
|
raise RuntimeError("agent is shutdown")
|
|
@@ -271,18 +273,18 @@ class Agent:
|
|
|
271
273
|
self._follow_up_requested = False
|
|
272
274
|
self._idle = asyncio.Event()
|
|
273
275
|
turn = _TurnState(turn_id or uuid7_string())
|
|
276
|
+
self._active_turn_id = turn.turn_id
|
|
274
277
|
try:
|
|
275
|
-
self.
|
|
278
|
+
messages = self._bind_turn(messages)
|
|
279
|
+
self._emit(TurnStartedEvent(turn.turn_id, messages))
|
|
276
280
|
while True:
|
|
277
281
|
phase = "pre_turn" if turn.iteration == 0 else "mid_turn"
|
|
278
282
|
await self._maybe_auto_compact(turn.turn_id, phase)
|
|
283
|
+
if turn.iteration == 0:
|
|
284
|
+
self._append_history(messages)
|
|
279
285
|
self._follow_up_requested = False
|
|
280
286
|
# Input delivery commits history; its failures must fail the turn.
|
|
281
287
|
self.event_handler(TurnInputReadyEvent(turn.turn_id))
|
|
282
|
-
if turn.iteration == 0:
|
|
283
|
-
self.receive_messages(
|
|
284
|
-
tuple(UserMessage(text=text, name=name) for text in texts)
|
|
285
|
-
)
|
|
286
288
|
response = await self._sample(turn)
|
|
287
289
|
self._emit(
|
|
288
290
|
ModelCompletedEvent(
|
|
@@ -347,6 +349,7 @@ class Agent:
|
|
|
347
349
|
finally:
|
|
348
350
|
self._stop_requested = False
|
|
349
351
|
self._follow_up_requested = False
|
|
352
|
+
self._active_turn_id = None
|
|
350
353
|
self._idle.set()
|
|
351
354
|
self._idle = None
|
|
352
355
|
|
|
@@ -479,14 +482,30 @@ class Agent:
|
|
|
479
482
|
)
|
|
480
483
|
return None
|
|
481
484
|
|
|
485
|
+
def _bind_turn(
|
|
486
|
+
self, items: "typing.Iterable[ConversationItem]"
|
|
487
|
+
) -> "typing.Tuple[ConversationItem, ...]":
|
|
488
|
+
turn_id = self._active_turn_id
|
|
489
|
+
return tuple(
|
|
490
|
+
item if isinstance(item, (ToolCall, ToolResult, ReasoningItem))
|
|
491
|
+
else replace(item, turn_id=turn_id) if turn_id is not None
|
|
492
|
+
else item
|
|
493
|
+
for item in items
|
|
494
|
+
)
|
|
495
|
+
|
|
482
496
|
def _append_history(
|
|
483
497
|
self,
|
|
484
498
|
items: "typing.Iterable[ConversationItem]",
|
|
485
499
|
) -> "None":
|
|
486
|
-
items =
|
|
500
|
+
items = self._bind_turn(items)
|
|
487
501
|
if self._rollout_recorder is not None:
|
|
488
502
|
self._rollout_recorder.append_history_items(items, self._history)
|
|
489
503
|
self._history.extend(items)
|
|
504
|
+
messages = tuple(
|
|
505
|
+
item for item in items if isinstance(item, (UserMessage, AgentMessage, AssistantMessage))
|
|
506
|
+
)
|
|
507
|
+
if messages:
|
|
508
|
+
self._emit(MessagesAddedEvent(messages[0].turn_id or "", messages))
|
|
490
509
|
|
|
491
510
|
def _handle_model_stream_event(self, turn_id: "str", event: "ModelEvent") -> "None":
|
|
492
511
|
if isinstance(event, TokenCountEvent):
|
pycodex/bootstrap.py
CHANGED
|
@@ -90,20 +90,18 @@ def build_model(
|
|
|
90
90
|
timeout_seconds: "float" = 120.0,
|
|
91
91
|
managed_responses_base_url: "typing.Union[str, None]" = None,
|
|
92
92
|
vllm_endpoint: "typing.Union[str, None]" = None,
|
|
93
|
-
use_chat_completion: "typing.Union[bool, None]" = None,
|
|
94
|
-
use_messages: "bool" = False,
|
|
95
93
|
) -> "ModelBootstrapResult":
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
compat_api = provider_config.compat_api
|
|
95
|
+
if vllm_endpoint is not None and compat_api not in ("none", "chat_completions"):
|
|
96
|
+
raise ValueError("--vllm-endpoint cannot be combined with compat_api=" + compat_api)
|
|
97
|
+
if managed_responses_base_url is not None and (
|
|
98
|
+
vllm_endpoint is not None or compat_api != "none"
|
|
99
|
+
):
|
|
100
|
+
raise ValueError("a managed Responses endpoint cannot be combined with compat_api or --vllm-endpoint")
|
|
102
101
|
uses_local_responses_compat = (
|
|
103
102
|
managed_responses_base_url is not None
|
|
104
103
|
or vllm_endpoint is not None
|
|
105
|
-
or
|
|
106
|
-
or use_messages
|
|
104
|
+
or compat_api != "none"
|
|
107
105
|
)
|
|
108
106
|
if vllm_endpoint is not None:
|
|
109
107
|
provider_config = replace(
|
|
@@ -122,7 +120,7 @@ def build_model(
|
|
|
122
120
|
LOCAL_RESPONSES_SERVER_API_KEY_ENV,
|
|
123
121
|
)
|
|
124
122
|
os.environ.setdefault(LOCAL_RESPONSES_SERVER_API_KEY_ENV, "dummy")
|
|
125
|
-
elif vllm_endpoint
|
|
123
|
+
elif vllm_endpoint is not None or compat_api != "none":
|
|
126
124
|
if vllm_endpoint:
|
|
127
125
|
managed_server = launch_chat_completion_compat_server(
|
|
128
126
|
vllm_endpoint,
|
|
@@ -133,7 +131,7 @@ def build_model(
|
|
|
133
131
|
provider_config.base_url,
|
|
134
132
|
provider_config.api_key_env,
|
|
135
133
|
model_provider=provider_config.provider_name,
|
|
136
|
-
outcomming_api=
|
|
134
|
+
outcomming_api=compat_api,
|
|
137
135
|
)
|
|
138
136
|
url, key_env = (
|
|
139
137
|
managed_server.base_url,
|
pycodex/cli.py
CHANGED
|
@@ -62,18 +62,6 @@ def build_parser():
|
|
|
62
62
|
default=None,
|
|
63
63
|
help="Start a local responses compat server for a chat-completions-backed vLLM endpoint.",
|
|
64
64
|
)
|
|
65
|
-
parser.add_argument(
|
|
66
|
-
"--use-chat-completion",
|
|
67
|
-
default=False,
|
|
68
|
-
action="store_true",
|
|
69
|
-
help="Start a local responses compat server for this session.",
|
|
70
|
-
)
|
|
71
|
-
parser.add_argument(
|
|
72
|
-
"--use-messages",
|
|
73
|
-
default=False,
|
|
74
|
-
action="store_true",
|
|
75
|
-
help="Route the local responses compat server to a downstream /v1/messages backend.",
|
|
76
|
-
)
|
|
77
65
|
parser.add_argument(
|
|
78
66
|
"--system-prompt",
|
|
79
67
|
default=None,
|
|
@@ -150,8 +138,6 @@ async def run_cli(args):
|
|
|
150
138
|
config.provider,
|
|
151
139
|
timeout_seconds=args.timeout_seconds,
|
|
152
140
|
vllm_endpoint=args.vllm_endpoint,
|
|
153
|
-
use_chat_completion=args.use_chat_completion or None,
|
|
154
|
-
use_messages=args.use_messages,
|
|
155
141
|
)
|
|
156
142
|
if bootstrap.owned_server is not None:
|
|
157
143
|
atexit.register(bootstrap.owned_server.stop)
|
pycodex/context.py
CHANGED
|
@@ -87,6 +87,7 @@ class ContextConfig:
|
|
|
87
87
|
multi_agent_subagent_instructions: "typing.Union[str, None]" = None
|
|
88
88
|
multi_agent_hint: "typing.Union[str, None]" = None
|
|
89
89
|
code_mode_only: "typing.Union[bool, None]" = None
|
|
90
|
+
include_environment_context: "bool" = True
|
|
90
91
|
|
|
91
92
|
def __post_init__(self):
|
|
92
93
|
if self.code_mode_only is not None and not isinstance(self.code_mode_only, bool):
|
|
@@ -228,6 +229,8 @@ class ContextManager:
|
|
|
228
229
|
|
|
229
230
|
def get_turn_metadata(self, turn_id: "str") -> "JSONDict":
|
|
230
231
|
metadata: "JSONDict" = {"turn_id": turn_id}
|
|
232
|
+
if not self.config.include_environment_context:
|
|
233
|
+
return metadata
|
|
231
234
|
if self._workspace_metadata_turn_id is None:
|
|
232
235
|
self._workspace_metadata_turn_id = turn_id
|
|
233
236
|
self._workspace_metadata_cache = get_workspace_turn_metadata(self.cwd)
|
|
@@ -281,8 +284,7 @@ class ContextManager:
|
|
|
281
284
|
input_items.extend(block)
|
|
282
285
|
position = offset
|
|
283
286
|
input_items.extend(history[position:])
|
|
284
|
-
|
|
285
|
-
input_items = _normalize_fork_calls(input_items)
|
|
287
|
+
input_items = _normalize_tool_calls(input_items, self._fork_context is not None)
|
|
286
288
|
base_instructions = self.resolve_base_instructions()
|
|
287
289
|
if capture_context:
|
|
288
290
|
self._last_context = ForkContext(
|
|
@@ -636,44 +638,24 @@ class ContextManager:
|
|
|
636
638
|
return f"{SKILLS_OPEN_TAG}\n{body}\n{SKILLS_CLOSE_TAG}"
|
|
637
639
|
|
|
638
640
|
def _discover_skills(self) -> "typing.List[SkillDescriptor]":
|
|
639
|
-
|
|
640
|
-
if codex_home is None:
|
|
641
|
-
return []
|
|
642
|
-
|
|
643
|
-
user_root = codex_home / "skills"
|
|
644
|
-
system_root = user_root / ".system"
|
|
645
|
-
discovered: "typing.List[SkillDescriptor]" = []
|
|
646
|
-
seen: "typing.Set[Path]" = set()
|
|
647
|
-
|
|
648
|
-
user_paths = _discover_skill_files(user_root, excluded_root=system_root)
|
|
649
|
-
system_paths = _discover_skill_files(system_root)
|
|
650
|
-
|
|
651
|
-
for scope_rank, root, paths in (
|
|
652
|
-
(3, user_root, user_paths),
|
|
653
|
-
(0, system_root, system_paths),
|
|
654
|
-
):
|
|
655
|
-
for path in paths:
|
|
656
|
-
resolved = path.resolve()
|
|
657
|
-
if resolved in seen:
|
|
658
|
-
continue
|
|
659
|
-
seen.add(resolved)
|
|
660
|
-
descriptor = _parse_skill_descriptor(path, scope_rank, root)
|
|
661
|
-
if descriptor is not None:
|
|
662
|
-
discovered.append(descriptor)
|
|
663
|
-
|
|
664
|
-
return discovered
|
|
641
|
+
return discover_skills(self.config.codex_home)
|
|
665
642
|
|
|
666
643
|
def _build_contextual_user_messages(self) -> "typing.List[ContextMessage]":
|
|
667
644
|
sections: "typing.List[str]" = []
|
|
668
645
|
user_instructions = self._merged_user_instructions()
|
|
669
646
|
if user_instructions is not None:
|
|
647
|
+
heading = (
|
|
648
|
+
f"{USER_INSTRUCTIONS_PREFIX}{self.cwd}"
|
|
649
|
+
if self.config.include_environment_context else "# User instructions"
|
|
650
|
+
)
|
|
670
651
|
sections.append(
|
|
671
652
|
(
|
|
672
|
-
f"{
|
|
653
|
+
f"{heading}\n\n"
|
|
673
654
|
f"<INSTRUCTIONS>\n{user_instructions}\n</INSTRUCTIONS>"
|
|
674
655
|
)
|
|
675
656
|
)
|
|
676
|
-
|
|
657
|
+
if self.config.include_environment_context:
|
|
658
|
+
sections.append(self._serialize_environment_context())
|
|
677
659
|
sections.extend(self._extra_contextual_user_messages)
|
|
678
660
|
if not sections:
|
|
679
661
|
return []
|
|
@@ -799,7 +781,7 @@ class ContextManager:
|
|
|
799
781
|
return "\n".join(lines)
|
|
800
782
|
|
|
801
783
|
|
|
802
|
-
def
|
|
784
|
+
def _normalize_tool_calls(items, complete_calls):
|
|
803
785
|
call_ids = {
|
|
804
786
|
(item.tool_type, item.call_id)
|
|
805
787
|
for item in items if isinstance(item, ToolCall)
|
|
@@ -817,7 +799,7 @@ def _normalize_fork_calls(items):
|
|
|
817
799
|
continue
|
|
818
800
|
normalized.append(item)
|
|
819
801
|
if (
|
|
820
|
-
isinstance(item, ToolCall)
|
|
802
|
+
complete_calls and isinstance(item, ToolCall)
|
|
821
803
|
and (item.tool_type, item.call_id) not in result_ids
|
|
822
804
|
):
|
|
823
805
|
prefix = "ctco" if item.tool_type == "custom" else "fco"
|
|
@@ -961,3 +943,32 @@ def build_goal_message(goal, budget_limited=False):
|
|
|
961
943
|
token_budget="none" if budget is None else budget,
|
|
962
944
|
remaining_tokens="unbounded" if budget is None else max(0, budget - goal["tokensUsed"]),
|
|
963
945
|
))
|
|
946
|
+
|
|
947
|
+
|
|
948
|
+
def discover_skills(codex_home):
|
|
949
|
+
"""Discover the same skill descriptors used in model context and input menus."""
|
|
950
|
+
if codex_home is None:
|
|
951
|
+
return []
|
|
952
|
+
|
|
953
|
+
user_root = codex_home / "skills"
|
|
954
|
+
system_root = user_root / ".system"
|
|
955
|
+
discovered: "typing.List[SkillDescriptor]" = []
|
|
956
|
+
seen: "typing.Set[Path]" = set()
|
|
957
|
+
|
|
958
|
+
user_paths = _discover_skill_files(user_root, excluded_root=system_root)
|
|
959
|
+
system_paths = _discover_skill_files(system_root)
|
|
960
|
+
|
|
961
|
+
for scope_rank, root, paths in (
|
|
962
|
+
(3, user_root, user_paths),
|
|
963
|
+
(0, system_root, system_paths),
|
|
964
|
+
):
|
|
965
|
+
for path in paths:
|
|
966
|
+
resolved = path.resolve()
|
|
967
|
+
if resolved in seen:
|
|
968
|
+
continue
|
|
969
|
+
seen.add(resolved)
|
|
970
|
+
descriptor = _parse_skill_descriptor(path, scope_rank, root)
|
|
971
|
+
if descriptor is not None:
|
|
972
|
+
discovered.append(descriptor)
|
|
973
|
+
|
|
974
|
+
return discovered
|
pycodex/events.py
CHANGED
|
@@ -5,7 +5,7 @@ import typing
|
|
|
5
5
|
from dataclasses import dataclass
|
|
6
6
|
from typing import ClassVar
|
|
7
7
|
|
|
8
|
-
from .protocol import JSONDict, ToolCall, ToolResult
|
|
8
|
+
from .protocol import AgentMessage, ConversationItem, JSONDict, ToolCall, ToolResult, UserMessage
|
|
9
9
|
from .utils.event_helpers import (
|
|
10
10
|
colorize_cli_message,
|
|
11
11
|
colorize_tool_message,
|
|
@@ -147,12 +147,15 @@ class TerminalEvent(TurnEvent):
|
|
|
147
147
|
@dataclass(frozen=True)
|
|
148
148
|
class TurnStartedEvent(TurnEvent):
|
|
149
149
|
turn_id: "str"
|
|
150
|
-
|
|
150
|
+
messages: "typing.Tuple[ConversationItem, ...]"
|
|
151
151
|
submission_id: "typing.Union[str, None]" = None
|
|
152
152
|
kind: ClassVar[str] = "turn_started"
|
|
153
153
|
|
|
154
154
|
def visualize(self) -> "str":
|
|
155
|
-
return "\n".join(
|
|
155
|
+
return "\n".join(
|
|
156
|
+
message.text for message in self.messages
|
|
157
|
+
if isinstance(message, (UserMessage, AgentMessage)) and message.visible
|
|
158
|
+
)
|
|
156
159
|
|
|
157
160
|
def render(self, display: "EventDisplay") -> "None":
|
|
158
161
|
display.begin_turn(self)
|
|
@@ -167,6 +170,16 @@ class TurnInputReadyEvent(TurnEvent):
|
|
|
167
170
|
kind: ClassVar[str] = "turn_input_ready"
|
|
168
171
|
|
|
169
172
|
|
|
173
|
+
@dataclass(frozen=True)
|
|
174
|
+
class MessagesAddedEvent(TurnEvent):
|
|
175
|
+
"""Conversation items committed to history, in their original order."""
|
|
176
|
+
|
|
177
|
+
turn_id: "str"
|
|
178
|
+
messages: "typing.Tuple[ConversationItem, ...]"
|
|
179
|
+
submission_id: "typing.Union[str, None]" = None
|
|
180
|
+
kind: ClassVar[str] = "messages_added"
|
|
181
|
+
|
|
182
|
+
|
|
170
183
|
@dataclass(frozen=True)
|
|
171
184
|
class TurnCompletedEvent(TerminalEvent):
|
|
172
185
|
turn_id: "str"
|
|
@@ -564,11 +577,7 @@ class SessionStateEvent(Event):
|
|
|
564
577
|
display.inserted_steer_prompts.clear()
|
|
565
578
|
active = state["active_turn"]
|
|
566
579
|
if active is not None:
|
|
567
|
-
|
|
568
|
-
active["turn_id"],
|
|
569
|
-
tuple(active["user_texts"]),
|
|
570
|
-
active["submission_id"],
|
|
571
|
-
).render(display)
|
|
580
|
+
display.set_status("working")
|
|
572
581
|
display.stream_buffer = active["assistant_text"]
|
|
573
582
|
elif not state["busy"]:
|
|
574
583
|
display.set_idle_status(state["background_work_count"])
|
|
@@ -636,7 +645,7 @@ class CommandFailedEvent(Event):
|
|
|
636
645
|
@dataclass(frozen=True)
|
|
637
646
|
class InputQueuedEvent(Event):
|
|
638
647
|
submission_id: "str"
|
|
639
|
-
|
|
648
|
+
message: "UserMessage"
|
|
640
649
|
queue: "str"
|
|
641
650
|
sender: "str"
|
|
642
651
|
explicit_queue: "bool"
|
|
@@ -644,7 +653,7 @@ class InputQueuedEvent(Event):
|
|
|
644
653
|
kind: ClassVar[str] = "input_queued"
|
|
645
654
|
|
|
646
655
|
def render(self, display: "EventDisplay") -> "None":
|
|
647
|
-
preview = shorten_title(self.
|
|
656
|
+
preview = shorten_title(self.message.text, 72)
|
|
648
657
|
if self.explicit_queue:
|
|
649
658
|
display.queued_steer_prompts.setdefault(self.submission_id, []).append(
|
|
650
659
|
preview
|
|
@@ -698,7 +707,7 @@ class InputRequestedEvent(Event):
|
|
|
698
707
|
question = self.question
|
|
699
708
|
return "\n".join(
|
|
700
709
|
[
|
|
701
|
-
"[
|
|
710
|
+
"[input] waiting for user response",
|
|
702
711
|
"[{0}] {1}".format(question["header"], question["question"]),
|
|
703
712
|
]
|
|
704
713
|
+ [
|
pycodex/model.py
CHANGED
|
@@ -98,7 +98,6 @@ class ResponsesProviderConfig:
|
|
|
98
98
|
provider_name: "str"
|
|
99
99
|
base_url: "str"
|
|
100
100
|
api_key_env: "typing.Union[str, None]"
|
|
101
|
-
use_chat_completion: "bool" = False
|
|
102
101
|
wire_api: "str" = "responses"
|
|
103
102
|
query_params: "typing.Dict[str, str]" = field(default_factory=dict)
|
|
104
103
|
reasoning_effort: "typing.Union[str, None]" = None
|
|
@@ -113,8 +112,11 @@ class ResponsesProviderConfig:
|
|
|
113
112
|
fallback_models: "typing.Tuple[str, ...]" = ()
|
|
114
113
|
fallback_cooldown_seconds: "int" = 900
|
|
115
114
|
stream_first_data_timeout_ms: "typing.Union[int, None]" = None
|
|
115
|
+
compat_api: "str" = "none"
|
|
116
116
|
|
|
117
117
|
def __post_init__(self):
|
|
118
|
+
if self.compat_api not in ("none", "chat_completions", "messages", "gemini"):
|
|
119
|
+
raise ValueError("compat_api must be none, chat_completions, messages or gemini")
|
|
118
120
|
cooldown = self.fallback_cooldown_seconds
|
|
119
121
|
if isinstance(cooldown, bool) or not isinstance(cooldown, int) or cooldown < 0:
|
|
120
122
|
raise ValueError("fallback_cooldown_seconds must be a non-negative integer")
|
|
@@ -164,11 +166,18 @@ class ResponsesProviderConfig:
|
|
|
164
166
|
beta_features: "typing.List[str]" = []
|
|
165
167
|
if isinstance(features, dict) and features.get("guardian_approval") is True:
|
|
166
168
|
beta_features.append("guardian_approval")
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
for key in ("use_messages", "use_gemini"):
|
|
170
|
+
if key in selected or key in provider:
|
|
171
|
+
raise ValueError(f"{key} has been removed; use compat_api instead")
|
|
172
|
+
compat_api = "none"
|
|
173
|
+
for source in (selected, provider):
|
|
174
|
+
if "compat_api" in source:
|
|
175
|
+
compat_api = source["compat_api"]
|
|
176
|
+
break
|
|
177
|
+
use_chat_completion = _optional_bool(source.get("use_chat_completion"))
|
|
178
|
+
if use_chat_completion is not None:
|
|
179
|
+
compat_api = "chat_completions" if use_chat_completion else "none"
|
|
180
|
+
break
|
|
172
181
|
fallback_models = provider.get("fallback_models", [])
|
|
173
182
|
if not isinstance(fallback_models, list) or any(
|
|
174
183
|
not isinstance(model, str) or not model or any(c.isspace() for c in model)
|
|
@@ -180,7 +189,7 @@ class ResponsesProviderConfig:
|
|
|
180
189
|
provider_name=provider_name,
|
|
181
190
|
base_url=provider["base_url"],
|
|
182
191
|
api_key_env=api_key_env,
|
|
183
|
-
|
|
192
|
+
compat_api=compat_api,
|
|
184
193
|
wire_api=wire_api,
|
|
185
194
|
query_params=query_params,
|
|
186
195
|
reasoning_effort=selected.get("model_reasoning_effort"),
|
pycodex/prompts/models.json
CHANGED
|
@@ -1814,6 +1814,20 @@
|
|
|
1814
1814
|
"personality_pragmatic": "# Personality\n\nYou are a deeply pragmatic, effective software engineer. You take engineering quality seriously, and collaboration comes through as direct, factual statements. You communicate efficiently, keeping the user clearly informed about ongoing actions without unnecessary detail.\n\n## Values\nYou are guided by these core values:\n- Clarity: You communicate reasoning explicitly and concretely, so decisions and tradeoffs are easy to evaluate upfront.\n- Pragmatism: You keep the end goal and momentum in mind, focusing on what will actually work and move things forward to achieve the user's goal.\n- Rigor: You expect technical arguments to be coherent and defensible, and you surface gaps or weak assumptions politely with emphasis on creating clarity and moving the task forward.\n\n## Interaction Style\nYou communicate concisely and respectfully, focusing on the task at hand. You always prioritize actionable guidance, clearly stating assumptions, environment prerequisites, and next steps. Unless explicitly asked, you avoid excessively verbose explanations about your work.\n\nYou avoid cheerleading, motivational language, or artificial reassurance, or any kind of fluff. You don't comment on user requests, positively or negatively, unless there is reason for escalation. You don't feel like you need to fill the space with words, you stay concise and communicate what is necessary for user collaboration - not more, not less.\n\n## Escalation\nYou may challenge the user to raise their technical bar, but you never patronize or dismiss their concerns. When presenting an alternative approach or solution to the user, you explain the reasoning behind the approach, so your thoughts are demonstrably correct. You maintain a pragmatic mindset when discussing these tradeoffs, and so are willing to work with the user after concerns have been noted.\n"
|
|
1815
1815
|
}
|
|
1816
1816
|
}
|
|
1817
|
+
},
|
|
1818
|
+
{
|
|
1819
|
+
"slug": "gemini-4-argon",
|
|
1820
|
+
"display_name": "Gemini 4 Argon",
|
|
1821
|
+
"description": "Local Gemini 4 Argon prompt adapted from Antigravity CLI 1.4.12.",
|
|
1822
|
+
"visibility": "hide",
|
|
1823
|
+
"model_messages": {
|
|
1824
|
+
"instructions_template": "You are Codex, a coding agent based on Gemini 4 Argon. You and the user share the same workspace and collaborate to achieve the user's goals.\n\n{{ personality }}\n\n# Role and workflow\n\nYou are pair programming with the user to solve their coding task. The task may require creating a new codebase, modifying or debugging an existing codebase, or simply answering a question. Prioritize addressing the user's request.\n\n- Read the relevant code and repository instructions before making changes. Build context from the actual workspace rather than assuming how the project works.\n- When the user asks you to implement or fix something, carry the work through implementation, appropriate verification, and a clear explanation of the result.\n- Follow the current run's autonomy, approval, and collaboration instructions. Work independently within the authorized scope; ask for clarification when missing information prevents progress.\n- Keep changes focused on the task and consistent with the project's existing conventions. Preserve unrelated user changes and existing comments unless the task requires changing them.\n- Run checks appropriate to the change. Report what was verified and any remaining limitations; do not claim success without evidence.\n\n# Tools\n\nUse only tools exposed in the current request, with the exact names and argument schemas in their definitions. Follow each tool's documented execution interface, including whether it is called directly or through exec.\n\nYou support batch function calling. When you need to execute multiple operations that are independent of each other, you SHOULD call multiple tools in parallel in a single turn. This is much more efficient than calling them sequentially.\n\nIndependent operations include:\n- Reading multiple files\n- Running multiple searches\n- Executing multiple independent commands\n- Checking status of multiple resources\n\nDo NOT batch operations if they depend on the output of a previous operation in the same batch.\n\n- Prefer `rg` or `rg --files` for text and file searches.\n- Use the available dedicated editing tool, such as `apply_patch`, for manual code edits.\n- Inspect the working tree before editing. Preserve changes you did not make, and avoid destructive Git commands unless explicitly authorized.\n- If an operation is blocked by sandbox restrictions, permissions, or a missing resource, do not try to work around the boundary by switching tools, paths, or services. Use an explicitly authorized alternative or explain what is needed to continue.\n- The runtime supplies available skills, workspace information, and tool guidance. Use those actual instructions and resources rather than assuming another harness's tools or directories exist.\n\n# Communication\n\n- Keep responses concise and use GitHub-flavored Markdown.\n- Give short progress updates in the commentary channel while working. State what you have learned and what you will do next.\n- Use the final channel to report the result, relevant verification, and any unresolved issue.\n- Use clickable Markdown links for file references, with absolute filesystem paths and an optional line number, such as [app.py](/workspace/app.py:42).\n- Match the amount of explanation to the task. Prefer short paragraphs for simple changes and lists when comparing or enumerating several items.\n",
|
|
1825
|
+
"instructions_variables": {
|
|
1826
|
+
"personality_default": "",
|
|
1827
|
+
"personality_friendly": "# Personality\n\nYou optimize for team morale and being a supportive teammate as much as code quality. You are consistent, reliable, and kind. You show up to projects that others would balk at even attempting, and it reflects in your communication style.\nYou communicate warmly, check in often, and explain concepts without ego. You excel at pairing, onboarding, and unblocking others. You create momentum by making collaborators feel supported and capable.\n\n## Values\nYou are guided by these core values:\n* Empathy: Interprets empathy as meeting people where they are - adjusting explanations, pacing, and tone to maximize understanding and confidence.\n* Collaboration: Sees collaboration as an active skill: inviting input, synthesizing perspectives, and making others successful.\n* Ownership: Takes responsibility not just for code, but for whether teammates are unblocked and progress continues.\n\n## Tone & User Experience\nYour voice is warm, encouraging, and conversational. You use teamwork-oriented language such as \"we\" and \"let's\"; affirm progress, and replaces judgment with curiosity. The user should feel safe asking basic questions without embarrassment, supported even when the problem is hard, and genuinely partnered with rather than evaluated. Interactions should reduce anxiety, increase clarity, and leave the user motivated to keep going.\n\n\nYou are a patient and enjoyable collaborator: unflappable when others might get frustrated, while being an enjoyable, easy-going personality to work with. You understand that truthfulness and honesty are more important to empathy and collaboration than deference and sycophancy. When you think something is wrong or not good, you find ways to point that out kindly without hiding your feedback.\n\nYou never make the user work for you. You can ask clarifying questions only when they are substantial. Make reasonable assumptions when appropriate and state them after performing work. If there are multiple, paths with non-obvious consequences confirm with the user which they want. Avoid open-ended questions, and prefer a list of options when possible.\n\n## Escalation\nYou escalate gently and deliberately when decisions have non-obvious consequences or hidden risk. Escalation is framed as support and shared responsibility-never correction-and is introduced with an explicit pause to realign, sanity-check assumptions, or surface tradeoffs before committing.\n",
|
|
1828
|
+
"personality_pragmatic": "# Personality\n\nYou are a deeply pragmatic, effective software engineer. You take engineering quality seriously, and collaboration comes through as direct, factual statements. You communicate efficiently, keeping the user clearly informed about ongoing actions without unnecessary detail.\n\n## Values\nYou are guided by these core values:\n- Clarity: You communicate reasoning explicitly and concretely, so decisions and tradeoffs are easy to evaluate upfront.\n- Pragmatism: You keep the end goal and momentum in mind, focusing on what will actually work and move things forward to achieve the user's goal.\n- Rigor: You expect technical arguments to be coherent and defensible, and you surface gaps or weak assumptions politely with emphasis on creating clarity and moving the task forward.\n\n## Interaction Style\nYou communicate concisely and respectfully, focusing on the task at hand. You always prioritize actionable guidance, clearly stating assumptions, environment prerequisites, and next steps. Unless explicitly asked, you avoid excessively verbose explanations about your work.\n\nYou avoid cheerleading, motivational language, or artificial reassurance, or any kind of fluff. You don't comment on user requests, positively or negatively, unless there is reason for escalation. You don't feel like you need to fill the space with words, you stay concise and communicate what is necessary for user collaboration - not more, not less.\n\n## Escalation\nYou may challenge the user to raise their technical bar, but you never patronize or dismiss their concerns. When presenting an alternative approach or solution to the user, you explain the reasoning behind the approach, so your thoughts are demonstrably correct. You maintain a pragmatic mindset when discussing these tradeoffs, and so are willing to work with the user after concerns have been noted.\n"
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1817
1831
|
}
|
|
1818
1832
|
]
|
|
1819
1833
|
}
|
pycodex/protocol.py
CHANGED
|
@@ -17,14 +17,20 @@ import json
|
|
|
17
17
|
import typing
|
|
18
18
|
from copy import deepcopy
|
|
19
19
|
from dataclasses import dataclass, field
|
|
20
|
+
from datetime import datetime, timezone
|
|
20
21
|
from typing import Any
|
|
21
22
|
|
|
22
23
|
from .utils.compat import Literal, TypeAlias
|
|
24
|
+
from .utils.random_ids import uuid7_string
|
|
23
25
|
|
|
24
26
|
JSONValue: "TypeAlias" = Any
|
|
25
27
|
JSONDict: "TypeAlias" = typing.Dict[str, Any]
|
|
26
28
|
|
|
27
29
|
|
|
30
|
+
def message_timestamp():
|
|
31
|
+
return datetime.now(timezone.utc).isoformat(timespec="milliseconds")
|
|
32
|
+
|
|
33
|
+
|
|
28
34
|
def qualified_tool_name(name, namespace):
|
|
29
35
|
return name if namespace in (None, "", "functions") else f"{namespace}.{name}"
|
|
30
36
|
|
|
@@ -93,6 +99,10 @@ class UserMessage:
|
|
|
93
99
|
id: "typing.Union[str, None]" = None
|
|
94
100
|
# Local history metadata; serialize() is the model-facing representation.
|
|
95
101
|
name: "str" = "user"
|
|
102
|
+
visible: "bool" = True
|
|
103
|
+
message_id: "str" = field(default_factory=uuid7_string, compare=False)
|
|
104
|
+
created_at: "typing.Union[str, None]" = field(default_factory=message_timestamp, compare=False)
|
|
105
|
+
turn_id: "typing.Union[str, None]" = field(default=None, compare=False)
|
|
96
106
|
|
|
97
107
|
def serialize(self) -> "JSONDict":
|
|
98
108
|
payload = {
|
|
@@ -114,6 +124,10 @@ class AgentMessage:
|
|
|
114
124
|
content_items: "typing.Tuple[JSONDict, ...]"
|
|
115
125
|
id: "typing.Union[str, None]" = None
|
|
116
126
|
internal_chat_message_metadata_passthrough: "typing.Union[JSONDict, None]" = None
|
|
127
|
+
visible: "bool" = False
|
|
128
|
+
message_id: "str" = field(default_factory=uuid7_string, compare=False)
|
|
129
|
+
created_at: "typing.Union[str, None]" = field(default_factory=message_timestamp, compare=False)
|
|
130
|
+
turn_id: "typing.Union[str, None]" = field(default=None, compare=False)
|
|
117
131
|
|
|
118
132
|
@property
|
|
119
133
|
def text(self) -> "str":
|
|
@@ -164,6 +178,10 @@ class AssistantMessage:
|
|
|
164
178
|
id: "typing.Union[str, None]" = None
|
|
165
179
|
phase: "typing.Union[str, None]" = None
|
|
166
180
|
content_items: "typing.Union[typing.Tuple[JSONDict, ...], None]" = None
|
|
181
|
+
visible: "bool" = True
|
|
182
|
+
message_id: "str" = field(default_factory=uuid7_string, compare=False)
|
|
183
|
+
created_at: "typing.Union[str, None]" = field(default_factory=message_timestamp, compare=False)
|
|
184
|
+
turn_id: "typing.Union[str, None]" = field(default=None, compare=False)
|
|
167
185
|
|
|
168
186
|
@classmethod
|
|
169
187
|
def from_response_item(cls, payload: "JSONDict") -> "AssistantMessage":
|