Agent Zero AI framework
Memory extensions, UI updates
frdeld233e0c94fa3
diff --git a/.gitignore b/.gitignoreindex f3671b64f..4e03ec2c6 100644--- a/.gitignore+++ b/.gitignore@@ -26,7 +26,16 @@ tmp/*# But do not ignore the directory itself!tmp/.gitkeep-# Ignore all contents of the directory "knowledge"+# Ignore everything in the "knowledge" directoryknowledge/*-# But do not ignore the directory itself-!knowledge/.gitkeep\ No newline at end of file++# Do not ignore subdirectories (so we can track .gitkeep)+!knowledge/*/++# Ignore all files within subdirectories (except .gitkeep)+knowledge/**/*.*+!knowledge/**/.gitkeep++# Explicitly allow the default folder and its contents+!knowledge/default/+!knowledge/default/**\ No newline at end of filediff --git a/.vscode/settings.json b/.vscode/settings.jsonindex 50879afee..4c03b2586 100644--- a/.vscode/settings.json+++ b/.vscode/settings.json@@ -1,4 +1,3 @@{"python.analysis.typeCheckingMode": "standard",- "deno.enable": true}\ No newline at end of filediff --git a/agent.py b/agent.pyindex 60a07a63d..5e4da261a 100644--- a/agent.py+++ b/agent.py@@ -14,6 +14,7 @@ from langchain_core.embeddings import Embeddingsimport python.helpers.log as Logfrom python.helpers.dirty_json import DirtyJsonfrom python.helpers.defer import DeferredTask+from typing import Callableclass AgentContext:@@ -90,7 +91,7 @@ class AgentConfig:embeddings_model: Embeddingsprompts_subdir: str = ""memory_subdir: str = ""- knowledge_subdir: str = ""+ knowledge_subdirs: list[str] = field(default_factory=lambda: ["default", "custom"])auto_memory_count: int = 3auto_memory_skip: int = 2rate_limit_seconds: int = 60@@ -162,29 +163,31 @@ class Agent:async def monologue(self, msg: str):try:- loop_data: dict[str, Any] = {"message": msg, "iteration": -1, "history_from": len(self.history) }+ # loop data dictionary to pass to extensions+ loop_data: dict[str, Any] = {+ "message": msg,+ "iteration": -1,+ "history_from": len(self.history),+ }- await self.call_extensions(- "monologue_start", loop_data=loop_data- ) # call monologue_start extensions+ # call monologue_start extensions+ await self.call_extensions("monologue_start", loop_data=loop_data)printer = PrintStyle(italic=True, font_color="#b3ffd9", padding=False)user_message = self.read_prompt("fw.user_message.md", message=msg)await self.append_message(user_message, human=True)await self.call_extensions(- "monologue_start", message=msg+ "monologue_start", loop_data=loop_data) # call monologue_end extensions- while (- True- ): # let the agent iterate on his thoughts until he stops by using a tool+ # let the agent run message loop until he stops it with a response tool+ while True:self.context.streaming_agent = self # mark self as current streameragent_response = ""loop_data["iteration"] += 1-try:# set system prompt and message history@@ -219,9 +222,9 @@ class Agent:font_color="green",padding=True,background_color="white",- ).print(f"{self.agent_name}: Generating:")+ ).print(f"{self.agent_name}: Generating")log = self.context.log.log(- type="agent", heading=f"{self.agent_name}: Generating:"+ type="agent", heading=f"{self.agent_name}: Generating")async for chunk in chain.astream(loop_data["history"]):@@ -346,7 +349,7 @@ class Agent:return "\n".join([f"{msg.type}: {msg.content}" for msg in messages])async def call_utility_llm(- self, system: str, msg: str, log_type: Log.Type = "util", output_label: str = ""+ self, system: str, msg: str, callback: Callable[[str], None] | None = None):prompt = ChatPromptTemplate.from_messages([SystemMessage(content=system), HumanMessage(content=msg)]@@ -354,17 +357,6 @@ class Agent:chain = prompt | self.config.utility_modelresponse = ""- printer = None- logger = None-- if output_label:- PrintStyle(- bold=True, font_color="orange", padding=True, background_color="white"- ).print(f"{self.agent_name}: {output_label}:")- printer = PrintStyle(italic=True, font_color="orange", padding=False)- logger = self.context.log.log(- type=log_type, heading=f"{self.agent_name}: {output_label}:"- )formatted_inputs = prompt.format()tokens = int(len(formatted_inputs) / 4)@@ -380,11 +372,10 @@ class Agent:else:content = str(chunk)- if printer:- printer.stream(content)+ if callback:+ callback(content)+response += content- if logger:- logger.update(content=response)self.rate_limiter.set_output_tokens(int(len(response) / 4))@@ -396,10 +387,23 @@ class Agent:async def replace_middle_messages(self, middle_messages):cleanup_prompt = self.read_prompt("fw.msg_cleanup.md")+ log_item = self.context.log.log(+ type="util", heading="Mid messages cleanup summary"+ )++ PrintStyle(+ bold=True, font_color="orange", padding=True, background_color="white"+ ).print(f"{self.agent_name}: Mid messages cleanup summary")+ printer = PrintStyle(italic=True, font_color="orange", padding=False)++ def log_callback(content):+ printer.print(content)+ log_item.stream(content=content)+summary = await self.call_utility_llm(system=cleanup_prompt,msg=self.concat_messages(middle_messages),- output_label="Mid messages cleanup summary",+ callback=log_callback,)new_human_message = HumanMessage(content=summary)return [new_human_message]@@ -473,7 +477,7 @@ class Agent:await self.append_message(msg, human=True)PrintStyle(font_color="red", padding=True).print(msg)self.context.log.log(- type="error", content=f"{self.agent_name}: Message misformat:"+ type="error", content=f"{self.agent_name}: Message misformat")def log_from_stream(self, stream: str, logItem: Log.LogItem):diff --git a/example.env b/example.envindex ddb5d4296..d0bc2093b 100644--- a/example.env+++ b/example.env@@ -2,9 +2,10 @@ API_KEY_OPENAI=API_KEY_ANTHROPIC=API_KEY_GROQ=API_KEY_PERPLEXITY=-GOOGLE_API_KEY=-MISTRAL_API_KEY=+API_KEY_GOOGLE=+API_KEY_MISTRAL=API_KEY_OPENROUTER=+API_KEY_SAMBANOVA=API_KEY_OPENAI_AZURE=OPENAI_AZURE_ENDPOINT=@@ -22,3 +23,4 @@ PYDEVD_DISABLE_FILE_VALIDATION=1OLLAMA_BASE_URL="http://127.0.0.1:11434"LM_STUDIO_BASE_URL="http://127.0.0.1:1234/v1"OPEN_ROUTER_BASE_URL="https://openrouter.ai/api/v1"+SAMBANOVA_BASE_URL="https://fast-api.snova.ai/v1"\ No newline at end of filediff --git a/initialize.py b/initialize.pyindex b578e72f5..cafe43130 100644--- a/initialize.py+++ b/initialize.py@@ -7,15 +7,16 @@ def initialize():chat_llm = models.get_openai_chat(model_name="gpt-4o-mini", temperature=0)# chat_llm = models.get_ollama_chat(model_name="gemma2:latest", temperature=0)# chat_llm = models.get_lmstudio_chat(model_name="lmstudio-community/Meta-Llama-3.1-8B-Instruct-GGUF", temperature=0)- # chat_llm = models.get_openrouter_chat(model_name="mattshumer/reflection-70b:free")+ # chat_llm = models.get_openrouter_chat(model_name="openai/o1-mini-2024-09-12")# chat_llm = models.get_azure_openai_chat(deployment_name="gpt-4o-mini", temperature=0)# chat_llm = models.get_anthropic_chat(model_name="claude-3-5-sonnet-20240620", temperature=0)# chat_llm = models.get_google_chat(model_name="gemini-1.5-flash", temperature=0)# chat_llm = models.get_mistral_chat(model_name="mistral-small-latest", temperature=0)# chat_llm = models.get_groq_chat(model_name="llama-3.1-70b-versatile", temperature=0)-+ # chat_llm = models.get_sambanova_chat(model_name="Meta-Llama-3.1-70B-Instruct-8k", temperature=0)+# utility model used for helper functions (cheaper, faster)- utility_llm = chat_llm # change if you want to use a different utility model+ utility_llm = chat_llm# embedding model used for memoryembedding_llm = models.get_openai_embedding(model_name="text-embedding-3-small")@@ -30,7 +31,7 @@ def initialize():embeddings_model = embedding_llm,# prompts_subdir = "",# memory_subdir = "",- # knowledge_subdir: str = ""+ knowledge_subdirs = ["default","custom"],auto_memory_count = 0,# auto_memory_skip = 2,# rate_limit_seconds = 60,diff --git a/knowledge/custom/.gitkeep b/knowledge/custom/.gitkeepnew file mode 100644index 000000000..e69de29bbdiff --git a/knowledge/custom/main/.gitkeep b/knowledge/custom/main/.gitkeepnew file mode 100644index 000000000..e69de29bbdiff --git a/knowledge/custom/solutions/.gitkeep b/knowledge/custom/solutions/.gitkeepnew file mode 100644index 000000000..e69de29bbdiff --git a/knowledge/default/.gitkeep b/knowledge/default/.gitkeepnew file mode 100644index 000000000..e69de29bbdiff --git a/knowledge/default/main/.gitkeep b/knowledge/default/main/.gitkeepnew file mode 100644index 000000000..e69de29bbdiff --git a/knowledge/default/solutions/.gitkeep b/knowledge/default/solutions/.gitkeepnew file mode 100644index 000000000..e69de29bbdiff --git a/knowledge/default/solutions/yt_download.md b/knowledge/default/solutions/yt_download.mdnew file mode 100644index 000000000..2aaa6ccef--- /dev/null+++ b/knowledge/default/solutions/yt_download.md@@ -0,0 +1,6 @@+# Problem+Download a YouTube video+# Solution+1. If you don't have exact URL, use knowledge_tool to get it+2. Pip install yt-dlp and ffmpeg+3. Download the video using yt-dlp command: 'yt-dlp YT_URL', replace YT_URL with your video URL.\ No newline at end of filediff --git a/models.py b/models.pyindex e4479a4bc..d9ce45fcf 100644--- a/models.py+++ b/models.py@@ -84,3 +84,8 @@ def get_openrouter_chat(model_name: str, api_key=get_api_key("openrouter"), tempdef get_openrouter_embedding(model_name: str, api_key=get_api_key("openrouter"), base_url=os.getenv("OPEN_ROUTER_BASE_URL") or "https://openrouter.ai/api/v1"):return OpenAIEmbeddings(model=model_name, api_key=api_key, base_url=base_url) # type: ignore++# Sambanova models+def get_sambanova_chat(model_name: str, api_key=get_api_key("sambanova"), temperature=DEFAULT_TEMPERATURE, base_url=os.getenv("SAMBANOVA_BASE_URL") or "https://fast-api.snova.ai/v1", max_tokens=1024):+ return ChatOpenAI(api_key=api_key, model=model_name, temperature=temperature, base_url=base_url, max_tokens=max_tokens) # type: ignore+diff --git a/prompts/default/agent.system.memories.md b/prompts/default/agent.system.memories.mdnew file mode 100644index 000000000..f7ab13fa5--- /dev/null+++ b/prompts/default/agent.system.memories.md@@ -0,0 +1,4 @@+# Memories on the topic+- following are your memories about current topic:++{{memories}}\ No newline at end of filediff --git a/prompts/default/memory.memories_query.sys.md b/prompts/default/memory.memories_query.sys.mdnew file mode 100644index 000000000..c9bba5979--- /dev/null+++ b/prompts/default/memory.memories_query.sys.md@@ -0,0 +1,19 @@+# AI's job+1. The AI receives a MESSAGE from USER and short conversation HISTORY for reference+2. AI analyzes the MESSAGE and HISTORY for CONTEXT+3. AI provide a search query for search engine where previous memories are stored based on CONTEXT++# Format+- The response format is a plain text string containing the query+- No other text, no formatting++# Example+```json+USER: "Write a song about my dog"+AI: "user's dog"+USER: "following the results of the biology project, summarize..."+AI: "biology project results"+```++# HISTORY:+{{history}}\ No newline at end of filediff --git a/prompts/default/memory.memories_sum.sys.md b/prompts/default/memory.memories_sum.sys.mdnew file mode 100644index 000000000..d29986e99--- /dev/null+++ b/prompts/default/memory.memories_sum.sys.md@@ -0,0 +1,22 @@+# Assistant's job+1. The assistant receives a HISTORY of conversation between USER and AGENT+2. Assistant searches for relevant information from the HISTORY+3. Assistant writes notes about information worth memorizing for further use++# Format+- The response format is a JSON array of text notes containing facts to memorize+- If the history does not contain any useful information, the response will be an empty JSON array.++# Example+~~~json+[+ "User's name is John Doe",+ "User's age is 30"+]+~~~++# Rules+- Focus only on relevant details and facts like names, IDs, instructions, opinions etc.+- Do not include irrelevant details that are of no use in the future+- Do not memorize facts that change like time, date etc.+- Do not add your own details that are not specifically mentioned in the history\ No newline at end of filediff --git a/python/extensions/message_loop_prompts/recall_memories.py b/python/extensions/message_loop_prompts/recall_memories.pynew file mode 100644index 000000000..a14092f2e--- /dev/null+++ b/python/extensions/message_loop_prompts/recall_memories.py@@ -0,0 +1,97 @@+from agent import Agent+from python.helpers.extension import Extension+from python.helpers.files import read_file+from python.helpers.vector_db import Area+import json+from python.helpers import errors, files+from python.tools.memory_tool import get_db+++class RecallMemories(Extension):++ INTERVAL = 3+ HISTORY = 5+ RESULTS = 3+ THRESHOLD = 0.1++ async def execute(self, loop_data={}, **kwargs):++ iter = loop_data.get("iteration", 0)+ if (+ iter % RecallMemories.INTERVAL == 0+ ): # every 3 iterations (or the first one) recall memories+ await self.search_memories(loop_data=loop_data, **kwargs)++ async def search_memories(self, loop_data={}, **kwargs):+ # try:+ # show temp info message+ self.agent.context.log.log(+ type="info", content="Searching memories...", temp=True+ )++ # show full util message, this will hide temp message immediately if turned on+ log_item = self.agent.context.log.log(+ type="util",+ heading="Searching memories...",+ )++ # get system message and chat history for util llm+ msgs_text = self.agent.concat_messages(+ self.agent.history[-RecallMemories.HISTORY :]+ ) # only last X messages+ system = self.agent.read_prompt(+ "memory.memories_query.sys.md", history=msgs_text+ )++ # log query streamed by LLM+ def log_callback(content):+ log_item.stream(query=content)++ # call util llm to summarize conversation+ query = await self.agent.call_utility_llm(+ system=system, msg=loop_data["message"], callback=log_callback+ )++ # get solutions database+ vdb = get_db(self.agent)++ memories = vdb.search_similarity_threshold(+ query=query,+ results=RecallMemories.RESULTS,+ threshold=RecallMemories.THRESHOLD,+ filter=f"area != '{Area.SOLUTIONS.value}'" # exclude solutions+ )++ # log the short result+ if not isinstance(memories, list) or len(memories) == 0:+ log_item.update(+ heading="No useful memories found.",+ )+ return+ else:+ log_item.update(+ heading=f"\n\n{len(memories)} memories found.",+ )++ # concatenate memory.page_content in memories:+ memories_text = ""+ for memory in memories:+ memories_text += memory.page_content + "\n\n"+ memories_text = memories_text.strip()++ # log the full results+ log_item.update(memories=memories_text)++ # place to prompt+ memories_prompt = self.agent.read_prompt(+ "agent.system.memories.md", memories=memories_text+ )++ # append to system message+ loop_data["system"] += memories_prompt++ # except Exception as e:+ # err = errors.format_error(e)+ # self.agent.context.log.log(+ # type="error", heading="Recall memories extension error:", content=err+ # )diff --git a/python/extensions/message_loop_prompts/recall_solutions.py b/python/extensions/message_loop_prompts/recall_solutions.pyindex ab3fb1c9d..60f3997ed 100644--- a/python/extensions/message_loop_prompts/recall_solutions.py+++ b/python/extensions/message_loop_prompts/recall_solutions.py@@ -1,8 +1,10 @@from agent import Agentfrom python.helpers.extension import Extensionfrom python.helpers.files import read_file-from python.helpers.vector_db import get_or_create+from python.helpers.vector_db import Areaimport json+from python.helpers import errors, files+from python.tools.memory_tool import get_dbclass RecallSolutions(Extension):@@ -15,59 +17,81 @@ class RecallSolutions(Extension):async def execute(self, loop_data={}, **kwargs):iter = loop_data.get("iteration", 0)- if iter % RecallSolutions.INTERVAL == 0: # every 3 iterations (or the first one) recall solution memories+ if (+ iter % RecallSolutions.INTERVAL == 0+ ): # every 3 iterations (or the first one) recall solution memoriesawait self.search_solutions(loop_data=loop_data, **kwargs)-async def search_solutions(self, loop_data={}, **kwargs):- self.agent.context.log.log(- type="info", content="Searching memory for solutions...", temp=False- )-- # get system message and chat history for util llm- msgs_text = self.agent.concat_messages(- self.agent.history[-RecallSolutions.HISTORY:]- ) # only last X messages- system = self.agent.read_prompt(- "memory.solutions_query.sys.md", history=msgs_text- )-- # call util llm to summarize conversation- query = await self.agent.call_utility_llm(- system=system, msg=loop_data["message"]- )-- # get solutions database- vdb = get_or_create(- logger=self.agent.context.log,- embeddings_model=self.agent.config.embeddings_model,- memory_dir="./memory/solutions",- knowledge_dir="",- )-- solutions = vdb.search_similarity_threshold(- query=query, results=RecallSolutions.RESULTS, threshold=RecallSolutions.THRESHOLD- )-- if not isinstance(solutions, list) or len(solutions) == 0:+ # try:+ # show temp info messageself.agent.context.log.log(- type="info", content="No successful solution memories found.", temp=False+ type="info", content="Searching memory for solutions...", temp=True)- return- else:- self.agent.context.log.log(- type="info",- content=f"{len(solutions)} successful solution memories found.",- temp=False,++ # show full util message, this will hide temp message immediately if turned on+ log_item = self.agent.context.log.log(+ type="util",+ heading="Searching memory for solutions...",+ )++ # get system message and chat history for util llm+ msgs_text = self.agent.concat_messages(+ self.agent.history[-RecallSolutions.HISTORY :]+ ) # only last X messages+ system = self.agent.read_prompt(+ "memory.solutions_query.sys.md", history=msgs_text+ )++ # log query streamed by LLM+ def log_callback(content):+ log_item.stream(query=content)++ # call util llm to summarize conversation+ query = await self.agent.call_utility_llm(+ system=system, msg=loop_data["message"], callback=log_callback)- # concatenate solution.page_content in solutions:- solutions_text = ""- for solution in solutions:- solutions_text += solution.page_content + "\n\n"+ # get solutions database+ vdb = get_db(self.agent)++ solutions = vdb.search_similarity_threshold(+ query=query,+ results=RecallSolutions.RESULTS,+ threshold=RecallSolutions.THRESHOLD,+ filter=f"area == '{Area.SOLUTIONS.value}'"+ )++ # log the short result+ if not isinstance(solutions, list) or len(solutions) == 0:+ log_item.update(+ heading="No successful solution memories found.",+ )+ return+ else:+ log_item.update(+ heading=f"\n\n{len(solutions)} successful solution memories found.",+ )++ # concatenate solution.page_content in solutions:+ solutions_text = ""+ for solution in solutions:+ solutions_text += solution.page_content + "\n\n"+ solutions_text = solutions_text.strip()++ # log the full results+ log_item.update(solutions=solutions_text)++ # place to prompt+ solutions_prompt = self.agent.read_prompt(+ "agent.system.solutions.md", solutions=solutions_text+ )- # place to prompt- solutions_prompt = self.agent.read_prompt("agent.system.solutions.md", solutions=solutions_text)+ # append to system message+ loop_data["system"] += solutions_prompt- # append to system message- loop_data["system"] += solutions_prompt+ # except Exception as e:+ # err = errors.format_error(e)+ # self.agent.context.log.log(+ # type="error", heading="Recall solutions extension error:", content=err+ # )diff --git a/python/extensions/monologue_end/50_memorize_memories.py b/python/extensions/monologue_end/50_memorize_memories.pynew file mode 100644index 000000000..6a4c7dfa2--- /dev/null+++ b/python/extensions/monologue_end/50_memorize_memories.py@@ -0,0 +1,74 @@+from agent import Agent+from python.helpers.extension import Extension+import python.helpers.files as files+from python.helpers.vector_db import Area+import json+from python.helpers.dirty_json import DirtyJson+from python.helpers import errors+from python.tools.memory_tool import get_db++class MemorizeMemories(Extension):++ async def execute(self, loop_data={}, **kwargs):+ # try:++ # show temp info message+ self.agent.context.log.log(+ type="info", content="Memorizing new information...", temp=True+ )++ # show full util message, this will hide temp message immediately if turned on+ log_item = self.agent.context.log.log(+ type="util",+ heading="Memorizing new information...",+ )++ # get system message and chat history for util llm+ system = self.agent.read_prompt("memory.memories_sum.sys.md")+ msgs_text = self.agent.concat_messages(self.agent.history)++ # log query streamed by LLM+ def log_callback(content):+ log_item.stream(content=content)++ # call util llm to find info in history+ memories_json = await self.agent.call_utility_llm(+ system=system,+ msg=msgs_text,+ callback=log_callback,+ )++ memories = DirtyJson.parse_string(memories_json)++ if not isinstance(memories, list) or len(memories) == 0:+ log_item.update(heading="No useful information to memorize.")+ return+ else:+ log_item.update(+ heading=f"{len(memories)} entries to memorize."+ )++ # save chat history+ vdb = get_db(self.agent)++ memories_txt = ""+ for memory in memories:+ # solution to plain text:+ txt = f"{memory}"+ memories_txt += txt + "\n\n"+ vdb.insert_text(+ text=txt, metadata={"area": Area.MAIN.value}+ )++ memories_txt = memories_txt.strip()+ log_item.update(memories=memories_txt)+ log_item.update(+ result=f"{len(memories)} entries memorized.",+ heading=f"{len(memories)} entries memorized.",+ )++ # except Exception as e:+ # err = errors.format_error(e)+ # self.agent.context.log.log(+ # type="error", heading="Memorize memories extension error:", content=err+ # )diff --git a/python/extensions/monologue_end/51_memorize_solutions.py b/python/extensions/monologue_end/51_memorize_solutions.pynew file mode 100644index 000000000..459ab0dde--- /dev/null+++ b/python/extensions/monologue_end/51_memorize_solutions.py@@ -0,0 +1,74 @@+from agent import Agent+from python.helpers.extension import Extension+import python.helpers.files as files+from python.helpers.vector_db import Area+import json+from python.helpers.dirty_json import DirtyJson+from python.helpers import errors+from python.tools.memory_tool import get_db++class MemorizeSolutions(Extension):++ async def execute(self, loop_data={}, **kwargs):+ # try:++ # show temp info message+ self.agent.context.log.log(+ type="info", content="Memorizing succesful solutions...", temp=True+ )++ # show full util message, this will hide temp message immediately if turned on+ log_item = self.agent.context.log.log(+ type="util",+ heading="Memorizing succesful solutions...",+ )++ # get system message and chat history for util llm+ system = self.agent.read_prompt("memory.solutions_sum.sys.md")+ msgs_text = self.agent.concat_messages(self.agent.history)++ # log query streamed by LLM+ def log_callback(content):+ log_item.stream(content=content)++ # call util llm to find solutions in history+ solutions_json = await self.agent.call_utility_llm(+ system=system,+ msg=msgs_text,+ callback=log_callback,+ )++ solutions = DirtyJson.parse_string(solutions_json)++ if not isinstance(solutions, list) or len(solutions) == 0:+ log_item.update(heading="No successful solutions to memorize.")+ return+ else:+ log_item.update(+ heading=f"{len(solutions)} successful solutions to memorize."+ )++ # save chat history+ vdb = get_db(self.agent)++ solutions_txt = ""+ for solution in solutions:+ # solution to plain text:+ txt = f"# Problem\n {solution['problem']}\n# Solution\n {solution['solution']}"+ solutions_txt += txt + "\n\n"+ vdb.insert_text(+ text=txt, metadata={"area": Area.SOLUTIONS.value}+ )++ solutions_txt = solutions_txt.strip()+ log_item.update(solutions=solutions_txt)+ log_item.update(+ result=f"{len(solutions)} solutions memorized.",+ heading=f"{len(solutions)} solutions memorized.",+ )++ # except Exception as e:+ # err = errors.format_error(e)+ # self.agent.context.log.log(+ # type="error", heading="Memorize solutions extension error:", content=err+ # )diff --git a/python/extensions/monologue_end/90_waiting_for_input_msg.py b/python/extensions/monologue_end/90_waiting_for_input_msg.pynew file mode 100644index 000000000..2d3b558e8--- /dev/null+++ b/python/extensions/monologue_end/90_waiting_for_input_msg.py@@ -0,0 +1,12 @@+from agent import Agent+from python.helpers.extension import Extension++class WaitingForInputMsg(Extension):++ async def execute(self, loop_data={}, **kwargs):+ # show temp info message+ if self.agent.number == 0:+ self.agent.context.log.log(+ type="util", heading="Waiting for input", temp=True+ )+diff --git a/python/extensions/monologue_end/memorize_solutions.py b/python/extensions/monologue_end/memorize_solutions.pydeleted file mode 100644index 666ffff66..000000000--- a/python/extensions/monologue_end/memorize_solutions.py+++ /dev/null@@ -1,70 +0,0 @@-from agent import Agent-from python.helpers.extension import Extension-from python.helpers.files import read_file-from python.helpers.vector_db import get_or_create-import json-from python.helpers.dirty_json import DirtyJson-from python.helpers import errors---class MemorizeSolutions(Extension):-- async def execute(self, loop_data={}, **kwargs):- try:- self.agent.context.log.log(- type="info", content="Memorizing succesful solutions...", temp=True- )-- # get system message and chat history for util llm- system = self.agent.read_prompt("memory.solutions_sum.sys.md")- msgs_text = self.agent.concat_messages(self.agent.history)-- # call util llm to find solutions in history- solutions_json = await self.agent.call_utility_llm(- system=system,- msg=msgs_text,- log_type="util",- )-- solutions = DirtyJson.parse_string(solutions_json)-- if not isinstance(solutions, list) or len(solutions) == 0:- self.agent.context.log.log(- type="info", content="No succesful solutions found.", temp=False- )- return- else:- self.agent.context.log.log(- type="info",- content=f"{len(solutions)} succesful solutions found.",- temp=True,- )-- # save chat history- vdb = get_or_create(- logger=self.agent.context.log,- embeddings_model=self.agent.config.embeddings_model,- memory_dir="./memory/solutions",- knowledge_dir="",- )-- for solution in solutions:- # solution to plain text:- txt = (- f"Problem: {solution['problem']}\nSolution: {solution['solution']}"- )- vdb.insert_text(- text=txt,- ) # metadata={"full": msgs_text})-- self.agent.context.log.log(- type="info",- content=f"{len(solutions)} solutions memorized.",- temp=False,- )-- except Exception as e:- err = errors.format_error(e)- self.agent.context.log.log(- type="error", heading="Memorize solutions extension error:", content=err- )diff --git a/python/extensions/msg_loop_break/zero_memorize_history.py b/python/extensions/msg_loop_break/zero_memorize_history.pydeleted file mode 100644index a2beec64d..000000000--- a/python/extensions/msg_loop_break/zero_memorize_history.py+++ /dev/null@@ -1,35 +0,0 @@-from agent import Agent-from python.helpers.extension import Extension-from python.helpers.files import read_file-from python.helpers.vector_db import VectorDB-import json--class MemorizeHistory(Extension):-- async def execute(self, **kwargs):- if self.agent.number != 0: return #only agent 0 will memorize chat history with user-- self.agent.context.log.log(type="info", content="Memorizing chat history...", temp=True)-- #get system message and chat history for util llm- system = self.agent.read_prompt("fw.memory.hist_sum.sys")- msgs = []- for msg in self.agent.history:- content = msg.get("content", "")- if content:- msgs.append(content)- msgs_json = json.dumps(msgs)-- #call util llm to summarize conversation- summary = await self.agent.call_utility_llm(system=system,msg=msgs_json,output_label="")-- #save chat history- vdb = VectorDB(- logger=self.agent.context.log,- embeddings_model=self.agent.config.embeddings_model,- memory_dir="./memory/history",- knowledge_dir=""- )-- self.agent.context.log.log(type="info", content="Chat history memorized.", temp=True)-\ No newline at end of filediff --git a/python/helpers/knowledge_import.py b/python/helpers/knowledge_import.pyindex ca748d674..54f2152a7 100644--- a/python/helpers/knowledge_import.py+++ b/python/helpers/knowledge_import.py@@ -4,13 +4,17 @@ import hashlibimport jsonfrom typing import Any, Dict, Literal, TypedDictfrom langchain_community.document_loaders import (- CSVLoader, JSONLoader, PyPDFLoader, TextLoader, UnstructuredHTMLLoader,- UnstructuredMarkdownLoader+ CSVLoader,+ JSONLoader,+ PyPDFLoader,+ TextLoader,+ UnstructuredHTMLLoader,+ UnstructuredMarkdownLoader,)from python.helpers import files-from python.helpers.log import Log+from python.helpers.log import LogItem-text_loader_kwargs = {'autodetect_encoding': True}+text_loader_kwargs = {"autodetect_encoding": True}class KnowledgeImport(TypedDict):@@ -23,65 +27,91 @@ class KnowledgeImport(TypedDict):def calculate_checksum(file_path: str) -> str:hasher = hashlib.md5()- with open(file_path, 'rb') as f:+ with open(file_path, "rb") as f:buf = f.read()hasher.update(buf)return hasher.hexdigest()-def load_knowledge(logger: Log, knowledge_dir: str, index: Dict[str, KnowledgeImport]) -> Dict[str, KnowledgeImport]:++def load_knowledge(+ log_item: LogItem | None, knowledge_dir: str, index: Dict[str, KnowledgeImport]+) -> Dict[str, KnowledgeImport]:knowledge_dir = files.get_abs_path(knowledge_dir)-++ from python.helpers.vector_db import Area# Mapping file extensions to corresponding loader classesfile_types_loaders = {- 'txt': TextLoader,- 'pdf': PyPDFLoader,- 'csv': CSVLoader,- 'html': UnstructuredHTMLLoader,- 'json': JSONLoader,- 'md': UnstructuredMarkdownLoader+ "txt": TextLoader,+ "pdf": PyPDFLoader,+ "csv": CSVLoader,+ "html": UnstructuredHTMLLoader,+ "json": JSONLoader,+ "md": UnstructuredMarkdownLoader,}cnt_files = 0cnt_docs = 0- # Fetch all files in the directory with specified extensions- kn_files = glob.glob(knowledge_dir + '/**/*', recursive=True)- if kn_files:- print(f"Found {len(kn_files)} knowledge files in {knowledge_dir}, processing...")- logger.log(type="info", content=f"Found {len(kn_files)} knowledge files in {knowledge_dir}, processing...")-- for file_path in kn_files:- ext = file_path.split('.')[-1].lower()- if ext in file_types_loaders:- checksum = calculate_checksum(file_path)- file_key = os.path.relpath(file_path, knowledge_dir)-- # Load existing data from the index or create a new entry- file_data = index.get(file_key, {})-- if file_data.get('checksum') == checksum:- file_data['state'] = 'original'- else:- file_data['state'] = 'changed'-- if file_data['state'] == 'changed':- file_data['checksum'] = checksum- loader_cls = file_types_loaders[ext]- loader = loader_cls(file_path, **(text_loader_kwargs if ext in ['txt', 'csv', 'html', 'md'] else {}))- file_data['documents'] = loader.load_and_split()- cnt_files += 1- cnt_docs += len(file_data['documents'])- # print(f"Imported {len(file_data['documents'])} documents from {file_path}")-- # Update the index- index[file_key] = file_data # type: ignore+ for area in Area:+ subdir = files.get_abs_path(knowledge_dir, area.value)++ if not os.path.exists(subdir):+ os.makedirs(subdir)+ continue++ # Fetch all files in the directory with specified extensions+ kn_files = glob.glob(subdir + "/**/*", recursive=True)+ if kn_files:+ print(f"Found {len(kn_files)} knowledge files in {subdir}, processing...")+ if log_item:+ log_item.stream(+ progress=f"\nFound {len(kn_files)} knowledge files in {subdir}, processing...",+ )++ for file_path in kn_files:+ ext = file_path.split(".")[-1].lower()+ if ext in file_types_loaders:+ checksum = calculate_checksum(file_path)+ file_key = file_path # os.path.relpath(file_path, knowledge_dir)++ # Load existing data from the index or create a new entry+ file_data = index.get(file_key, {})++ if file_data.get("checksum") == checksum:+ file_data["state"] = "original"+ else:+ file_data["state"] = "changed"++ if file_data["state"] == "changed":+ file_data["checksum"] = checksum+ loader_cls = file_types_loaders[ext]+ loader = loader_cls(+ file_path,+ **(+ text_loader_kwargs+ if ext in ["txt", "csv", "html", "md"]+ else {}+ ),+ )+ file_data["documents"] = loader.load_and_split()+ for doc in file_data["documents"]:+ doc.metadata["area"] = area.value+ cnt_files += 1+ cnt_docs += len(file_data["documents"])+ # print(f"Imported {len(file_data['documents'])} documents from {file_path}")++ # Update the index+ index[file_key] = file_data # type: ignore# loop index where state is not set and mark it as removedfor file_key, file_data in index.items():- if not file_data.get('state', ''):- index[file_key]['state'] = 'removed'+ if not file_data.get("state", ""):+ index[file_key]["state"] = "removed"print(f"Processed {cnt_docs} documents from {cnt_files} files.")- logger.log(type="info", content=f"Processed {cnt_docs} documents from {cnt_files} files.")+ if log_item:+ log_item.stream(+ progress=f"\nProcessed {cnt_docs} documents from {cnt_files} files."+ )return indexdiff --git a/python/helpers/log.py b/python/helpers/log.pyindex 4d1912849..1c1efe836 100644--- a/python/helpers/log.py+++ b/python/helpers/log.py@@ -5,20 +5,23 @@ import uuidtype Type = Literal[- 'agent',- 'code_exe',- 'error',- 'hint',- 'info',- 'tool',- 'user',- 'util',- 'warning',- ]+ "agent",+ "code_exe",+ "error",+ "hint",+ "info",+ "progress",+ "response",+ "tool",+ "user",+ "util",+ "warning",+]+@dataclassclass LogItem:- log: 'Log'+ log: "Log"no: inttype: strheading: str@@ -30,9 +33,35 @@ class LogItem:def __post_init__(self):self.guid = self.log.guid- def update(self, type: Type | None = None, heading: str | None = None, content: str | None = None, kvps: dict | None = None, temp: bool | None = None):+ def update(+ self,+ type: Type | None = None,+ heading: str | None = None,+ content: str | None = None,+ kvps: dict | None = None,+ temp: bool | None = None,+ **kwargs,+ ):if self.guid == self.log.guid:- self.log.update_item(self.no, type=type, heading=heading, content=content, kvps=kvps, temp=temp)+ self.log.update_item(+ self.no,+ type=type,+ heading=heading,+ content=content,+ kvps=kvps,+ temp=temp,+ **kwargs,+ )++ def stream(self, heading: str | None = None, content: str | None = None, **kwargs):+ if heading is not None:+ self.update(heading=self.heading + heading)+ if content is not None:+ self.update(content=self.content + content)++ for k, v in kwargs.items():+ prev = self.kvps.get(k, "") if self.kvps else ""+ self.update(**{k: prev + v})def output(self):return {@@ -41,34 +70,70 @@ class LogItem:"heading": self.heading,"content": self.content,"temp": self.temp,- "kvps": self.kvps+ "kvps": self.kvps,}+class Log:def __init__(self):self.guid: str = str(uuid.uuid4())self.updates: list[int] = []self.logs: list[LogItem] = []+ self.progress = ""- def log(self, type: Type, heading: str | None = None, content: str | None = None, kvps: dict | None = None, temp: bool | None = None) -> LogItem:- item = LogItem(log=self,no=len(self.logs), type=type, heading=heading or "", content=content or "", kvps=kvps, temp=temp or False)+ def log(+ self,+ type: Type,+ heading: str | None = None,+ content: str | None = None,+ kvps: dict | None = None,+ temp: bool | None = None,+ ) -> LogItem:+ item = LogItem(+ log=self,+ no=len(self.logs),+ type=type,+ heading=heading or "",+ content=content or "",+ kvps=kvps,+ temp=temp or False,+ )self.logs.append(item)self.updates += [item.no]+ if heading:+ self.progress = headingreturn item- def update_item(self, no: int, type: str | None = None, heading: str | None = None, content: str | None = None, kvps: dict | None = None, temp: bool | None = None):+ def update_item(+ self,+ no: int,+ type: str | None = None,+ heading: str | None = None,+ content: str | None = None,+ kvps: dict | None = None,+ temp: bool | None = None,+ **kwargs,+ ):item = self.logs[no]if type is not None:item.type = typeif heading is not None:item.heading = heading+ self.progress = headingif content is not None:item.content = contentif kvps is not None:item.kvps = kvpsif temp is not None:item.temp = temp++ if kwargs:+ if item.kvps is None:+ item.kvps = {}+ for k, v in kwargs.items():+ item.kvps[k] = v+self.updates += [item.no]def output(self, start=None, end=None):@@ -76,19 +141,18 @@ class Log:start = 0if end is None:end = len(self.updates)-+out = []seen = set()for update in self.updates[start:end]:if update not in seen:out.append(self.logs[update].output())seen.add(update)-- return out-+ return outdef reset(self):self.guid = str(uuid.uuid4())self.updates = []self.logs = []+ self.progress = ""diff --git a/python/helpers/tool.py b/python/helpers/tool.pyindex 112faa2f6..c89a74ad1 100644--- a/python/helpers/tool.py+++ b/python/helpers/tool.py@@ -22,8 +22,8 @@ class Tool:passasync def before_execution(self, **kwargs):- PrintStyle(font_color="#1B4F72", padding=True, background_color="white", bold=True).print(f"{self.agent.agent_name}: Using tool '{self.name}':")- self.log = self.agent.context.log.log(type="tool", heading=f"{self.agent.agent_name}: Using tool '{self.name}':", content="", kvps=self.args)+ PrintStyle(font_color="#1B4F72", padding=True, background_color="white", bold=True).print(f"{self.agent.agent_name}: Using tool '{self.name}'")+ self.log = self.agent.context.log.log(type="tool", heading=f"{self.agent.agent_name}: Using tool '{self.name}'", content="", kvps=self.args)if self.args and isinstance(self.args, dict):for key, value in self.args.items():PrintStyle(font_color="#85C1E9", bold=True).stream(self.nice_key(key)+": ")@@ -34,7 +34,7 @@ class Tool:text = messages.truncate_text(self.agent, response.message.strip(), self.agent.config.max_tool_response_length)msg_response = self.agent.read_prompt("fw.tool_response.md", tool_name=self.name, tool_response=text)await self.agent.append_message(msg_response, human=True)- PrintStyle(font_color="#1B4F72", background_color="white", padding=True, bold=True).print(f"{self.agent.agent_name}: Response from tool '{self.name}':")+ PrintStyle(font_color="#1B4F72", background_color="white", padding=True, bold=True).print(f"{self.agent.agent_name}: Response from tool '{self.name}'")PrintStyle(font_color="#85C1E9").print(response.message)self.log.update(content=response.message)diff --git a/python/helpers/vector_db.py b/python/helpers/vector_db.pyindex 33f6ad481..2456393a3 100644--- a/python/helpers/vector_db.py+++ b/python/helpers/vector_db.py@@ -1,3 +1,4 @@+from typing import Anyfrom langchain.storage import InMemoryByteStore, LocalFileStorefrom langchain.embeddings import CacheBackedEmbeddings@@ -11,21 +12,31 @@ from . import filesfrom langchain_core.documents import Documentimport uuidfrom python.helpers import knowledge_import-from python.helpers.log import Log+from python.helpers.log import Log, LogItem+import pandas as pd+from enum import Enum+++class Area(Enum):+ MAIN = "main"+ SOLUTIONS = "solutions"+index: dict[str, "VectorDB"] = {}-def get_or_create(- logger: Log,+def get_or_create_db(+ logger: Log | None,embeddings_model,+ memory_dir: str,in_memory=False,- memory_dir="./memory",- knowledge_dir=None,+ knowledge_dirs: list[str] = [],):if index.get(memory_dir) is None:+ log_item = None+ if(logger): log_item = logger.log(type="util", heading=f"Initializing VectorDB in {memory_dir}")index[memory_dir] = VectorDB(- logger, embeddings_model, in_memory, memory_dir, knowledge_dir+ log_item, embeddings_model, memory_dir, knowledge_dirs, in_memory)return index[memory_dir]@@ -34,22 +45,23 @@ class VectorDB:def __init__(self,- logger: Log,+ log_item: LogItem | None,embeddings_model,+ memory_dir: str,+ knowledge_dirs: list[str] = [],in_memory=False,- memory_dir="./memory/default",- knowledge_dir=None,):- self.logger = logger+ self.log_item = log_itemprint("Initializing VectorDB...")- self.logger.log("info", content="Initializing VectorDB...", temp=True)+ if(self.log_item): self.log_item.stream(progress="\nInitializing VectorDB")self.embeddings_model = embeddings_model- self.em_dir = files.get_abs_path("./memory/embeddings") # just caching, no need to parameterize+ self.em_dir = files.get_abs_path(+ "./memory/embeddings"+ ) # just caching, no need to parameterizeself.db_dir = files.get_abs_path("./memory", memory_dir, "database")- self.kn_dir = files.get_abs_path(knowledge_dir) if knowledge_dir else ""# make sure embeddings and database directories existos.makedirs(self.db_dir, exist_ok=True)@@ -93,10 +105,10 @@ class VectorDB:)# preload knowledge files- if self.kn_dir:- self.preload_knowledge(self.kn_dir, self.db_dir)+ if knowledge_dirs:+ self.preload_knowledge(knowledge_dirs, self.db_dir)- def preload_knowledge(self, kn_dir: str, db_dir: str):+ def preload_knowledge(self, kn_dirs: list[str], db_dir: str):# Load the index file if it existsindex_path = files.get_abs_path(db_dir, "knowledge_import.json")@@ -110,7 +122,8 @@ class VectorDB:with open(index_path, "r") as f:index = json.load(f)- index = knowledge_import.load_knowledge(self.logger, kn_dir, index)+ for kn_dir in kn_dirs:+ index = knowledge_import.load_knowledge(self.log_item, kn_dir, index)for file in index:if index[file]["state"] in ["changed", "removed"] and index[file].get(@@ -139,12 +152,16 @@ class VectorDB:def search_similarity(self, query, results=3):return self.db.similarity_search(query, results)- def search_similarity_threshold(self, query, results=3, threshold=0.5):+ def search_similarity_threshold(+ self, query: str, results=3, threshold=0.5, filter: str = ""+ ):+ comparator = VectorDB.get_comparator(filter) if filter else Nonereturn self.db.search(query,search_type="similarity_score_threshold",k=results,score_threshold=threshold,+ filter=comparator,)def search_max_rel(self, query, results=3):@@ -198,8 +215,20 @@ class VectorDB:def insert_documents(self, docs: list[Document]):ids = [str(uuid.uuid4()) for _ in range(len(docs))]- for doc, id in zip(docs, ids):- doc.metadata["id"] = id # add ids to documents metadata- self.db.add_documents(documents=docs, ids=ids)- self.db.save_local(folder_path=self.db_dir) # persist+ if ids:+ for doc, id in zip(docs, ids):+ doc.metadata["id"] = id # add ids to documents metadata+ self.db.add_documents(documents=docs, ids=ids)+ self.db.save_local(folder_path=self.db_dir) # persistreturn ids++ @staticmethod+ def get_comparator(condition: str):+ def comparator(data: dict[str, Any]):+ try:+ return eval(condition, {}, data)+ except Exception as e:+ print(f"Error evaluating condition: {e}")+ return False++ return comparatordiff --git a/python/tools/code_execution_tool.py b/python/tools/code_execution_tool.pyindex 45a6e0607..eae0a7ba6 100644--- a/python/tools/code_execution_tool.py+++ b/python/tools/code_execution_tool.py@@ -53,10 +53,10 @@ class CodeExecution(Tool):await self.agent.handle_intervention() # wait for intervention and handle it, if pausedPrintStyle(font_color="#1B4F72", padding=True, background_color="white", bold=True- ).print(f"{self.agent.agent_name}: Using tool '{self.name}':")+ ).print(f"{self.agent.agent_name}: Using tool '{self.name}'")self.log = self.agent.context.log.log(type="code_exe",- heading=f"{self.agent.agent_name}: Using tool '{self.name}':",+ heading=f"{self.agent.agent_name}: Using tool '{self.name}'",content="",kvps=self.args,)@@ -132,7 +132,7 @@ class CodeExecution(Tool):self.state.shell.send_command(command)PrintStyle(background_color="white", font_color="#1B4F72", bold=True).print(- f"{self.agent.agent_name} code execution output:"+ f"{self.agent.agent_name} code execution output")return await self.get_terminal_output()diff --git a/python/tools/knowledge_tool.py b/python/tools/knowledge_tool.pyindex ae5d36b47..b0e9029da 100644--- a/python/tools/knowledge_tool.py+++ b/python/tools/knowledge_tool.py@@ -25,9 +25,7 @@ class Knowledge(Tool):duckduckgo = executor.submit(duckduckgo_search.search, question)# manual memory search- future_memory_man = executor.submit(memory_tool.search, self.agent, "manual", question)- # history memory search- # future_memory_man = executor.submit(memory_tool.search, self.agent, "history", question)+ future_memory_man = executor.submit(memory_tool.search, self.agent, question)# Wait for both functions to completetry:diff --git a/python/tools/memory_tool.py b/python/tools/memory_tool.pyindex ffa9c1200..11cfdf005 100644--- a/python/tools/memory_tool.py+++ b/python/tools/memory_tool.py@@ -1,14 +1,11 @@import re-from typing import Literalfrom agent import Agent-from python.helpers.vector_db import get_or_create+from python.helpers.vector_db import get_or_create_dbimport osfrom python.helpers.tool import Tool, Responsefrom python.helpers.print_style import PrintStylefrom python.helpers.errors import handle_error---type Area = Literal['manual', 'history']+from python.helpers import filesclass Memory(Tool):async def execute(self,**kwargs):@@ -20,13 +17,13 @@ class Memory(Tool):if "query" in kwargs:threshold = float(kwargs.get("threshold", 0.1))count = int(kwargs.get("count", 5))- result = search(self.agent, area, kwargs["query"], count, threshold)+ result = search(self.agent, kwargs["query"], count, threshold)elif "memorize" in kwargs:- result = save(self.agent, area, kwargs["memorize"])+ result = save(self.agent, kwargs["memorize"])elif "forget" in kwargs:- result = forget(self.agent, area, kwargs["forget"])+ result = forget(self.agent, kwargs["forget"])# elif "delete" in kwargs- result = delete(self.agent, area, kwargs["delete"])+ result = delete(self.agent, kwargs["delete"])except Exception as e:handle_error(e)# hint about embedding change with existing database@@ -37,39 +34,39 @@ class Memory(Tool):# result = process_query(self.agent, self.args["memory"],self.args["action"], result_count=self.agent.config.auto_memory_count)return Response(message=result, break_loop=False)-def search(agent:Agent, area: Area, query:str, count:int=5, threshold:float=0.1):- db = get_db(agent, area)+def search(agent:Agent, query:str, count:int=5, threshold:float=0.1):+ db = get_db(agent)# docs = db.search_similarity(query,count) # type: ignoredocs = db.search_similarity_threshold(query,count,threshold) # type: ignoreif len(docs)==0: return agent.read_prompt("fw.memories_not_found.md", query=query)else: return str(docs)-def save(agent:Agent, area: Area, text:str):- db = get_db(agent, area)+def save(agent:Agent, text:str):+ db = get_db(agent)id = db.insert_text(text) # type: ignorereturn agent.read_prompt("fw.memory_saved.md", memory_id=id)-def delete(agent:Agent, area: Area, ids_str:str):- db = get_db(agent, area)+def delete(agent:Agent, ids_str:str):+ db = get_db(agent)ids = extract_guids(ids_str)deleted = db.delete_documents_by_ids(ids) # type: ignorereturn agent.read_prompt("fw.memories_deleted.md", memory_count=deleted)-def forget(agent:Agent, area: Area, query:str):- db = get_db(agent, area)+def forget(agent:Agent, query:str):+ db = get_db(agent)deleted = db.delete_documents_by_query(query) # type: ignorereturn agent.read_prompt("fw.memories_deleted.md", memory_count=deleted)-def get_db(agent: Agent, area: Area):- mem_dir = os.path.join("memory", agent.config.memory_subdir or "default", area)- kn_dir = os.path.join("knowledge", agent.config.knowledge_subdir)+def get_db(agent: Agent):+ mem_dir = files.get_abs_path("memory", agent.config.memory_subdir or "default")+ kn_dirs = [files.get_abs_path("knowledge", d) for d in agent.config.knowledge_subdirs or []]- db = get_or_create(+ db = get_or_create_db(agent.context.log,embeddings_model=agent.config.embeddings_model,in_memory=False,memory_dir=mem_dir,- knowledge_dir=kn_dir)+ knowledge_dirs=kn_dirs)return dbdiff --git a/python/tools/response.py b/python/tools/response.pyindex 52ece8b5f..194fd9171 100644--- a/python/tools/response.py+++ b/python/tools/response.py@@ -7,7 +7,7 @@ class ResponseTool(Tool):return Response(message=self.args["text"], break_loop=True)async def before_execution(self, **kwargs):- self.log = self.agent.context.log.log(type="response", heading=f"{self.agent.agent_name}: Responding:", content=self.args.get("text", ""))+ self.log = self.agent.context.log.log(type="response", heading=f"{self.agent.agent_name}: Responding", content=self.args.get("text", ""))async def after_execution(self, response, **kwargs):diff --git a/python/tools/task_done.py b/python/tools/task_done.pyindex 0acf00e70..46c698166 100644--- a/python/tools/task_done.py+++ b/python/tools/task_done.py@@ -7,7 +7,7 @@ class TaskDone(Tool):return Response(message=self.args["text"], break_loop=True)async def before_execution(self, **kwargs):- self.log = self.agent.context.log.log(type="response", heading=f"{self.agent.agent_name}: Task done:", content=self.args.get("text", ""))+ self.log = self.agent.context.log.log(type="response", heading=f"{self.agent.agent_name}: Task done", content=self.args.get("text", ""))async def after_execution(self, response, **kwargs):pass # do add anything to the history or output\ No newline at end of filediff --git a/requirements.txt b/requirements.txtindex aeec28617..b32c05443 100644--- a/requirements.txt+++ b/requirements.txt@@ -7,10 +7,12 @@ langchain-openai==0.1.15langchain-community==0.2.7langchain-anthropic==0.1.19langchain-google-genai==1.0.7+Markdown==3.7langchain_mistralai==0.1.8webcolors==24.6.0sentence-transformers==3.0.1docker==7.1.0+pandas==2.2.3paramiko==3.4.0duckduckgo_search==6.1.12inputimeout==1.0.4@@ -19,6 +21,8 @@ beautifulsoup4==4.12.3lxml_html_clean==0.2.0pynput==1.7.7pypdf==4.3.1+unstructured==0.15.13+unstructured-client==0.25.9Flask[async]==3.0.3Flask-BasicAuth==0.2.0faiss-cpu==1.8.0.post1\ No newline at end of filediff --git a/run_ui.py b/run_ui.pyindex 6dd6310af..376878acd 100644--- a/run_ui.py+++ b/run_ui.py@@ -13,93 +13,116 @@ from python.helpers.print_style import PrintStylefrom python.helpers.log import Logfrom dotenv import load_dotenv+load_dotenv()-#initialize the internal Flask server-app = Flask("app",static_folder=get_abs_path("./webui"),static_url_path="/")+# initialize the internal Flask server+app = Flask("app", static_folder=get_abs_path("./webui"), static_url_path="/")lock = threading.Lock()# Set up basic authentication, name and password from .env variables-app.config['BASIC_AUTH_USERNAME'] = os.environ.get('BASIC_AUTH_USERNAME') or "admin" #default name-app.config['BASIC_AUTH_PASSWORD'] = os.environ.get('BASIC_AUTH_PASSWORD') or "admin" #default pass+app.config["BASIC_AUTH_USERNAME"] = (+ os.environ.get("BASIC_AUTH_USERNAME") or "admin"+) # default name+app.config["BASIC_AUTH_PASSWORD"] = (+ os.environ.get("BASIC_AUTH_PASSWORD") or "admin"+) # default passbasic_auth = BasicAuth(app)+# get context to run agent zero in-def get_context(ctxid:str):+def get_context(ctxid: str):with lock:- if not ctxid:- first = AgentContext.first()- if first: return first+ if not ctxid:+ first = AgentContext.first()+ if first:+ return firstreturn AgentContext(config=initialize())got = AgentContext.get(ctxid)- if got: return got- return AgentContext(config=initialize(),id=ctxid)+ if got:+ return got+ return AgentContext(config=initialize(), id=ctxid)+# Now you can use @requires_auth function decorator to require login on certain pagesdef requires_auth(f):@wraps(f)async def decorated(*args, **kwargs):auth = request.authorization- if not auth or not (auth.username == app.config['BASIC_AUTH_USERNAME'] and auth.password == app.config['BASIC_AUTH_PASSWORD']):+ if not auth or not (+ auth.username == app.config["BASIC_AUTH_USERNAME"]+ and auth.password == app.config["BASIC_AUTH_PASSWORD"]+ ):return Response(- 'Could not verify your access level for that URL.\n'- 'You have to login with proper credentials', 401,- {'WWW-Authenticate': 'Basic realm="Login Required"'})+ "Could not verify your access level for that URL.\n"+ "You have to login with proper credentials",+ 401,+ {"WWW-Authenticate": 'Basic realm="Login Required"'},+ )return await f(*args, **kwargs)+return decorated+# handle default address, show demo html page from ./test_form.html[email protected]('/', methods=['GET'])[email protected]("/", methods=["GET"])async def test_form():return Path(get_abs_path("./webui/index.html")).read_text()+# simple health check, just return OK to see the server is running[email protected]('/ok', methods=['GET','POST'])[email protected]("/ok", methods=["GET", "POST"])async def health_check():return "OK"+# # secret page, requires authentication# @app.route('/secret', methods=['GET'])# @requires_auth# async def secret_page():# return Path("./secret_page.html").read_text()+# send message to agent (async UI)[email protected]('/msg', methods=['POST'])[email protected]("/msg", methods=["POST"])async def handle_message_async():return await handle_message(False)+# send message to agent (synchronous API)[email protected]('/msg_sync', methods=['POST'])[email protected]("/msg_sync", methods=["POST"])async def handle_msg_sync():return await handle_message(True)-async def handle_message(sync:bool):++async def handle_message(sync: bool):try:-- #data sent to the server++ # data sent to the serverinput = request.get_json()text = input.get("text", "")ctxid = input.get("context", "")blev = input.get("broadcast", 1)- #context instance - get or create+ # context instance - get or createcontext = get_context(ctxid)# print to console and log- PrintStyle(background_color="#6C3483", font_color="white", bold=True, padding=True).print(f"User message:")+ PrintStyle(+ background_color="#6C3483", font_color="white", bold=True, padding=True+ ).print(f"User message:")PrintStyle(font_color="white", padding=False).print(f"> {text}")context.log.log(type="user", heading="User message", content=text)if sync:context.communicate(text)- result = await context.process.result() #type: ignore+ result = await context.process.result() # type: ignoreresponse = {"ok": True,"message": result,- }+ }else:- print("\n\n",(context.process and context.process.is_alive()))+ print("\n\n", (context.process and context.process.is_alive()))context.communicate(text)response = {"ok": True,@@ -111,21 +134,23 @@ async def handle_message(sync:bool):"ok": False,"message": str(e),}+ PrintStyle.error(str(e))- #respond with json+ # respond with jsonreturn jsonify(response)-++# pausing/unpausing the agent[email protected]('/pause', methods=['POST'])[email protected]("/pause", methods=["POST"])async def pause():try:-- #data sent to the server++ # data sent to the serverinput = request.get_json()paused = input.get("paused", False)ctxid = input.get("context", "")- #context instance - get or create+ # context instance - get or createcontext = get_context(ctxid)context.paused = paused@@ -133,100 +158,107 @@ async def pause():response = {"ok": True,"message": "Agent paused." if paused else "Agent unpaused.",- "pause": paused- }-+ "pause": paused,+ }+except Exception as e:response = {"ok": False,"message": str(e),}+ PrintStyle.error(str(e))- #respond with json+ # respond with jsonreturn jsonify(response)+# restarting with new agent0[email protected]('/reset', methods=['POST'])[email protected]("/reset", methods=["POST"])async def reset():try:- #data sent to the server+ # data sent to the serverinput = request.get_json()ctxid = input.get("context", "")- #context instance - get or create+ # context instance - get or createcontext = get_context(ctxid)context.reset()-+response = {"ok": True,"message": "Agent restarted.",- }-+ }+except Exception as e:response = {"ok": False,"message": str(e),}+ PrintStyle.error(str(e))- #respond with json+ # respond with jsonreturn jsonify(response)+# killing context[email protected]('/remove', methods=['POST'])[email protected]("/remove", methods=["POST"])async def remove():try:- #data sent to the server+ # data sent to the serverinput = request.get_json()ctxid = input.get("context", "")- #context instance - get or create+ # context instance - get or createAgentContext.remove(ctxid)-+response = {"ok": True,"message": "Context removed.",- }-+ }+except Exception as e:response = {"ok": False,"message": str(e),}+ PrintStyle.error(str(e))- #respond with json+ # respond with jsonreturn jsonify(response)+# Web UI polling[email protected]('/poll', methods=['POST'])[email protected]("/poll", methods=["POST"])async def poll():try:-- #data sent to the server++ # data sent to the serverinput = request.get_json()ctxid = input.get("context", uuid.uuid4())from_no = input.get("log_from", 0)- #context instance - get or create+ # context instance - get or createcontext = get_context(ctxid)-logs = context.log.output(start=from_no)# loop AgentContext._contextsctxs = []for ctx in AgentContext._contexts.values():- ctxs.append({- "id": ctx.id,- "no": ctx.no,- "log_guid": ctx.log.guid,- "log_version": len(ctx.log.updates),- "log_length": len(ctx.log.logs),- "paused": ctx.paused- })-- #data from this server+ ctxs.append(+ {+ "id": ctx.id,+ "no": ctx.no,+ "log_guid": ctx.log.guid,+ "log_version": len(ctx.log.updates),+ "log_length": len(ctx.log.logs),+ "paused": ctx.paused,+ }+ )++ # data from this serverresponse = {"ok": True,"context": context.id,@@ -234,7 +266,8 @@ async def poll():"logs": logs,"log_guid": context.log.guid,"log_version": len(context.log.updates),- "paused": context.paused+ "log_progress": context.log.progress,+ "paused": context.paused,}except Exception as e:@@ -242,23 +275,22 @@ async def poll():"ok": False,"message": str(e),}+ PrintStyle.error(str(e))- #respond with json+ # respond with jsonreturn jsonify(response)--#run the internal server+# run the internal serverif __name__ == "__main__":- load_dotenv()-# Suppress only request logs but keep the startup messagesfrom werkzeug.serving import WSGIRequestHandler+class NoRequestLoggingWSGIRequestHandler(WSGIRequestHandler):- def log_request(self, code='-', size='-'):+ def log_request(self, code="-", size="-"):pass # Override to suppress request logging# run the server on port from .envport = int(os.environ.get("WEB_UI_PORT", 0)) or None- app.run(request_handler=NoRequestLoggingWSGIRequestHandler,port=port)+ app.run(request_handler=NoRequestLoggingWSGIRequestHandler, port=port)diff --git a/test.py b/test.pydeleted file mode 100644index 3b1b5133a..000000000--- a/test.py+++ /dev/null@@ -1,293 +0,0 @@-from playwright.async_api import async_playwright, TimeoutError as PlaywrightTimeoutError-from python.helpers.print_style import PrintStyle-import asyncio-import random-import re--# List of user agents-user_agents = [- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15',- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0',- 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36',- 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Mobile/15E148 Safari/604.1',- 'Mozilla/5.0 (iPad; CPU OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/91.0.4472.80 Mobile/15E148 Safari/604.1',- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.59',- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36'-]--async def scrape_page(url, headless=True):- try:- async with async_playwright() as p:- browser = await p.chromium.launch(headless=headless)- context = await browser.new_context(- user_agent=random.choice(user_agents)- )- page = await context.new_page()- page.set_default_timeout(30000)-- await page.goto(url, wait_until='domcontentloaded', timeout=30000)- await page.wait_for_selector('body', timeout=5000)-- result = await page.evaluate(r'''() => {- const cleanText = (text) => {- return text- .replace(/class="[^"]*"/g, '')- .replace(/id="[^"]*"/g, '')- .replace(/<[^>]+>/g, '')- .replace(/\s+/g, ' ')- .trim();- };- const getMetaContent = (name) => {- const meta = document.querySelector(`meta[name="${name}"], meta[property="${name}"]`);- return meta ? cleanText(meta.content) : null;- };- const getMainContent = () => {- const contentSelectors = [- 'main', '#content', '#main-content', '.content',- '.post-content', '.entry-content', '.article-content',- '#mw-content-text', '.mw-parser-output'- ];- for (const selector of contentSelectors) {- const element = document.querySelector(selector);- if (element) {- return cleanText(element.innerText);- }- }- return cleanText(document.body.innerText);- };- const getProducts = () => {- const productSelectors = [- '.s-result-item', '.product-item', '[data-component-type="s-search-result"]', '.sg-col-inner'- ];- for (const selector of productSelectors) {- const elements = document.querySelectorAll(selector);- if (elements.length > 0) {- return Array.from(elements).slice(0, 10).map(product => {- const titleElement = product.querySelector('h2 a, .a-link-normal.a-text-normal');- const priceElement = product.querySelector('.a-price .a-offscreen, .a-price');- const imageElement = product.querySelector('img.s-image');- let price = priceElement ? cleanText(priceElement.textContent) : null;- // Remove duplicate price- price = price ? price.replace(/(\$\d+(?:\.\d{2}?))\1+/, '$1') : null;- return {- title: titleElement ? cleanText(titleElement.textContent) : null,- link: titleElement ? titleElement.href : null,- price: price,- image: imageElement ? imageElement.src : null- };- }).filter(product => product.title && product.link);- }- }- return [];- };- const getNavigation = () => {- const navSelectors = ['nav', 'header', '[data-cy="header-nav"]'];- for (const selector of navSelectors) {- const navElement = document.querySelector(selector);- if (navElement) {- return Array.from(navElement.querySelectorAll('a'))- .filter(link => !link.href.endsWith('.svg'))- .slice(0, 10) // Limit to 10 items- .map(link => ({- href: link.href,- text: cleanText(link.textContent)- }));- }- }- return [];- };- const getImages = () => {- return Array.from(document.querySelectorAll('img'))- .filter(img => !img.src.endsWith('.svg'))- .map(img => ({- src: img.src,- alt: img.alt,- }));- };- const getLists = () => {- const listSelectors = [- '.mw-parser-output > ul', '.mw-parser-output > ol',- '[data-cy="main-content"] ul', '[data-cy="main-content"] ol',- 'main ul', 'main ol',- '.content ul', '.content ol',- '#content ul', '#content ol'- ];- let lists = [];- for (const selector of listSelectors) {- const elements = document.querySelectorAll(selector);- if (elements.length > 0) {- lists = Array.from(elements)- .filter(list => list.children.length >= 3 && list.children.length <= 20)- .map(list => ({- type: list.tagName.toLowerCase(),- items: Array.from(list.children)- .filter(li => li.textContent.trim().length > 10)- .map(li => {- // Remove CSS classes, IDs, and inline styles- let text = li.textContent.replace(/\s+/g, ' ').trim();- // Remove any remaining HTML tags- text = text.replace(/<[^>]+>/g, '');- // Remove CSS-related content- text = text.replace(/\.mw-parser-output[^{]+\{[^}]+\}/g, '');- // Remove ISBN prefix if present- text = text.replace(/^ISBN\s+/, '');- return text;- })- .filter(text => text.length > 0 && !text.includes('mw-parser-output'))- .slice(0, 10)- }))- .filter(list => list.items.length >= 3)- .slice(0, 3);- if (lists.length > 0) break;- }- }- return lists;- };- const getSocialMediaLinks = () => {- const socialSelectors = [- 'a[href*="facebook.com"]',- 'a[href*="twitter.com"]',- 'a[href*="x.com"]',- 'a[href*="github.com"]',- 'a[href*="reddit.com"]',- 'a[href*="tiktok.com"]',- 'a[href*="discord.com"]',- 'a[href*="instagram.com"]',- 'a[href*="linkedin.com"]',- 'a[href*="youtube.com"]',- 'a[href*="pinterest.com"]',- 'a[href*="snapchat.com"]',- 'a[href*="tumblr.com"]',- 'a[href*="medium.com"]',- 'a[href*="whatsapp.com"]',- 'a[href*="telegram.org"]',- 'a[href*="vimeo.com"]',- 'a[href*="flickr.com"]',- 'a[href*="quora.com"]',- 'a[href*="twitch.tv"]'- ];- return socialSelectors.map(selector => {- const element = document.querySelector(selector);- return element ? element.href : null;- }).filter(Boolean);- };- const getCodeScripts = () => {- const codeBlocks = document.querySelectorAll('pre code, .highlight pre, .code-block');- return Array.from(codeBlocks).map(block => ({- language: block.className.match(/language-(\w+)/)?.[1] || 'text',- code: cleanText(block.textContent)- })).filter(script => script.code.length > 0);- };- return {- url: window.location.href,- title: document.title,- author: getMetaContent('author'),- publishDate: getMetaContent('article:published_time') || getMetaContent('date'),- lastModified: document.lastModified,- keywords: getMetaContent('keywords'),- metaDescription: getMetaContent('description') || getMetaContent('og:description'),- mainContent: getMainContent(),- navigation: getNavigation(),- images: getImages(),- lists: getLists(),- products: getProducts(),- socialMediaLinks: getSocialMediaLinks(),- codeScripts: getCodeScripts(),- };- }''')-- await browser.close()- return result- except PlaywrightTimeoutError as e:- PrintStyle(font_color="yellow", padding=True).print(f"Attempt {attempt + 1} failed due to timeout: {str(e)}")- except Exception as e:- PrintStyle(font_color="red", padding=True).print(f"Attempt {attempt + 1} failed: {str(e)}")---async def scrape_url(url, headless):- try:- result = await scrape_page(url, headless)-- if result is None:- raise ValueError("Scraping result is None")-- markdown_content = f"# {result.get('title', 'No Title')}\n\n"-- if result.get('url'):- markdown_content += f"URL: {result['url']}\n\n"-- if result.get('author'):- markdown_content += f"Author: {result['author']}\n\n"-- if result.get('publishDate'):- markdown_content += f"Published: {result['publishDate']}\n\n"-- if result.get('keywords'):- markdown_content += f"Keywords: {result['keywords']}\n\n"-- if result.get('metaDescription'):- markdown_content += f"## Description\n\n{result['metaDescription']}\n\n"-- if result.get('mainContent'):- markdown_content += "## Webpage Content:\n\n"- markdown_content += result['mainContent'] + "\n\n"-- if result.get('lists'):- markdown_content += "## Lists\n\n"- for list_item in result['lists']:- markdown_content += f"### {list_item['type'].upper()} List\n\n"- for item in list_item['items']:- markdown_content += f"- {item}\n"- markdown_content += "\n"-- if result.get('products'):- markdown_content += "## Products\n\n"- for product in result['products']:- markdown_content += f"### {product.get('title', 'Untitled Product')}\n\n"- if product.get('price'):- price = product['price']- price = re.sub(r'(\$\d+(?:\.\d{2})?)\1+', r'\1', price)- markdown_content += f"Price: {price}\n\n"- if product.get('link'):- markdown_content += f"[View Product]({product['link']})\n\n"- if product.get('image'):- markdown_content += f"\n\n"- markdown_content += "---\n\n"-- if result.get('socialMediaLinks'):- markdown_content += "## Social Media Links\n\n"- for link in result['socialMediaLinks']:- markdown_content += f"- [{link.split('.com')[0].split('/')[-1].capitalize()}]({link})\n"- markdown_content += "\n"-- if result.get('codeScripts'):- markdown_content += "## Code Snippet\n\n"- for script in result['codeScripts']:- markdown_content += f"```{script['language']}\n{script['code']}\n```\n\n"-- markdown_content = markdown_content.strip()-- return markdown_content- except Exception as e:- return f"Error: Failed to scrape URL. Reason: {str(e)}"--async def fetch_page_content(url: str, max_retries: int = 2, headless: bool = True):- for attempt in range(max_retries):- try:- content = await scrape_url(url, headless)- if content.startswith("Error:"):- raise Exception(content)- return str(content)- except Exception as e:- PrintStyle(font_color="red", padding=True).print(f"Attempt {attempt + 1} failed: {str(e)}")-- raise Exception("Error: Webpage content is not available.")---async def test():- url = "https://github.com/frdel/agent-zero"- content = await fetch_page_content(url)- print(content)--asyncio.run(test())\ No newline at end of filediff --git a/test2.py b/test2.pydeleted file mode 100644index f32a057dd..000000000--- a/test2.py+++ /dev/null@@ -1,120 +0,0 @@-import requests-from bs4 import BeautifulSoup-import random-import re--# List of user agents-user_agents = [- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Safari/605.1.15',- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0',- 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36',- 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Mobile/15E148 Safari/604.1',- 'Mozilla/5.0 (iPad; CPU OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/91.0.4472.80 Mobile/15E148 Safari/604.1',- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.59',- 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36'-]--def clean_text(text):- """Utility function to clean HTML tags and whitespace."""- text = re.sub(r'class="[^"]*"', '', text)- text = re.sub(r'id="[^"]*"', '', text)- text = re.sub(r'<[^>]+>', '', text)- return re.sub(r'\s+', ' ', text).strip()--def scrape_page(url):- headers = {- 'User-Agent': random.choice(user_agents)- }-- try:- response = requests.get(url, headers=headers, timeout=30)- response.raise_for_status() # Check if the request was successful- soup = BeautifulSoup(response.content, 'html.parser')-- # Extract title- title = soup.title.string if soup.title else 'No Title'-- # Extract meta information- def get_meta_content(name):- meta = soup.find('meta', attrs={'name': name}) or soup.find('meta', property=name)- return meta['content'] if meta else None-- author = get_meta_content('author')- publish_date = get_meta_content('article:published_time') or get_meta_content('date')- keywords = get_meta_content('keywords')- description = get_meta_content('description') or get_meta_content('og:description')-- # Extract main content- def get_main_content():- content_selectors = ['main', '#content', '#main-content', '.content', '.post-content', '.entry-content', '.article-content', '#mw-content-text', '.mw-parser-output']- for selector in content_selectors:- element = soup.select_one(selector)- if element:- return clean_text(element.get_text())- return clean_text(soup.body.get_text() if soup.body else "")-- # Extract images- def get_images():- images = []- for img in soup.find_all('img'):- if not img.get('src', '').endswith('.svg'):- images.append({- 'src': img['src'],- 'alt': img.get('alt', '')- })- return images-- # Extract product listings- def get_products():- products = []- product_selectors = ['.s-result-item', '.product-item', '[data-component-type="s-search-result"]', '.sg-col-inner']- for selector in product_selectors:- elements = soup.select(selector)- if elements:- for product in elements[:10]:- title_element = product.select_one('h2 a, .a-link-normal.a-text-normal')- price_element = product.select_one('.a-price .a-offscreen, .a-price')- image_element = product.select_one('img.s-image')- price = clean_text(price_element.text) if price_element else None- price = re.sub(r'(\$\d+(?:\.\d{2})?)\1+', r'\1', price) if price else None- products.append({- 'title': clean_text(title_element.text) if title_element else None,- 'link': title_element['href'] if title_element else None,- 'price': price,- 'image': image_element['src'] if image_element else None- })- return products-- # Extract lists- def get_lists():- lists = []- list_selectors = ['.mw-parser-output > ul', '.mw-parser-output > ol', 'main ul', 'main ol', '.content ul', '.content ol']- for selector in list_selectors:- elements = soup.select(selector)- for element in elements:- list_items = [clean_text(li.get_text()) for li in element.find_all('li') if len(li.get_text().strip()) > 10]- if 3 <= len(list_items) <= 20:- lists.append({'type': element.name, 'items': list_items[:10]})- return lists-- # Gather all extracted data- return {- 'url': url,- 'title': title,- 'author': author,- 'publishDate': publish_date,- 'keywords': keywords,- 'metaDescription': description,- 'mainContent': get_main_content(),- 'images': get_images(),- 'products': get_products(),- 'lists': get_lists()- }-- except requests.exceptions.RequestException as e:- return {"error": str(e)}--# Example usage:-result = scrape_page('https://github.com/frdel/agent-zero')-print(result)diff --git a/webui/index.css b/webui/index.cssindex 5040883ea..531f51da8 100644--- a/webui/index.css+++ b/webui/index.css@@ -175,7 +175,8 @@ h3 {margin-top: var(--spacing-lg);}h4 {- margin-top: 0.625rem;+ margin-top: auto;+ margin-bottom: auto;}#a0version {@@ -239,12 +240,44 @@ h4 {#logo-container img {border-radius: var(--spacing-xs);- height: auto;- width: 3rem;+ width: auto;+ height: 3rem;filter: none;transition: filter 0.3s ease;}+#progress-bar-box{+ background-color: var(--color-panel);+ /* padding-left: 1em;+ padding-right: 1em;+ padding-top: 0.5em;+ padding-bottom: 0; */+ padding: var(--spacing-sm) var(--spacing-md);+ padding-bottom: 0;+}++#progress-bar-h {+ color: var(--color-primary);+ display: flex;+ align-items: left;+ justify-content: flex-start;+ height: 1.2em;+ text-wrap: ellipsis;+ overflow: hidden;+ font-weight: normal;+}++#progress-bar-i {+ font-weight: bold;+ padding-right: 0.5em;+ color: var(--color-secondary)+}++.progress-bar h4{+ margin-left: 1em;+ margin-right: 1.2em;+}+#right-panel.expanded #logo-container {margin-left: 5.5rem;}@@ -271,6 +304,11 @@ h4 {align-self: flex-start;}+.center-container {+ align-self: center;+ max-width: 80%;+}+.message-user {background-color: #4a4a4a;border-bottom-right-radius: var(--spacing-xs);@@ -281,10 +319,28 @@ h4 {}/* Message Types */-.message-fw {+/* .message-fw {border-radius: var(--border-radius);border-top-left-radius: var(--spacing-xs);margin-left: var(--spacing-lg);+} */++.message-center{+ align-self: center;+ border-bottom-left-radius: unset;+}++.message-followup{+ margin-left: 2em;+ margin-bottom: 2em;+}+.message-followup .message{+ border-radius: 1.125em; /* 18px */+ border-top-left-radius: 0.3125em; /* 5px */+}++.message-followup + .message-followup {+ margin-bottom: 0;}/* Update message types for dark mode */@@ -294,8 +350,8 @@ h4 {.message-agent-delegation { background-color: #00695C; color: #E0E0E0; }.message-tool { background-color: #5D4C6A; color: #E0E0E0; }.message-code-exe { background-color: #3a147c; color: #E0E0E0; }-.message-adhoc { background-color: #cf7b0e; color: #E0E0E0; }.message-info { background-color: var(--color-panel); color: #E0E0E0; }+.message-util { background-color: #23211a; color: #E0E0E0; display:none }.message-warning { background-color: #c2771b; color: #E0E0E0; }.message-error { background-color: #ab1313; color: #E0E0E0; }@@ -306,22 +362,23 @@ h4 {margin-bottom: var(--spacing-xs);opacity: 0.7;}--.ai-info {+.msg-kvps {+ font-size: 0.9em;+ margin-bottom: 0.625em; /* 10px */border-collapse: collapse;font-size: 0.9em;margin-bottom: var(--spacing-sm);width: 100%;}-.ai-info th,-.ai-info td {+.msg-kvps th,+.msg-kvps td {border-bottom: 1px solid rgba(255, 255, 255, 0.1);padding: 0.25rem;text-align: left;}-.ai-info th {+.msg-kvps th {color: var(--color-primary);width: 40%;}@@ -564,8 +621,8 @@ input:checked + .slider:before {.light-mode .message-agent-delegation { background-color: #E0F2F1; color: #00695C; }.light-mode .message-tool { background-color: #EDE7F6; color: #5D4C6A; }.light-mode .message-code-exe { background-color: #FCE4EC; color: #3a147c; }-.light-mode .message-adhoc { background-color: #FFF3E0; color: #cf7b0e; }.light-mode .message-info { background-color: #E8EAF6; color: #2C3E50; }+.light-mode .message-util { background-color: #e8eaf6d6; color: #353c43; }.light-mode .message-warning { background-color: #FFF3E0; color: #c2771b; }.light-mode .message-error { background-color: #FFEBEE; color: #ab1313; }.light-mode .message-user {@@ -663,14 +720,21 @@ input:checked + .slider:before {}.msg-thoughts{- display: auto;+ display: auto;+}++.message-util .msg-kvps{+}++.message-util .msg-content{+}.message-temp {display: none;}-.message-temp:last-child {+.message-temp:not([style*="display: none"]):last-of-type {display: block; /* or any style you want for visibility */}diff --git a/webui/index.html b/webui/index.htmlindex 4c59ab9c2..09b7a118f 100644--- a/webui/index.html+++ b/webui/index.html@@ -6,6 +6,7 @@<meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Agent Zero</title><link rel="stylesheet" href="index.css">+ <link rel="stylesheet" href="toast.css"><script>window.safeCall = function (name, ...args) {@@ -23,42 +24,44 @@<!--Sidebar--><button id="toggle-sidebar" class="toggle-sidebar-button" aria-label="Toggle Sidebar" aria-expanded="false"><span aria-hidden="true">- <svg id="sidebar-hamburger-svg" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="CurrentColor">- <path d="M3 13h2v-2H3v2zm0 4h2v-2H3v2zm0-8h2V7H3v2zm4 4h14v-2H7v2zm0 4h14v-2H7v2zM7 7v2h14V7H7z"/>- </svg>+ <svg id="sidebar-hamburger-svg" xmlns="http://www.w3.org/2000/svg" width="24" height="24"+ viewBox="0 0 24 24" fill="CurrentColor">+ <path+ d="M3 13h2v-2H3v2zm0 4h2v-2H3v2zm0-8h2V7H3v2zm4 4h14v-2H7v2zm0 4h14v-2H7v2zM7 7v2h14V7H7z" />+ </svg></span>- </button>+ </button></div><div id="left-panel" class="panel"><div class="left-panel-top">- <!--Sidebar upper elements-->- <div class="config-section" id="status-section" x-data="{ connected: true }">- <h3>Status</h3>- <h4 class="connected" x-show="connected">✔ Connected</h4>- <h4 class="disconnected" x-show="!connected">✘ Disconnected</h4>- </div>+ <!--Sidebar upper elements-->+ <div class="config-section" id="status-section" x-data="{ connected: true }">+ <h3>Status</h3>+ <h4 class="connected" x-show="connected">✔ Connected</h4>+ <h4 class="disconnected" x-show="!connected">✘ Disconnected</h4>+ </div>- <div class="config-section" x-data="{ showQuickActions: true }">- <h3>Quick Actions</h3>- <button class="config-button" id="resetChat" @click="resetChat()">Reset chat</button>- <button class="config-button" id="newChat" @click="newChat()">New Chat</button>- </div>+ <div class="config-section" x-data="{ showQuickActions: true }">+ <h3>Quick Actions</h3>+ <button class="config-button" id="resetChat" @click="resetChat()">Reset chat</button>+ <button class="config-button" id="newChat" @click="newChat()">New Chat</button>+ </div>- <div class="config-section" id="chats-section" x-data="{ contexts: [], selected: '' }" x-show="contexts.length > 0">- <h3>Chats</h3>- <ul class="config-list">- <template x-for="context in contexts">- <li>- <span- :class="{'chat-list-button': true, 'font-bold': context.id === selected}"- @click="selected = context.id; selectChat(context.id)">- Chat #<span x-text="context.no"></span>- </span>- <button class="edit-button" @click="killChat(context.id)">X</button>- </li>- </template>- </ul>- </div>+ <div class="config-section" id="chats-section" x-data="{ contexts: [], selected: '' }"+ x-show="contexts.length > 0">+ <h3>Chats</h3>+ <ul class="config-list">+ <template x-for="context in contexts">+ <li>+ <span :class="{'chat-list-button': true, 'font-bold': context.id === selected}"+ @click="selected = context.id; selectChat(context.id)">+ Chat #<span x-text="context.no"></span>+ </span>+ <button class="edit-button" @click="killChat(context.id)">X</button>+ </li>+ </template>+ </ul>+ </div></div><!--Preferences--><div class="pref-section">@@ -89,47 +92,67 @@<span class="slider"></span></label></li>- <li x-data="{ darkMode: localStorage.getItem('darkMode') === 'true' }" x-init="$watch('darkMode', val => toggleDarkMode(val))">- <div class="switch-label">Light/Dark mode</div>+ <li x-data="{ darkMode: localStorage.getItem('darkMode') != 'false' }"+ x-init="$watch('darkMode', val => toggleDarkMode(val))">+ <div class="switch-label">Dark mode</div><label class="switch">- <input type="checkbox" x-model="darkMode">- <span class="slider"></span>+ <input type="checkbox" x-model="darkMode">+ <span class="slider"></span>+ </label>+ </li>+ <li x-data="{ showUtils: false }">+ <span>Show utility messages</span>+ <label class="switch">+ <input type="checkbox" x-model="showUtils"+ x-effect="window.safeCall('toggleUtils',showUtils)">+ <span class="slider"></span></label>- </li>+ </li>+</ul>- <span id="a0version">Agent Zero 0.6.5<br>built on 9/13/2024</span>- </div>+ <span id="a0version">Agent Zero 0.7<br>built on 2024-09-25</span></div>+ </div><div id="right-panel" class="panel"><div id="logo-container"><a href="https://github.com/frdel/agent-zero" target="_blank" rel="noopener noreferrer"><img src="splash.jpg" alt="a0" width="48" height="48"></a>- <div id="time-date"></div>- </div>+ <div id="time-date"></div>+ </div><!--Chat--><div id="chat-history"></div>+ <div id="progress-bar-box">+ <h4 id="progress-bar-h"><span id="progress-bar-i">|></span><span id="progress-bar"></span></h4>+ </div>+ <div id="toast" class="toast">+ <div class="toast__message"></div>+ <button class="toast__copy">Copy</button>+ <button class="toast__close">Close</button>+ </div><div id="input-section" x-data="{ paused: false }"><textarea id="chat-input" placeholder="Type your message here..." rows="1"></textarea><button class="chat-button" id="send-button" aria-label="Send message"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><path d="M25 20 L75 50 L25 80" fill="none" stroke="currentColor" stroke-width="15" />- </svg>+ </svg></button>- <button class="chat-button pause-button" id="pause-button" @click="pauseAgent(true)" x-show="!paused" aria-label="Pause agent">+ <button class="chat-button pause-button" id="pause-button" @click="pauseAgent(true)" x-show="!paused"+ aria-label="Pause agent"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">- <path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z"/>+ <path d="M6 19h4V5H6v14zm8-14v14h4V5h-4z" /></svg></button>- <button class="chat-button pause-button" id="unpause-button" @click="pauseAgent(false)" x-show="paused" aria-label="Resume agent">+ <button class="chat-button pause-button" id="unpause-button" @click="pauseAgent(false)" x-show="paused"+ aria-label="Resume agent"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor">- <path d="M8 5v14l11-7z"/>+ <path d="M8 5v14l11-7z" /></svg></button>+ </div></div></div>- </div></body>-</html>+</html>\ No newline at end of filediff --git a/webui/index.js b/webui/index.jsindex 8a86ecd21..7afed4769 100644--- a/webui/index.js+++ b/webui/index.js@@ -9,70 +9,87 @@ const sendButton = document.getElementById('send-button');const inputSection = document.getElementById('input-section');const statusSection = document.getElementById('status-section');const chatsSection = document.getElementById('chats-section');-const scrollbarThumb = document.querySelector('#chat-history::-webkit-scrollbar-thumb');+const scrollbarThumb = document.querySelector('#chat-history::-webkit-scrollbar-thumb');+const progressBar = document.getElementById('progress-bar');++let autoScroll = true;let context = "";// Initialize the toggle button-setupSidebarToggle();+setupSidebarToggle();function isMobile() {return window.innerWidth <= 768;- }-- function toggleSidebar() {+}++function toggleSidebar() {leftPanel.classList.toggle('hidden');rightPanel.classList.toggle('expanded');- }-- function handleResize() {+}++function handleResize() {if (isMobile()) {- leftPanel.classList.add('hidden');- rightPanel.classList.add('expanded');+ leftPanel.classList.add('hidden');+ rightPanel.classList.add('expanded');} else {- leftPanel.classList.remove('hidden');- rightPanel.classList.remove('expanded');+ leftPanel.classList.remove('hidden');+ rightPanel.classList.remove('expanded');}- }-- // Run on startup and window resize- window.addEventListener('load', handleResize);- window.addEventListener('resize', handleResize);-- function setupSidebarToggle() {+}++// Run on startup and window resize+window.addEventListener('load', handleResize);+window.addEventListener('resize', handleResize);++function setupSidebarToggle() {const leftPanel = document.getElementById('left-panel');const rightPanel = document.getElementById('right-panel');const toggleSidebarButton = document.getElementById('toggle-sidebar');if (toggleSidebarButton) {- toggleSidebarButton.addEventListener('click', toggleSidebar);+ toggleSidebarButton.addEventListener('click', toggleSidebar);} else {- console.error('Toggle sidebar button not found');- setTimeout(setupSidebarToggle, 100);+ console.error('Toggle sidebar button not found');+ setTimeout(setupSidebarToggle, 100);}- }- // Make sure to call this function- document.addEventListener('DOMContentLoaded', setupSidebarToggle);+}+// Make sure to call this function+document.addEventListener('DOMContentLoaded', setupSidebarToggle);async function sendMessage() {- const message = chatInput.value.trim();- if (message) {-- const response = await sendJsonData("/msg", { text: message, context });-- //setMessage('user', message);- chatInput.value = '';- adjustTextareaHeight();+ try {+ const message = chatInput.value.trim();+ if (message) {++ const response = await sendJsonData("/msg", { text: message, context });++ if (!response) {+ toast("No response returned.", "error")+ } else if (!response.ok) {+ if (response.message) {+ toast(response.message, "error")+ } else {+ toast("Undefined error.", "error")+ }+ }++ //setMessage('user', message);+ chatInput.value = '';+ adjustTextareaHeight();+ }+ } catch (e) {+ toast(e.message, "error")}}-+chatInput.addEventListener('keydown', (e) => {if (e.key === 'Enter' && !e.shiftKey) {e.preventDefault();sendMessage();}});-+sendButton.addEventListener('click', sendMessage);function updateUserTime() {@@ -81,7 +98,7 @@ function updateUserTime() {const minutes = now.getMinutes();const seconds = now.getSeconds();const ampm = hours >= 12 ? 'pm' : 'am';- const formattedHours = hours % 12 || 12;+ const formattedHours = hours % 12 || 12;// Format the timeconst timeString = `${formattedHours}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')} ${ampm}`;@@ -94,11 +111,11 @@ function updateUserTime() {const userTimeElement = document.getElementById('time-date');userTimeElement.innerHTML = `${timeString}<br><span id="user-date">${dateString}</span>`;}-+updateUserTime();setInterval(updateUserTime, 1000);--function setMessage(id, type, heading, content, kvps = null) {++function setMessage(id, type, heading, content, temp, kvps = null) {// Search for the existing message container by idlet messageContainer = document.getElementById(`message-${id}`);@@ -181,6 +198,8 @@ async function poll() {}}+ updateProgress(response.log_progress)+//set ui model vars from backendconst inputAD = Alpine.$data(inputSection);inputAD.paused = response.paused;@@ -202,10 +221,18 @@ async function poll() {}}+function updateProgress(progress) {+ if (!progress) progress = "Waiting for input"++ if (progressBar.innerHTML != progress) {+ progressBar.innerHTML = progress+ }+}+function updatePauseButtonState(isPaused) {const pauseButton = document.getElementById('pause-button');const unpauseButton = document.getElementById('unpause-button');-+if (isPaused) {pauseButton.style.display = 'none';unpauseButton.style.display = 'flex';@@ -277,22 +304,38 @@ window.toggleThoughts = async function (showThoughts) {toggleCssProperty('.msg-thoughts', 'display', showThoughts ? undefined : 'none');}+window.toggleUtils = async function (showUtils) {+ // add display:none to .msg-json class definition+ toggleCssProperty('.message-util', 'display', showUtils ? undefined : 'none');+ // toggleCssProperty('.message-util .msg-kvps', 'display', showUtils ? undefined : 'none');+ // toggleCssProperty('.message-util .msg-content', 'display', showUtils ? undefined : 'none');+}-window.toggleDarkMode = function(isDark) {+window.toggleDarkMode = function (isDark) {if (isDark) {- document.body.classList.remove('light-mode');+ document.body.classList.remove('light-mode');} else {- document.body.classList.add('light-mode');+ document.body.classList.add('light-mode');}console.log("Dark mode:", isDark);localStorage.setItem('darkMode', isDark);};-- // Modify this part- document.addEventListener('DOMContentLoaded', () => {- const isDarkMode = localStorage.getItem('darkMode') === 'true';++// Modify this part+document.addEventListener('DOMContentLoaded', () => {+ const isDarkMode = localStorage.getItem('darkMode') !== 'false';toggleDarkMode(isDarkMode);- });+});++window.toggleDarkMode = function (isDark) {+ if (isDark) {+ document.body.classList.remove('light-mode');+ } else {+ document.body.classList.add('light-mode');+ }+ console.log("Dark mode:", isDark);+ localStorage.setItem('darkMode', isDark);+};function toggleCssProperty(selector, property, value) {// Get the stylesheet that contains the class@@ -310,7 +353,7 @@ function toggleCssProperty(selector, property, value) {if (value === undefined) {rule.style.removeProperty(property);} else {- rule.style.setProperty(property, value);+ rule.style.setProperty(property, value);}return;}@@ -318,6 +361,40 @@ function toggleCssProperty(selector, property, value) {}}+function toast(text, type = 'info') {+ const toast = document.getElementById('toast');++ // Update the toast content and type+ toast.querySelector('#toast .toast__message').textContent = text;+ toast.className = `toast toast--${type}`;+ toast.style.display = 'flex';++ // Add the close button event listener+ const closeButton = toast.querySelector('#toast .toast__close');+ closeButton.onclick = () => {+ toast.style.display = 'none';+ clearTimeout(toast.timeoutId);+ };++ // Add the copy button event listener+ const copyButton = toast.querySelector('#toast .toast__copy');+ copyButton.onclick = () => {+ navigator.clipboard.writeText(text);+ copyButton.textContent = 'Copied!';+ setTimeout(() => {+ copyButton.textContent = 'Copy';+ }, 2000);+ };++ // Clear any existing timeout+ clearTimeout(toast.timeoutId);++ // Automatically close the toast after 5 seconds+ toast.timeoutId = setTimeout(() => {+ toast.style.display = 'none';+ }, 10000);+}+chatInput.addEventListener('input', adjustTextareaHeight);setInterval(poll, 250);diff --git a/webui/messages.js b/webui/messages.jsindex 206ebec8d..d5bb7c2b2 100644--- a/webui/messages.js+++ b/webui/messages.js@@ -18,8 +18,8 @@ export function getHandler(type) {return drawMessageError;case 'info':return drawMessageInfo;- case 'adhoc':- return drawMessageAdhoc;+ case 'util':+ return drawMessageUtil;case 'hint':return drawMessageInfo;default:@@ -27,7 +27,7 @@ export function getHandler(type) {}}-export function _drawMessage(messageContainer, heading, content, temp, kvps = null, messageClasses = [], contentClasses = []) {+export function _drawMessage(messageContainer, heading, content, temp, followUp, kvps = null, messageClasses = [], contentClasses = []) {// if (type !== 'user') {@@ -48,10 +48,12 @@ export function _drawMessage(messageContainer, heading, content, temp, kvps = nutextNode.textContent = content;textNode.style.whiteSpace = 'pre-wrap';textNode.style.wordBreak = 'break-word';- textNode.classList.add("message-content", ...contentClasses)+ textNode.classList.add("msg-content", ...contentClasses)messageDiv.appendChild(textNode);messageContainer.appendChild(messageDiv);+ if (followUp) messageContainer.classList.add("message-followup")+// if (type !== 'user') {// const actions = document.createElement('div');// actions.classList.add('message-actions');@@ -63,51 +65,53 @@ export function _drawMessage(messageContainer, heading, content, temp, kvps = nu}export function drawMessageDefault(messageContainer, id, type, heading, content, temp, kvps = null) {- _drawMessage(messageContainer, heading, content, temp, kvps, ['message-ai', 'message-default'], ['msg-json']);+ _drawMessage(messageContainer, heading, content, temp, false, kvps, ['message-ai', 'message-default'], ['msg-json']);}export function drawMessageAgent(messageContainer, id, type, heading, content, temp, kvps = null) {- let kvpsFlat=null+ let kvpsFlat = nullif (kvps) {kvpsFlat = { ...kvps, ...kvps['tool_args'] || {} }delete kvpsFlat['tool_args']}- _drawMessage(messageContainer, heading, content, temp, kvpsFlat, ['message-ai', 'message-agent'], ['msg-json']);+ _drawMessage(messageContainer, heading, content, temp, false, kvpsFlat, ['message-ai', 'message-agent'], ['msg-json']);}export function drawMessageResponse(messageContainer, id, type, heading, content, temp, kvps = null) {- _drawMessage(messageContainer, heading, content, temp, null, ['message-ai', 'message-agent-response', 'message-fw']);+ _drawMessage(messageContainer, heading, content, temp, true, null, ['message-ai', 'message-agent-response']);}export function drawMessageDelegation(messageContainer, id, type, heading, content, temp, kvps = null) {- _drawMessage(messageContainer, heading, content, temp, kvps, ['message-ai', 'message-agent', 'message-fw', 'message-agent-delegation']);+ _drawMessage(messageContainer, heading, content, temp, true, kvps, ['message-ai', 'message-agent', 'message-agent-delegation']);}export function drawMessageUser(messageContainer, id, type, heading, content, temp, kvps = null) {- _drawMessage(messageContainer, heading, content, temp, kvps, ['message-user']);+ _drawMessage(messageContainer, heading, content, temp, false, kvps, ['message-user']);}export function drawMessageTool(messageContainer, id, type, heading, content, temp, kvps = null) {- _drawMessage(messageContainer, heading, content, temp, kvps, ['message-ai', 'message-tool', 'message-fw'], ['msg-output']);+ _drawMessage(messageContainer, heading, content, temp, true, kvps, ['message-ai', 'message-tool'], ['msg-output']);}export function drawMessageCodeExe(messageContainer, id, type, heading, content, temp, kvps = null) {- _drawMessage(messageContainer, heading, content, temp, null, ['message-ai', 'message-code-exe', 'message-fw']);+ _drawMessage(messageContainer, heading, content, temp, true, null, ['message-ai', 'message-code-exe']);}export function drawMessageAgentPlain(classes, messageContainer, id, type, heading, content, temp, kvps = null) {- _drawMessage(messageContainer, heading, content, temp, null, ['message-ai', ...classes]);-}--export function drawMessageAdhoc(messageContainer, id, type, heading, content, temp, kvps = null) {- return drawMessageAgentPlain(['message-adhoc'], messageContainer, id, type, heading, content, temp, kvps);+ _drawMessage(messageContainer, heading, content, temp, false, null, [...classes]);+ messageContainer.classList.add('center-container')}export function drawMessageInfo(messageContainer, id, type, heading, content, temp, kvps = null) {return drawMessageAgentPlain(['message-info'], messageContainer, id, type, heading, content, temp, kvps);}+export function drawMessageUtil(messageContainer, id, type, heading, content, temp, kvps = null) {+ _drawMessage(messageContainer, heading, content, temp, false, kvps, ['message-util'], ['msg-json']);+ messageContainer.classList.add('center-container')+}+export function drawMessageWarning(messageContainer, id, type, heading, content, temp, kvps = null) {return drawMessageAgentPlain(['message-warning'], messageContainer, id, type, heading, content, temp, kvps);}@@ -119,9 +123,10 @@ export function drawMessageError(messageContainer, id, type, heading, content, tfunction drawKvps(container, kvps) {if (kvps) {const table = document.createElement('table');- table.classList.add('ai-info');+ table.classList.add('msg-kvps');for (let [key, value] of Object.entries(kvps)) {const row = table.insertRow();+ row.classList.add('kvps-row');if (key == "thoughts") row.classList.add('msg-thoughts');const th = row.insertCell();diff --git a/webui/toast.css b/webui/toast.cssnew file mode 100644index 000000000..dde8d00dd--- /dev/null+++ b/webui/toast.css@@ -0,0 +1,42 @@+#toast {+ /* position: fixed;+ bottom: 20px;+ left: 50%;+ transform: translateX(-50%); */+ margin: 0.5em;+ background-color: #333;+ color: #fff;+ padding: 0.3em;+ border-radius: 0.3125em;+ box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);+ display: none;+ align-items: center;+ z-index: 9999;+ }++ #toast.toast--success {+ background-color: #4CAF50;+ }++ #toast.toast--error {+ background-color: #731811;+ }++ #toast.toast--info {+ background-color: #2196F3;+ }++ .toast__message {+ margin-right: 16px;+ flex-grow: 1;+ }++ .toast__close,+ .toast__copy {+ background-color: transparent;+ border: none;+ color: #fff;+ cursor: pointer;+ font-size: 16px;+ margin-left: 8px;+ }\ No newline at end of file