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

View File

@ -4,6 +4,6 @@ repos:
- id: trufflehog
name: TruffleHog
description: Detect secrets in your data.
entry: bash -c 'trufflehog git file://. --since-commit HEAD --results=verified,unknown --fail'
entry: bash -c 'trufflehog git file://. --since-commit HEAD --results=verified,unknown --fail --no-update'
language: system
stages: ["commit", "push"]

28
main.py
View File

@ -29,22 +29,18 @@ def main():
server_address=config["MAIN"]["provider_server_address"])
agents = [
CasualAgent(model=config["MAIN"]["provider_model"],
name=config["MAIN"]["agent_name"],
prompt_path="prompts/casual_agent.txt",
provider=provider),
CoderAgent(model=config["MAIN"]["provider_model"],
name="coder",
prompt_path="prompts/coder_agent.txt",
provider=provider),
FileAgent(model=config["MAIN"]["provider_model"],
name="File Agent",
prompt_path="prompts/file_agent.txt",
provider=provider),
BrowserAgent(model=config["MAIN"]["provider_model"],
name="Browser",
prompt_path="prompts/browser_agent.txt",
provider=provider)
CasualAgent(name=config["MAIN"]["agent_name"],
prompt_path="prompts/casual_agent.txt",
provider=provider, verbose=False),
CoderAgent(name="coder",
prompt_path="prompts/coder_agent.txt",
provider=provider, verbose=False),
FileAgent(name="File Agent",
prompt_path="prompts/file_agent.txt",
provider=provider, verbose=False),
BrowserAgent(name="Browser",
prompt_path="prompts/browser_agent.txt",
provider=provider, verbose=False)
]
interaction = Interaction(agents, tts_enabled=config.getboolean('MAIN', 'speak'),

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)

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(),
}

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(),

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(),

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()

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()
}

View File

@ -20,7 +20,7 @@ class Memory():
recover_last_session: bool = False,
memory_compression: bool = True):
self.memory = []
self.memory = [{'role': 'user', 'content': system_prompt}]
self.memory = [{'role': 'system', 'content': system_prompt}]
self.session_time = datetime.datetime.now()
self.session_id = str(uuid.uuid4())

View File

@ -75,7 +75,7 @@ class searxSearch(Tools):
'Upgrade-Insecure-Requests': '1',
'User-Agent': self.user_agent
}
data = f"q={query}&categories=general&language=auto&time_range=&safesearch=0&theme=simple"
data = f"q={query}&categories=general&language=auto&time_range=&safesearch=0&theme=simple".encode('utf-8')
try:
response = requests.post(search_url, headers=headers, data=data, verify=False)
response.raise_for_status()