nanoPyCodeAgent 0.9.0__py3-none-any.whl → 0.10.0__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.
- nanopycodeagent/agent.py +55 -4
- {nanopycodeagent-0.9.0.dist-info → nanopycodeagent-0.10.0.dist-info}/METADATA +1 -1
- {nanopycodeagent-0.9.0.dist-info → nanopycodeagent-0.10.0.dist-info}/RECORD +6 -6
- {nanopycodeagent-0.9.0.dist-info → nanopycodeagent-0.10.0.dist-info}/WHEEL +1 -1
- {nanopycodeagent-0.9.0.dist-info → nanopycodeagent-0.10.0.dist-info}/entry_points.txt +0 -0
- {nanopycodeagent-0.9.0.dist-info → nanopycodeagent-0.10.0.dist-info}/licenses/LICENSE +0 -0
nanopycodeagent/agent.py
CHANGED
|
@@ -75,9 +75,15 @@ STREAM_RETRY_DELAYS = (1.0, 2.0)
|
|
|
75
75
|
STREAM_RETRY_WINDOW_SECONDS = 300.0
|
|
76
76
|
|
|
77
77
|
_TRUNCATION_NOTICE = (
|
|
78
|
-
"[response truncated: reached max_tokens
|
|
78
|
+
"[response truncated: reached max_tokens before finishing the task. "
|
|
79
79
|
"Tool calls from this response were not executed.]"
|
|
80
80
|
)
|
|
81
|
+
_TRUNCATION_RECOVERY_NOTE = (
|
|
82
|
+
"The previous response reached its output limit without finishing the task. "
|
|
83
|
+
"No tool calls from that response were executed. Continue from the last "
|
|
84
|
+
"confirmed tool results and current files within the remaining budget. "
|
|
85
|
+
"This is the only automatic truncation recovery for this run."
|
|
86
|
+
)
|
|
81
87
|
|
|
82
88
|
# How many model replies one headless task may spend before the run stops on
|
|
83
89
|
# its own. The interactive loop needs no such cap — a human watching the
|
|
@@ -199,7 +205,30 @@ HEADLESS_SYSTEM_PROMPT = (
|
|
|
199
205
|
"run. Runtime budget reminders report remaining time and model replies; "
|
|
200
206
|
"when either is running low, prioritize saving the required deliverables, "
|
|
201
207
|
"necessary verification, and a final summary. Do not start optional work "
|
|
202
|
-
"after the requirements are satisfied
|
|
208
|
+
"after the requirements are satisfied.\n\n"
|
|
209
|
+
"Identify the required deliverables, interfaces, and constraints. Treat "
|
|
210
|
+
"examples as evidence, not as the full contract unless the task says so. "
|
|
211
|
+
"Inspect relevant files, dependencies, and existing checks instead of "
|
|
212
|
+
"guessing. Task-supplied workspace files, including source, executables, "
|
|
213
|
+
"and tests, are available references unless the task restricts their use. "
|
|
214
|
+
"Consult general documentation as needed. Do not seek or use task-specific "
|
|
215
|
+
"reference solutions or hidden evaluation tests from outside the supplied "
|
|
216
|
+
"materials unless the task explicitly requests them. Derive checks from "
|
|
217
|
+
"the stated requirements.\n\n"
|
|
218
|
+
"Verify the requested behavior through the real entry point when feasible. "
|
|
219
|
+
"Check the content and meaning of outputs, not only command success or "
|
|
220
|
+
"file existence. For logic or numerical work, choose a few representative "
|
|
221
|
+
"and boundary cases justified by the task, using an independent reference, "
|
|
222
|
+
"invariant, or consistency check when available. Do not derive every "
|
|
223
|
+
"expectation from the implementation being tested or weaken requirements "
|
|
224
|
+
"to make a check pass. Keep verification proportional to the task and "
|
|
225
|
+
"remaining budget.\n\n"
|
|
226
|
+
"When a check fails, inspect the error and relevant output, revise the "
|
|
227
|
+
"underlying assumption or implementation, and rerun the affected check. "
|
|
228
|
+
"Keep the task's constraints intact. Once appropriate checks support the "
|
|
229
|
+
"required behavior, save the deliverables and finish. State what was "
|
|
230
|
+
"verified and any remaining limitation without claiming unobserved "
|
|
231
|
+
"success.\n\n"
|
|
203
232
|
) + _TOOL_GUIDANCE
|
|
204
233
|
|
|
205
234
|
def _json_value(value: object) -> JsonValue:
|
|
@@ -298,6 +327,8 @@ class _TextOutputProjector:
|
|
|
298
327
|
print()
|
|
299
328
|
if event.payload["stop_reason"] == "max_tokens":
|
|
300
329
|
print(_TRUNCATION_NOTICE, file=sys.stderr)
|
|
330
|
+
elif event.type == "input.injected" and event.payload["reason"] == "truncation_recovery":
|
|
331
|
+
print("[continuing after response truncation; recovery 1/1]", file=sys.stderr)
|
|
301
332
|
elif event.type == "model.failed" and event.payload["will_retry"]:
|
|
302
333
|
if str(event.payload["model_call_id"]) in self._model_calls_with_text:
|
|
303
334
|
print()
|
|
@@ -490,7 +521,8 @@ def _run_exchange(
|
|
|
490
521
|
|
|
491
522
|
Appends assistant replies and tool results to ``messages`` in place.
|
|
492
523
|
A truncated reply retains only its text and a notice in request history;
|
|
493
|
-
the original response is kept in the journal.
|
|
524
|
+
the original response is kept in the journal. Headless runs may recover
|
|
525
|
+
once within the original budgets. Returns the stopping outcome,
|
|
494
526
|
distinguishing completion, turn-budget exhaustion, and response truncation.
|
|
495
527
|
"""
|
|
496
528
|
run_id = f"run-{uuid.uuid4()}"
|
|
@@ -603,6 +635,8 @@ def _run_model_loop(
|
|
|
603
635
|
turns = 0
|
|
604
636
|
retries = 0
|
|
605
637
|
retry_deadline = None
|
|
638
|
+
truncation_recovered = False
|
|
639
|
+
recovery_pending = False
|
|
606
640
|
deadline = (
|
|
607
641
|
time.monotonic() + time_budget_seconds
|
|
608
642
|
if time_budget_seconds is not None and time_budget_seconds > 0
|
|
@@ -615,6 +649,15 @@ def _run_model_loop(
|
|
|
615
649
|
remaining = deadline - time.monotonic()
|
|
616
650
|
if remaining <= 0:
|
|
617
651
|
return "time_budget_exhausted"
|
|
652
|
+
if recovery_pending:
|
|
653
|
+
messages.append({"role": "user", "content": _TRUNCATION_RECOVERY_NOTE})
|
|
654
|
+
emitter.emit("input.injected", {
|
|
655
|
+
"model_call_id": model_call_id,
|
|
656
|
+
"content": _TRUNCATION_RECOVERY_NOTE,
|
|
657
|
+
"reason": "truncation_recovery",
|
|
658
|
+
"source_timestamp": utc_now(),
|
|
659
|
+
})
|
|
660
|
+
recovery_pending = False
|
|
618
661
|
if deadline is not None or (max_turns is not None and retries == 0):
|
|
619
662
|
_append_budget_note(
|
|
620
663
|
messages,
|
|
@@ -784,7 +827,7 @@ def _run_model_loop(
|
|
|
784
827
|
if message.stop_reason == "max_tokens":
|
|
785
828
|
# Do not execute partial tool calls or replay them without results.
|
|
786
829
|
# Thinking may also be cut off before its signature arrives. Keep
|
|
787
|
-
# visible text and an explicit notice for
|
|
830
|
+
# visible text and an explicit notice for a safe follow-up request.
|
|
788
831
|
text = "".join(
|
|
789
832
|
block.text for block in message.content if block.type == "text"
|
|
790
833
|
)
|
|
@@ -794,6 +837,14 @@ def _run_model_loop(
|
|
|
794
837
|
"content": (f"{text}\n\n" if text else "") + _TRUNCATION_NOTICE,
|
|
795
838
|
}
|
|
796
839
|
)
|
|
840
|
+
if (
|
|
841
|
+
not truncation_recovered
|
|
842
|
+
and (max_turns is not None or time_budget_seconds is not None)
|
|
843
|
+
and (max_turns is None or turns < max_turns)
|
|
844
|
+
):
|
|
845
|
+
truncation_recovered = True
|
|
846
|
+
recovery_pending = True
|
|
847
|
+
continue
|
|
797
848
|
return "response_truncated"
|
|
798
849
|
request_content = []
|
|
799
850
|
for block in message.content:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: nanoPyCodeAgent
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.10.0
|
|
4
4
|
Summary: A nano code agent built from scratch in pure Python.
|
|
5
5
|
Project-URL: Homepage, https://github.com/minixalpha/nanoPyCodeAgent
|
|
6
6
|
Project-URL: Repository, https://github.com/minixalpha/nanoPyCodeAgent
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
nanopycodeagent/__init__.py,sha256=uSIpn2Wz2y-xUU31rtpEE-WZ9ZXSWV9Fo1O03FUaHrE,57
|
|
2
|
-
nanopycodeagent/agent.py,sha256=
|
|
2
|
+
nanopycodeagent/agent.py,sha256=qliWCAO-d3l8Kt32XXzHhaS-VPQK1Y1Tue6p_KHPS1Y,43300
|
|
3
3
|
nanopycodeagent/atif.py,sha256=ykeTuXHRJdkEiIuFhFLbjbMOIfDZuHgYEzBi-2zr4nA,22466
|
|
4
4
|
nanopycodeagent/bash_tool.py,sha256=3PA2b7nr3KJY1MQLGlC3iy7Hn8S4XLslOsmpzpU0V08,4952
|
|
5
5
|
nanopycodeagent/cli.py,sha256=4zV4mz8JRAq9RBVHouPi_rMrkMaOm6X8gjfej2usKTI,6076
|
|
@@ -13,8 +13,8 @@ nanopycodeagent/terminal.py,sha256=jSe0CXayttR25RBt_qmCsFURVDW0uha391hBKgW3XwQ,3
|
|
|
13
13
|
nanopycodeagent/tool_validation.py,sha256=OhqFpyIt0VBL31jzfmWlHRHeE9FsTn30LHK0zVi15eU,1801
|
|
14
14
|
nanopycodeagent/transport.py,sha256=FS0_94vg47LZLgq7v7ZS1zRmr_V60xbAbcDgckERZ_4,495
|
|
15
15
|
nanopycodeagent/write_tool.py,sha256=dnHoNGT6HpQvJXQvxXPQcS4yBTtfwCkSV4hLAn9_YgY,6168
|
|
16
|
-
nanopycodeagent-0.
|
|
17
|
-
nanopycodeagent-0.
|
|
18
|
-
nanopycodeagent-0.
|
|
19
|
-
nanopycodeagent-0.
|
|
20
|
-
nanopycodeagent-0.
|
|
16
|
+
nanopycodeagent-0.10.0.dist-info/METADATA,sha256=tdg1htl6IBYk2IzvMqGEt3QlXNBjIsj3JeTl0oG0KF0,2836
|
|
17
|
+
nanopycodeagent-0.10.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
18
|
+
nanopycodeagent-0.10.0.dist-info/entry_points.txt,sha256=4gU7YNzQaf2RKlOdfebOWYNYIUk2LDoyhu3G4Vgole8,57
|
|
19
|
+
nanopycodeagent-0.10.0.dist-info/licenses/LICENSE,sha256=g24TppoiLdeF_1_-Y7H2H_eOavKseWA5utuK83Vq1sA,1067
|
|
20
|
+
nanopycodeagent-0.10.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|