feat : file agent improved

This commit is contained in:
martin legrand
2025-03-26 12:06:27 +01:00
parent df922b18a7
commit 8922350379
11 changed files with 75 additions and 41 deletions
-1
View File
@@ -176,7 +176,6 @@ class Agent():
blocks, save_path = tool.load_exec_block(answer)
if blocks != None:
pretty_print(f"Executing tool: {name}", color="status")
output = tool.execute(blocks)
feedback = tool.interpreter_feedback(output) # tool interpreter feedback
success = not tool.execution_failure_check(output)
+4 -17
View File
@@ -13,11 +13,7 @@ class CasualAgent(Agent):
"""
super().__init__(name, prompt_path, provider, verbose)
self.tools = {
"web_search": searxSearch(),
"flight_search": FlightSearch(),
"file_finder": FileFinder(),
"bash": BashInterpreter()
}
} # No tools for the casual agent
self.role = {
"en": "talk",
"fr": "discuter",
@@ -27,19 +23,10 @@ class CasualAgent(Agent):
self.type = "casual_agent"
def process(self, prompt, speech_module) -> str:
complete = False
self.memory.push('user', prompt)
while not complete:
animate_thinking("Thinking...", color="status")
answer, reasoning = self.llm_request()
exec_success, _ = self.execute_modules(answer)
answer = self.remove_blocks(answer)
self.last_answer = answer
complete = True
for tool in self.tools.values():
if tool.found_executable_blocks():
complete = False # AI read results and continue the conversation
animate_thinking("Thinking...", color="status")
answer, reasoning = self.llm_request()
self.last_answer = answer
return answer, reasoning
if __name__ == "__main__":
+6
View File
@@ -33,11 +33,17 @@ class CoderAgent(Agent):
attempt = 0
max_attempts = 3
self.memory.push('user', prompt)
clarify_trigger = "REQUEST_CLARIFICATION"
while attempt < max_attempts:
animate_thinking("Thinking...", color="status")
self.wait_message(speech_module)
answer, reasoning = self.llm_request()
if clarify_trigger in answer:
return answer.replace(clarify_trigger, ""), reasoning
if not "```" in answer:
self.last_answer = answer
break
animate_thinking("Executing code...", color="status")
exec_success, _ = self.execute_modules(answer)
answer = self.remove_blocks(answer)
+2
View File
@@ -14,6 +14,7 @@ class FileAgent(Agent):
"file_finder": FileFinder(),
"bash": BashInterpreter()
}
self.work_dir = self.tools["file_finder"].get_work_dir()
self.role = {
"en": "files",
"fr": "fichiers",
@@ -24,6 +25,7 @@ class FileAgent(Agent):
def process(self, prompt, speech_module) -> str:
exec_success = False
prompt += f"\nWork directory: {self.work_dir}"
self.memory.push('user', prompt)
self.wait_message(speech_module)
+3
View File
@@ -103,7 +103,10 @@ class Interaction:
self.current_agent.memory.push('user', self.last_query)
self.current_agent.memory.push('assistant', self.last_answer)
self.current_agent = agent
tmp = self.last_answer
self.last_answer, _ = agent.process(self.last_query, self.speech)
if self.last_answer == tmp:
self.last_answer = None
def show_answer(self) -> None:
"""Show the answer to the user."""
+2
View File
@@ -263,6 +263,8 @@ class AgentRouter:
("What are some good netflix show like Altered Carbon ?", "web"),
("can you find the latest research paper on AI", "web"),
("can you find research.pdf in my drive", "files"),
("hi", "talk"),
("hello", "talk"),
]
texts = [text for text, _ in few_shots]
labels = [label for _, label in few_shots]
+3
View File
@@ -35,6 +35,9 @@ class Tools():
self.current_dir = self.create_work_dir()
self.excutable_blocks_found = False
def get_work_dir(self):
return self.current_dir
def check_config_dir_validity(self):
"""
Check if the config directory is valid.