Feat : improve prompt, add agent verbose option

This commit is contained in:
martin legrand
2025-03-24 14:41:24 +01:00
parent d423c08440
commit 323783b89e
10 changed files with 40 additions and 35 deletions
+15 -6
View File
@@ -30,16 +30,24 @@ class Agent():
"""
An abstract class for all agents.
"""
def __init__(self, model: str,
name: str,
def __init__(self, name: str,
prompt_path:str,
provider,
recover_last_session=True) -> None:
recover_last_session=True,
verbose=False) -> None:
"""
Args:
name (str): Name of the agent.
prompt_path (str): Path to the prompt file for the agent.
provider: The provider for the LLM.
recover_last_session (bool, optional): Whether to recover the last conversation.
verbose (bool, optional): Enable verbose logging if True. Defaults to False.
"""
self.agent_name = name
self.role = None
self.type = None
self.current_directory = os.getcwd()
self.model = model
self.llm = provider
self.memory = Memory(self.load_prompt(prompt_path),
recover_last_session=recover_last_session,
@@ -47,6 +55,7 @@ class Agent():
self.tools = {}
self.blocks_result = []
self.last_answer = ""
self.verbose = verbose
@property
def get_tools(self) -> dict:
@@ -94,12 +103,12 @@ class Agent():
end_idx = text.rfind(end_tag)+8
return text[start_idx:end_idx]
def llm_request(self, verbose = False) -> Tuple[str, str]:
def llm_request(self) -> Tuple[str, str]:
"""
Ask the LLM to process the prompt and return the answer and the reasoning.
"""
memory = self.memory.get()
thought = self.llm.respond(memory, verbose)
thought = self.llm.respond(memory, self.verbose)
reasoning = self.extract_reasoning_text(thought)
answer = self.remove_reasoning_text(thought)
+2 -2
View File
@@ -9,11 +9,11 @@ from datetime import date
from typing import List, Tuple
class BrowserAgent(Agent):
def __init__(self, model, name, prompt_path, provider):
def __init__(self, name, prompt_path, provider, verbose=False):
"""
The Browser agent is an agent that navigate the web autonomously in search of answer
"""
super().__init__(model, name, prompt_path, provider)
super().__init__(name, prompt_path, provider, verbose)
self.tools = {
"web_search": searxSearch(),
}
+2 -2
View File
@@ -7,11 +7,11 @@ from sources.tools.fileFinder import FileFinder
from sources.tools.BashInterpreter import BashInterpreter
class CasualAgent(Agent):
def __init__(self, model, name, prompt_path, provider):
def __init__(self, name, prompt_path, provider, verbose=False):
"""
The casual agent is a special for casual talk to the user without specific tasks.
"""
super().__init__(model, name, prompt_path, provider)
super().__init__(name, prompt_path, provider, verbose)
self.tools = {
"web_search": searxSearch(),
"flight_search": FlightSearch(),
+2 -2
View File
@@ -11,8 +11,8 @@ class CoderAgent(Agent):
"""
The code agent is an agent that can write and execute code.
"""
def __init__(self, model, name, prompt_path, provider):
super().__init__(model, name, prompt_path, provider)
def __init__(self, name, prompt_path, provider, verbose=False):
super().__init__(name, prompt_path, provider, verbose)
self.tools = {
"bash": BashInterpreter(),
"python": PyInterpreter(),
+2 -2
View File
@@ -5,11 +5,11 @@ from sources.tools.fileFinder import FileFinder
from sources.tools.BashInterpreter import BashInterpreter
class FileAgent(Agent):
def __init__(self, model, name, prompt_path, provider):
def __init__(self, name, prompt_path, provider, verbose=False):
"""
The file agent is a special agent for file operations.
"""
super().__init__(model, name, prompt_path, provider)
super().__init__(name, prompt_path, provider, verbose)
self.tools = {
"file_finder": FileFinder(),
"bash": BashInterpreter()
+2 -2
View File
@@ -7,11 +7,11 @@ from sources.agents.browser_agent import BrowserAgent
from sources.tools.tools import Tools
class PlannerAgent(Agent):
def __init__(self, model, name, prompt_path, provider):
def __init__(self, name, prompt_path, provider, verbose=False):
"""
The planner agent is a special agent that divides and conquers the task.
"""
super().__init__(model, name, prompt_path, provider)
super().__init__(name, prompt_path, provider, verbose)
self.tools = {
"json": Tools()
}