Skip to content

Commit 5e897ea

Browse files
authored
Merge pull request #54 from commit-0/aider
add agent rerun after reach limit
2 parents 7b57bad + fb55a66 commit 5e897ea

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

agent/agents.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
import os
33
from abc import ABC, abstractmethod
44
from pathlib import Path
5+
import logging
56

67
from aider.coders import Coder
78
from aider.models import Model
89
from aider.io import InputOutput
10+
from tenacity import retry, wait_exponential
911

1012

1113
class Agents(ABC):
@@ -23,6 +25,9 @@ def __init__(self, max_iteration: int, model_name: str):
2325
super().__init__(max_iteration)
2426
self.model = Model(model_name)
2527

28+
@retry(
29+
wait=wait_exponential(multiplier=1, min=4, max=10),
30+
)
2631
def run(
2732
self,
2833
message: str,
@@ -44,10 +49,33 @@ def run(
4449
log_dir.mkdir(parents=True, exist_ok=True)
4550
input_history_file = log_dir / ".aider.input.history"
4651
chat_history_file = log_dir / ".aider.chat.history.md"
52+
4753
print(
4854
f"check {os.path.abspath(chat_history_file)} for prompts and lm generations",
4955
file=sys.stderr,
5056
)
57+
# Set up logging
58+
log_file = log_dir / "aider.log"
59+
logging.basicConfig(
60+
filename=log_file,
61+
level=logging.INFO,
62+
format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
63+
)
64+
65+
# Redirect print statements to the log file
66+
sys.stdout = open(log_file, "a")
67+
sys.stderr = open(log_file, "a")
68+
69+
# Configure httpx logging
70+
httpx_logger = logging.getLogger("httpx")
71+
httpx_logger.setLevel(logging.INFO)
72+
httpx_logger.propagate = False # Prevent propagation to root logger
73+
httpx_handler = logging.FileHandler(log_file)
74+
httpx_handler.setFormatter(
75+
logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
76+
)
77+
httpx_logger.addHandler(httpx_handler)
78+
5179
io = InputOutput(
5280
yes=True,
5381
input_history_file=input_history_file,
@@ -64,4 +92,13 @@ def run(
6492
)
6593
coder.max_reflection = self.max_iteration
6694
coder.stream = False
95+
96+
# Run the agent
6797
coder.run(message)
98+
99+
# Close redirected stdout and stderr
100+
sys.stdout.close()
101+
sys.stderr.close()
102+
# Restore original stdout and stderr
103+
sys.stdout = sys.__stdout__
104+
sys.stderr = sys.__stderr__

agent/run_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def run_agent(agent_config_file: str) -> None:
164164
with tqdm(
165165
total=len(filtered_dataset), smoothing=0, desc="Running Aider for repos"
166166
) as pbar:
167-
with multiprocessing.Pool(processes=10) as pool:
167+
with multiprocessing.Pool(processes=2) as pool:
168168
results = []
169169

170170
# Use apply_async to submit jobs and add progress bar updates

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies = [
1414
"aider-chat>=0.56.0",
1515
"modal>=0.64.95",
1616
"typer>=0.12.0",
17+
"tenacity>=8.5.0",
1718
"datasets>=3.0.0",
1819
"docker>=7.1.0",
1920
"fastcore>=1.7.8",

uv.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)