agentic-python-coder 3.4.1__py3-none-any.whl → 3.4.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.
- agentic_python_coder/agent.py +51 -5
- {agentic_python_coder-3.4.1.dist-info → agentic_python_coder-3.4.2.dist-info}/METADATA +1 -1
- {agentic_python_coder-3.4.1.dist-info → agentic_python_coder-3.4.2.dist-info}/RECORD +6 -6
- {agentic_python_coder-3.4.1.dist-info → agentic_python_coder-3.4.2.dist-info}/WHEEL +0 -0
- {agentic_python_coder-3.4.1.dist-info → agentic_python_coder-3.4.2.dist-info}/entry_points.txt +0 -0
- {agentic_python_coder-3.4.1.dist-info → agentic_python_coder-3.4.2.dist-info}/licenses/LICENSE +0 -0
agentic_python_coder/agent.py
CHANGED
|
@@ -19,6 +19,55 @@ from agentic_python_coder.tools import (
|
|
|
19
19
|
# Default maximum number of steps the agent can take before stopping
|
|
20
20
|
DEFAULT_STEP_LIMIT = 200
|
|
21
21
|
|
|
22
|
+
# Retries for API error responses the OpenAI SDK parses without raising:
|
|
23
|
+
# OpenRouter intermittently returns HTTP 200 whose body is an error object
|
|
24
|
+
# ({"choices": null, "error": {...}}), or a choice with finish_reason "error"
|
|
25
|
+
API_ERROR_MAX_RETRIES = 3
|
|
26
|
+
API_ERROR_BACKOFF_SECONDS = 5
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _response_error(response) -> Optional[str]:
|
|
30
|
+
"""Return a description if the response is an error envelope, else None."""
|
|
31
|
+
if not response.choices:
|
|
32
|
+
error = (getattr(response, "model_extra", None) or {}).get("error")
|
|
33
|
+
if error:
|
|
34
|
+
return f"no choices, error: {error}"
|
|
35
|
+
dump = getattr(response, "model_dump_json", None)
|
|
36
|
+
body = dump() if callable(dump) else repr(response)
|
|
37
|
+
return f"no choices, body: {body[:500]}"
|
|
38
|
+
choice = response.choices[0]
|
|
39
|
+
if choice.finish_reason == "error":
|
|
40
|
+
error = (getattr(choice, "model_extra", None) or {}).get("error") or (
|
|
41
|
+
getattr(response, "model_extra", None) or {}
|
|
42
|
+
).get("error")
|
|
43
|
+
return f"finish_reason 'error', error: {error}"
|
|
44
|
+
return None
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _create_with_retry(llm_config: LLMConfig, request_kwargs: dict, quiet: bool):
|
|
48
|
+
"""Call the completions API, retrying error responses.
|
|
49
|
+
|
|
50
|
+
Raises RuntimeError when retries are exhausted, so callers see a failure
|
|
51
|
+
instead of a silent early stop reported as success.
|
|
52
|
+
"""
|
|
53
|
+
detail = ""
|
|
54
|
+
for attempt in range(API_ERROR_MAX_RETRIES + 1):
|
|
55
|
+
response = llm_config.client.chat.completions.create(**request_kwargs)
|
|
56
|
+
detail = _response_error(response)
|
|
57
|
+
if detail is None:
|
|
58
|
+
return response
|
|
59
|
+
if not quiet:
|
|
60
|
+
print(
|
|
61
|
+
f"Warning: API returned an error response "
|
|
62
|
+
f"(attempt {attempt + 1}/{API_ERROR_MAX_RETRIES + 1}); {detail}"
|
|
63
|
+
)
|
|
64
|
+
if attempt < API_ERROR_MAX_RETRIES:
|
|
65
|
+
time.sleep(API_ERROR_BACKOFF_SECONDS * (attempt + 1))
|
|
66
|
+
raise RuntimeError(
|
|
67
|
+
f"API returned error responses on {API_ERROR_MAX_RETRIES + 1} attempts; "
|
|
68
|
+
f"last: {detail}"
|
|
69
|
+
)
|
|
70
|
+
|
|
22
71
|
|
|
23
72
|
def load_prompt(prompt_path: Path) -> str:
|
|
24
73
|
"""Load a prompt from file."""
|
|
@@ -246,8 +295,8 @@ def run_agent(
|
|
|
246
295
|
request_kwargs["tools"] = openai_tools
|
|
247
296
|
request_kwargs["tool_choice"] = "auto"
|
|
248
297
|
|
|
249
|
-
# Call API
|
|
250
|
-
response = agent.llm_config
|
|
298
|
+
# Call API (retries transient error responses, raises if they persist)
|
|
299
|
+
response = _create_with_retry(agent.llm_config, request_kwargs, quiet)
|
|
251
300
|
|
|
252
301
|
# Track tokens (some providers return usage objects with None fields)
|
|
253
302
|
if response.usage:
|
|
@@ -261,9 +310,6 @@ def run_agent(
|
|
|
261
310
|
response.usage.total_tokens or 0
|
|
262
311
|
)
|
|
263
312
|
|
|
264
|
-
if not response.choices:
|
|
265
|
-
break
|
|
266
|
-
|
|
267
313
|
assistant_message = response.choices[0].message
|
|
268
314
|
|
|
269
315
|
# Check for tool calls
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
agentic_python_coder/__init__.py,sha256=e6o-k__u5xNIiQAkZbHtbZC2-NwpeOdi4MdQtAqJBjE,2112
|
|
2
|
-
agentic_python_coder/agent.py,sha256=
|
|
2
|
+
agentic_python_coder/agent.py,sha256=0JfVNO-NEss9ZNEYkYvVlJSRzIxNa6sgRqLTdsD4zbs,16484
|
|
3
3
|
agentic_python_coder/cli.py,sha256=HS9nlqsiWZAvg0Hc8ExoVT8eEcy2t3Bux6UGukERWqQ,14663
|
|
4
4
|
agentic_python_coder/kernel.py,sha256=Q-yLb8Il54kZv41qev2uzASFlr6bGjQ7ztBy7yD48GM,23273
|
|
5
5
|
agentic_python_coder/llm.py,sha256=zjsk4-Kdx92hFSxywPGIkLv8zflWnE2cMEcpeXu6ttw,6998
|
|
@@ -41,8 +41,8 @@ agentic_python_coder/models/sonnet46.json,sha256=Ops1FpBoyx9PBGRhIXG8u-YGBgIui9D
|
|
|
41
41
|
agentic_python_coder/models/sonnet5.json,sha256=kf6DIkQlcGVZ40IzRv3GXFtNncZF_gKqQeGzZAxE_KM,87
|
|
42
42
|
agentic_python_coder/prompts/system.md,sha256=hREDVAhJXwCBAgJ3AE9JD6j-JRHREUPlkRSvThOvM3A,3807
|
|
43
43
|
agentic_python_coder/prompts/system_todo.md,sha256=TuNeeUNS9KqyF62Da6t2mlUCYhKsgzwGe5ic_vFPDqw,5054
|
|
44
|
-
agentic_python_coder-3.4.
|
|
45
|
-
agentic_python_coder-3.4.
|
|
46
|
-
agentic_python_coder-3.4.
|
|
47
|
-
agentic_python_coder-3.4.
|
|
48
|
-
agentic_python_coder-3.4.
|
|
44
|
+
agentic_python_coder-3.4.2.dist-info/METADATA,sha256=0LbGgUf4Gd3AS3C6dYjfDoayDSqq5vtlbkA3V9gssew,12872
|
|
45
|
+
agentic_python_coder-3.4.2.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
|
|
46
|
+
agentic_python_coder-3.4.2.dist-info/entry_points.txt,sha256=XIW3nZzL4kJ-Igohilj_mTvBcCyHBouDq2jmGzDILrk,107
|
|
47
|
+
agentic_python_coder-3.4.2.dist-info/licenses/LICENSE,sha256=R9-M_V-SPdN71IphOVzM7kCNpUYs_hwj7rtroTwDhs0,11362
|
|
48
|
+
agentic_python_coder-3.4.2.dist-info/RECORD,,
|
|
File without changes
|
{agentic_python_coder-3.4.1.dist-info → agentic_python_coder-3.4.2.dist-info}/entry_points.txt
RENAMED
|
File without changes
|
{agentic_python_coder-3.4.1.dist-info → agentic_python_coder-3.4.2.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|