Skip to content

Commit

Permalink
prevent infinite loop of getting relevant files
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonOstrez committed Aug 6, 2024
1 parent 7bd4f1a commit 1c5ece7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions core/agents/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from core.agents.convo import AgentConvo
from core.agents.response import AgentResponse
from core.config import GET_RELEVANT_FILES_AGENT_NAME
from core.llm.parser import JSONParser
from core.log import get_logger

Expand Down Expand Up @@ -66,7 +67,7 @@ async def get_relevant_files(

done = False
relevant_files = set()
llm = self.get_llm()
llm = self.get_llm(GET_RELEVANT_FILES_AGENT_NAME)
convo = (
AgentConvo(self)
.template(
Expand All @@ -78,7 +79,7 @@ async def get_relevant_files(
.require_schema(RelevantFiles)
)

while not done:
while not done and len(convo.messages) < 13:
llm_response: RelevantFiles = await llm(convo, parser=JSONParser(RelevantFiles), temperature=0)

# Check if there are files to add to the list
Expand Down
2 changes: 2 additions & 0 deletions core/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
CHECK_LOGS_AGENT_NAME = "BugHunter.check_logs"
TASK_BREAKDOWN_AGENT_NAME = "Developer.breakdown_current_task"
SPEC_WRITER_AGENT_NAME = "SpecWriter"
GET_RELEVANT_FILES_AGENT_NAME = "get_relevant_files"

# Endpoint for the external documentation
EXTERNAL_DOCUMENTATION_API = "http://docs-pythagora-io-439719575.us-east-1.elb.amazonaws.com"
Expand Down Expand Up @@ -330,6 +331,7 @@ class Config(_StrictModel):
temperature=0.5,
),
SPEC_WRITER_AGENT_NAME: AgentLLMConfig(model="gpt-4-0125-preview", temperature=0.0),
GET_RELEVANT_FILES_AGENT_NAME: AgentLLMConfig(model="claude-3-5-sonnet-20240620", temperature=0.0),
}
)
prompt: PromptConfig = PromptConfig()
Expand Down
14 changes: 10 additions & 4 deletions core/prompts/partials/filter_files_actions.prompt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ Here is the current relevant files list:
{% if relevant_files %}{{ relevant_files }}{% else %}[]{% endif %}

Now, with multiple iterations you have to find relevant files for the current task. Here are commands that you can use:
- `read_file` - list of files that you want to read
- `add_file` - add file to the list of relevant files
- `remove_file` - remove file from the list of relevant files
- `finished` - boolean command that you will use when you finish with adding files
- `read_files` - List of files that you want to read.
- `add_files` - Add file to the list of relevant files.
- `remove_files` - Remove file from the list of relevant files.
- `finished` - Boolean command that you will use when you finish with finding relevant files.

Make sure to follow these rules:
- 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.
- 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.
- 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.
- Focus only on your current task `{{ state.current_task.description }}` when selecting relevant files.

0 comments on commit 1c5ece7

Please sign in to comment.