Skip to content

Commit 1c5ece7

Browse files
committed
prevent infinite loop of getting relevant files
1 parent 7bd4f1a commit 1c5ece7

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

core/agents/mixins.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from core.agents.convo import AgentConvo
66
from core.agents.response import AgentResponse
7+
from core.config import GET_RELEVANT_FILES_AGENT_NAME
78
from core.llm.parser import JSONParser
89
from core.log import get_logger
910

@@ -66,7 +67,7 @@ async def get_relevant_files(
6667

6768
done = False
6869
relevant_files = set()
69-
llm = self.get_llm()
70+
llm = self.get_llm(GET_RELEVANT_FILES_AGENT_NAME)
7071
convo = (
7172
AgentConvo(self)
7273
.template(
@@ -78,7 +79,7 @@ async def get_relevant_files(
7879
.require_schema(RelevantFiles)
7980
)
8081

81-
while not done:
82+
while not done and len(convo.messages) < 13:
8283
llm_response: RelevantFiles = await llm(convo, parser=JSONParser(RelevantFiles), temperature=0)
8384

8485
# Check if there are files to add to the list

core/config/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
CHECK_LOGS_AGENT_NAME = "BugHunter.check_logs"
4040
TASK_BREAKDOWN_AGENT_NAME = "Developer.breakdown_current_task"
4141
SPEC_WRITER_AGENT_NAME = "SpecWriter"
42+
GET_RELEVANT_FILES_AGENT_NAME = "get_relevant_files"
4243

4344
# Endpoint for the external documentation
4445
EXTERNAL_DOCUMENTATION_API = "http://docs-pythagora-io-439719575.us-east-1.elb.amazonaws.com"
@@ -330,6 +331,7 @@ class Config(_StrictModel):
330331
temperature=0.5,
331332
),
332333
SPEC_WRITER_AGENT_NAME: AgentLLMConfig(model="gpt-4-0125-preview", temperature=0.0),
334+
GET_RELEVANT_FILES_AGENT_NAME: AgentLLMConfig(model="claude-3-5-sonnet-20240620", temperature=0.0),
333335
}
334336
)
335337
prompt: PromptConfig = PromptConfig()

core/prompts/partials/filter_files_actions.prompt

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ Here is the current relevant files list:
22
{% if relevant_files %}{{ relevant_files }}{% else %}[]{% endif %}
33

44
Now, with multiple iterations you have to find relevant files for the current task. Here are commands that you can use:
5-
- `read_file` - list of files that you want to read
6-
- `add_file` - add file to the list of relevant files
7-
- `remove_file` - remove file from the list of relevant files
8-
- `finished` - boolean command that you will use when you finish with adding files
5+
- `read_files` - List of files that you want to read.
6+
- `add_files` - Add file to the list of relevant files.
7+
- `remove_files` - Remove file from the list of relevant files.
8+
- `finished` - Boolean command that you will use when you finish with finding relevant files.
9+
10+
Make sure to follow these rules:
11+
- All files that you want to read or add to the list of relevant files, must exist in the project. Do not ask to read or add file that does not exist! In the first message you have list of all files that currently exist in the project.
12+
- Do not repeat actions that you have already done. For example if you already added "index.js" to the list of relevant files you must not add it again.
13+
- You must read the file before adding it to the list of relevant files. Do not `add_files` that you didn't read and see the content of the file.
14+
- Focus only on your current task `{{ state.current_task.description }}` when selecting relevant files.

0 commit comments

Comments
 (0)