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 - id: trufflehog
name: TruffleHog name: TruffleHog
description: Detect secrets in your data. 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 language: system
stages: ["commit", "push"] stages: ["commit", "push"]

28
main.py
View File

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

View File

@ -30,16 +30,24 @@ class Agent():
""" """
An abstract class for all agents. An abstract class for all agents.
""" """
def __init__(self, model: str, def __init__(self, name: str,
name: str,
prompt_path:str, prompt_path:str,
provider, 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.agent_name = name
self.role = None self.role = None
self.type = None self.type = None
self.current_directory = os.getcwd() self.current_directory = os.getcwd()
self.model = model
self.llm = provider self.llm = provider
self.memory = Memory(self.load_prompt(prompt_path), self.memory = Memory(self.load_prompt(prompt_path),
recover_last_session=recover_last_session, recover_last_session=recover_last_session,
@ -47,6 +55,7 @@ class Agent():
self.tools = {} self.tools = {}
self.blocks_result = [] self.blocks_result = []
self.last_answer = "" self.last_answer = ""
self.verbose = verbose
@property @property
def get_tools(self) -> dict: def get_tools(self) -> dict:
@ -94,12 +103,12 @@ class Agent():
end_idx = text.rfind(end_tag)+8 end_idx = text.rfind(end_tag)+8
return text[start_idx:end_idx] 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. Ask the LLM to process the prompt and return the answer and the reasoning.
""" """
memory = self.memory.get() memory = self.memory.get()
thought = self.llm.respond(memory, verbose) thought = self.llm.respond(memory, self.verbose)
reasoning = self.extract_reasoning_text(thought) reasoning = self.extract_reasoning_text(thought)
answer = self.remove_reasoning_text(thought) answer = self.remove_reasoning_text(thought)

View File

@ -9,11 +9,11 @@ from datetime import date
from typing import List, Tuple from typing import List, Tuple
class BrowserAgent(Agent): 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 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 = { self.tools = {
"web_search": searxSearch(), "web_search": searxSearch(),
} }

View File

@ -7,11 +7,11 @@ from sources.tools.fileFinder import FileFinder
from sources.tools.BashInterpreter import BashInterpreter from sources.tools.BashInterpreter import BashInterpreter
class CasualAgent(Agent): 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. 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 = { self.tools = {
"web_search": searxSearch(), "web_search": searxSearch(),
"flight_search": FlightSearch(), "flight_search": FlightSearch(),

View File

@ -11,8 +11,8 @@ class CoderAgent(Agent):
""" """
The code agent is an agent that can write and execute code. The code agent is an agent that can write and execute code.
""" """
def __init__(self, model, name, prompt_path, provider): def __init__(self, name, prompt_path, provider, verbose=False):
super().__init__(model, name, prompt_path, provider) super().__init__(name, prompt_path, provider, verbose)
self.tools = { self.tools = {
"bash": BashInterpreter(), "bash": BashInterpreter(),
"python": PyInterpreter(), "python": PyInterpreter(),

View File

@ -5,11 +5,11 @@ from sources.tools.fileFinder import FileFinder
from sources.tools.BashInterpreter import BashInterpreter from sources.tools.BashInterpreter import BashInterpreter
class FileAgent(Agent): 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. 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 = { self.tools = {
"file_finder": FileFinder(), "file_finder": FileFinder(),
"bash": BashInterpreter() "bash": BashInterpreter()

View File

@ -7,11 +7,11 @@ from sources.agents.browser_agent import BrowserAgent
from sources.tools.tools import Tools from sources.tools.tools import Tools
class PlannerAgent(Agent): 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. 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 = { self.tools = {
"json": Tools() "json": Tools()
} }

View File

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

View File

@ -75,7 +75,7 @@ class searxSearch(Tools):
'Upgrade-Insecure-Requests': '1', 'Upgrade-Insecure-Requests': '1',
'User-Agent': self.user_agent '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: try:
response = requests.post(search_url, headers=headers, data=data, verify=False) response = requests.post(search_url, headers=headers, data=data, verify=False)
response.raise_for_status() response.raise_for_status()