Skip to content

Agent Zero AI framework

prototype v0.2

frdelbe11dbbab621
diff --git a/agent.py b/agent.py
index f653a9be9..752104b8c 100644
--- a/agent.py
+++ b/agent.py
@@ -1,5 +1,4 @@
-import json
-import time, importlib, inspect
+import time, importlib, inspect, os, json
import traceback
from typing import Optional, Dict, TypedDict
from tools.helpers import extract_tools, rate_limiter, files, errors
@@ -9,6 +8,7 @@ from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_core.messages import HumanMessage, SystemMessage
from langchain_core.language_models.chat_models import BaseChatModel
from langchain_core.embeddings import Embeddings
+from tools.helpers.rate_limiter import RateLimiter
# rate_limit = rate_limiter.rate_limiter(30,160000) #TODO! implement properly
@@ -20,32 +20,36 @@ class Agent:
def __init__(self,
agent_number: int,
- chat_llm:BaseChatModel,
+ chat_model:BaseChatModel,
embeddings_model:Embeddings,
memory_subdir: str = "",
auto_memory_count: int = 3,
auto_memory_skip: int = 2,
rate_limit_seconds: int = 60,
+ rate_limit_requests: int = 30,
rate_limit_input_tokens: int = 0,
rate_limit_output_tokens: int = 0,
- msgs_keep_max: int =25,
- msgs_keep_start: int =5,
- msgs_keep_end: int =10,
+ msgs_keep_max: int = 25,
+ msgs_keep_start: int = 5,
+ msgs_keep_end: int = 10,
+ max_tool_response_length: int = 3000,
**kwargs):
# agent config
self.agent_number = agent_number
- self.chat_model = chat_llm
+ self.chat_model = chat_model
self.embeddings_model = embeddings_model
self.memory_subdir = memory_subdir
self.auto_memory_count = auto_memory_count
self.auto_memory_skip = auto_memory_skip
self.rate_limit_seconds = rate_limit_seconds
+ self.rate_limit_requests = rate_limit_requests
self.rate_limit_input_tokens = rate_limit_input_tokens
self.rate_limit_output_tokens = rate_limit_output_tokens
self.msgs_keep_max = msgs_keep_max
self.msgs_keep_start = msgs_keep_start
self.msgs_keep_end = msgs_keep_end
+ self.max_tool_response_length = max_tool_response_length
# non-config vars
self.agent_name = f"Agent {self.agent_number}"
@@ -57,9 +61,12 @@ class Agent:
self.last_message = ""
self.intervention_message = ""
self.intervention_status = False
-
+ self.rate_limiter = RateLimiter(max_calls=rate_limit_requests,max_input_tokens=rate_limit_input_tokens,max_output_tokens=rate_limit_output_tokens,window_seconds=rate_limit_seconds)
self.data = {} # free data object all the tools can use
+ os.chdir(files.get_abs_path("./work_dir")) #change CWD to work_dir
+
+
def message_loop(self, msg: str):
try:
printer = PrintStyle(italic=True, font_color="#b3ffd9", padding=False)
@@ -84,10 +91,11 @@ class Agent:
inputs = {"messages": self.history}
chain = prompt | self.chat_model
- formatted_inputs = prompt.format(messages=self.history)
-
- # rate_limit(len(formatted_inputs)/4) #wait for rate limiter - A helpful rule of thumb is that one token generally corresponds to ~4 characters of text for common English text. This translates to roughly ¾ of a word (so 100 tokens ~= 75 words).
+ formatted_inputs = prompt.format(messages=self.history)
+ tokens = int(len(formatted_inputs)/4)
+ self.rate_limiter.limit_call_and_input(tokens)
+
# output that the agent is starting
PrintStyle(bold=True, font_color="green", padding=True, background_color="white").print(f"{self.agent_name}: Starting a message:")
@@ -101,7 +109,9 @@ class Agent:
if content:
printer.stream(content) # output the agent response stream
agent_response += content # concatenate stream into the response
-
+
+ self.rate_limiter.set_output_tokens(int(len(agent_response)/4))
+
if not self.handle_intervention(agent_response):
if self.last_message == agent_response: #if assistant_response is the same as last message in history, let him know
self.append_message(agent_response) # Append the assistant's response to the history
@@ -156,9 +166,13 @@ class Agent:
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)
-
+
+ formatted_inputs = prompt.format()
+ tokens = int(len(formatted_inputs)/4)
+ self.rate_limiter.limit_call_and_input(tokens)
+
for chunk in chain.stream({}):
- if self.handle_intervention(response): break # wait for intervention and handle it, if paused
+ if self.handle_intervention(): break # wait for intervention and handle it, if paused
if isinstance(chunk, str): content = chunk
elif hasattr(chunk, "content"): content = str(chunk.content)
@@ -167,6 +181,8 @@ class Agent:
if printer: printer.stream(content)
response+=content
+ self.rate_limiter.set_output_tokens(int(len(response)/4))
+
return response
def get_last_message(self):
@@ -205,7 +221,6 @@ class Agent:
return self.history
-
def handle_intervention(self, progress:str="") -> bool:
while self.paused: time.sleep(0.1) # wait if paused
if self.intervention_message and not self.intervention_status: # if there is an intervention message, but not yet processed
@@ -229,8 +244,8 @@ class Agent:
if self.handle_intervention(): return # wait if paused and handle intervention message if needed
- tool.before_execution()
- response = tool.execute()
+ tool.before_execution(**tool_args)
+ response = tool.execute(**tool_args)
tool.after_execution(response)
if response.break_loop: return response.message
@@ -267,5 +282,5 @@ class Agent:
"raw_memories": memories
}
cleanup_prompt = files.read_file("./prompts/msg.memory_cleanup.md").replace("{", "{{")
- clean_memories = self.send_adhoc_message(cleanup_prompt,json.dumps(input), output_label="Memory cleanup summary")
+ clean_memories = self.send_adhoc_message(cleanup_prompt,json.dumps(input), output_label="Memory injection")
return clean_memories
\ No newline at end of file
diff --git a/example.env b/example.env
index 0476bebd2..2aa725749 100644
--- a/example.env
+++ b/example.env
@@ -1,4 +1,8 @@
API_KEY_OPENAI=
API_KEY_ANTHROPIC=
API_KEY_GROQ=
-API_KEY_PERPLEXITY=
\ No newline at end of file
+API_KEY_PERPLEXITY=
+
+
+TOKENIZERS_PARALLELISM=true
+PYDEVD_DISABLE_FILE_VALIDATION=1
\ No newline at end of file
diff --git a/main.py b/main.py
index 01e254bc0..fe3d59b96 100644
--- a/main.py
+++ b/main.py
@@ -32,9 +32,21 @@ def chat():
embedding_llm = models.get_embedding_hf()
# create the first agent
- agent0 = Agent(agent_number=0,
- chat_llm=chat_llm,
- embeddings_model=embedding_llm)
+ agent0 = Agent( agent_number=0,
+ chat_model=chat_llm,
+ embeddings_model=embedding_llm,
+ # memory_subdir = "",
+ # auto_memory_count = 3,
+ # auto_memory_skip = 2,
+ # rate_limit_seconds = 60,
+ rate_limit_requests = 30,
+ rate_limit_input_tokens = 160000,
+ rate_limit_output_tokens = 8000,
+ # msgs_keep_max = 25,
+ # msgs_keep_start = 5,
+ # msgs_keep_end = 10,
+ # max_tool_response_length = 3000,
+ )
# start the conversation loop
while True:
diff --git a/prompts/agent.system.md b/prompts/agent.system.md
index 7dcfc7ab4..078da7134 100644
--- a/prompts/agent.system.md
+++ b/prompts/agent.system.md
@@ -1,5 +1,7 @@
# Your role
-- You are autonomous JSON AI task solver
+- You are autonomous JSON AI task solving agent enhanced with knowledge and execution tools
+- You are given task by your superior and you solve it using your subordinates and tools
+- You never just talk about solutions, never inform user about intentions, you are the one to execute actions using your tools and get things done
# Communication
- Your response is a JSON containing the following fields:
@@ -11,14 +13,14 @@
- Each tool has specific arguments listed in Available tools section
- No text before or after the JSON object. End message there.
-## Response example that must be used every time
+## Response example
~~~json
{
"thoughts": [
- "The user has requested...",
- "I need to follow these steps...",
- "I need to use the tool...",
- "Then I will..."
+ "The user has requested extracting a zip file downloaded yesterday.",
+ "Steps to solution are...",
+ "I will process step by step...",
+ "Analysis of step..."
],
"tool_name": "name_of_tool",
"tool_args": {
@@ -26,4 +28,43 @@
"arg2": "val2"
}
}
-~~~
\ No newline at end of file
+~~~
+
+# Step by step instruction manual to problem solving
+- Do not follow for simple questions, only for tasks need solving.
+- Explain each step using your **thoughts** argument.
+
+0. Outline the plan by repeating these instructions.
+1. Check the memory output of your **knowledge_tool**. Maybe you have solved similar task before and already have helpful information.
+2. Check the online sources output of your **knowledge_tool**.
+ - Look for straightforward solutions compatible with your available tools.
+ - Always look for opensource python/nodejs/terminal tools and packages first.
+3. Break task into subtasks that can be solved independently.
+4. Solution / delegation
+ - If your role is suitable for the curent subtask, use your tools to solve it.
+ - If a different role would be more suitable for the subtask, use **call_subordinate** tool to delegate the subtask to subordinate agent and instruct him about his role.
+5. Completing the task
+ - Consolidate all subtasks and explain the status.
+ - Verify the result using your tools if possible (check created files etc.)
+ - Do not accept failure, search for error solution and try again with fixed input or different ways.
+ - If there is helpful information discovered during the solution, save it into your memory using tool **memorize** for later.
+ - Report back to your user using **response** tool, describe the result and provide all necessary information. Do not just output your response, you must use the tool for that.
+
+# General operation manual
+- Use your reasoning and process each problem in a step-by-step manner using your **thoughts** argument.
+- Always check your previous messages and prevent repetition. Always move towards solution.
+- Never assume success. You always need to do a check with a positive result.
+- Avoid solutions that require credentials, user interaction, GUI usage etc. All has to be done using code and terminal.
+- When asked about your memory, it always refers to **knowledge_tool** and **memorize** tool, never your internal knowledge.
+
+# Cooperation and delegation
+- Agents can have roles like scientist, coder, writer etc.
+- If your user has assigned you a role in the first message, you have to follow these instructions and play your role.
+- Your role will not be suitable for some subtasks, in that case you can delegate the subtask to subordinate agent and instruct him about his role using **call_subordinate** tool.
+- Always be very descriptive when explaining your subordinate agent's role and task. Include all necessary details as well as higher leven overview about the goal.
+- Communicate back and forth with your subordinate and superior using **call_subordinate** and **response** tools.
+- Communication is the key to succesfull solution.
+
+# Tips and tricks
+- Focus on python/nodejs/linux libraries when searching for solutions. You can use them with your tools and make solutions easy.
+- Sometimes you don't need tools, some things can be determined.
diff --git a/prompts/agent.tools.md b/prompts/agent.tools.md
index bbe059aed..2314f1fb5 100644
--- a/prompts/agent.tools.md
+++ b/prompts/agent.tools.md
@@ -20,6 +20,27 @@ Always verify memory by online.
}
~~~
+### call_subordinate:
+Use subordinate agents to solve subtasks.
+Use "message" argument to send message. Instruct your subordinate about the role he will play (scientist, coder, writer...) and his task in detail.
+Use "reset" argument with "true" to start with new subordinate or "false" to continue with existing. For brand new tasks use "true", for followup conversation use "false".
+Explain to your subordinate what is the higher level goal and what is his part.
+Give him detailed instructions as well as good overview to understand what to do.
+**Example usage**:
+~~~json
+{
+ "thoughts": [
+ "The result seems to be ok but...",
+ "I will ask my subordinate to fix...",
+ ],
+ "tool_name": "call_subordinate",
+ "tool_args": {
+ "message": "Well done, now edit...",
+ "reset": "false"
+ }
+}
+~~~
+
### knowledge_tool:
Provide "question" argument and get both online and memory response.
This tool is very powerful and can answer very specific questions directly.
diff --git a/prompts/fw.msg_timeout.md b/prompts/fw.msg_timeout.md
index da5c93805..0faaa5e6d 100644
--- a/prompts/fw.msg_timeout.md
+++ b/prompts/fw.msg_timeout.md
@@ -1,3 +1,16 @@
-User is not responding to your message.
+# User is not responding to your message.
If you have a task in progress, continue on your own.
-I you don't have a task, use the <task_done$> message.
\ No newline at end of file
+I you don't have a task, use the **task_done** tool with **text** argument.
+
+# Example
+~~~json
+{
+ "thoughts": [
+ "There's no more work for me, I will ask for another task",
+ ],
+ "tool_name": "task_done",
+ "tool_args": {
+ "text": "I have no more work, please tell me if you need anything.",
+ }
+}
+~~~
\ No newline at end of file
diff --git a/prompts/msg.memory_cleanup.md b/prompts/msg.memory_cleanup.md
index 0dcf3fc8d..1563bbc31 100644
--- a/prompts/msg.memory_cleanup.md
+++ b/prompts/msg.memory_cleanup.md
@@ -8,6 +8,19 @@
# Expected output format
- Return filtered list of bullet points of key elements in the memories
-- Include every important detail relevant to conversation
-- Include code snippets if relevant
-- Omit any unrelevant information
\ No newline at end of file
+- Do not include memory contents, only their summaries to inform the user that he has memories of the topic.
+- If there are relevant memories, instruct user to use "knowledge_tool" to get more details.
+
+# Example output 1 (relevant memories):
+~~~md
+1. Guide how to create a web app including code.
+2. Javascript snippets from snake game development.
+3. SVG image generation for game sprites with examples.
+
+Check your knowledge_tool for more details.
+~~~
+
+# Example output 2 (no relevant memories):
+~~~text
+No relevant memories on the topic found.
+~~~
\ No newline at end of file
diff --git a/test.py b/test.py
deleted file mode 100644
index 65d08ba67..000000000
--- a/test.py
+++ /dev/null
@@ -1,26 +0,0 @@
-def extract_json_string(content):
- start = content.find('{')
- if start == -1:
- print("No JSON content found.")
- return ""
-
- # Find the first '{'
- end = content.rfind('}')
- if end == -1:
- # If there's no closing '}', return from start to the end
- return content[start:]
- else:
- # If there's a closing '}', return the substring from start to end
- return content[start:end+1]
-
-# Test cases
-test_cases = [
- 'Some text before {"key1": "value1", "key2": 123, "key3": true, "key4": null} some text after',
- '{"key1": "value1", "key2": 123, "key3": true, "key4": null', # Incomplete JSON
- '{"nested": {"key": "value"}, "list": [1, 2, 3], "bool": true}',
- 'text without json',
-]
-
-# Run the test cases
-results = [extract_json_string(tc) for tc in test_cases]
-print(results)
diff --git a/tools/delegation.py b/tools/call_subordinate.py
similarity index 59%
rename from tools/delegation.py
rename to tools/call_subordinate.py
index 8e51bf5ee..a0f55c211 100644
--- a/tools/delegation.py
+++ b/tools/call_subordinate.py
@@ -5,12 +5,14 @@ from tools.helpers.print_style import PrintStyle
class Delegation(Tool):
- def execute(self, **kwargs):
+ def execute(self, message="", reset="", **kwargs):
# create subordinate agent using the data object on this agent and set superior agent to his data object
- if self.agent.get_data("subordinate") is None or self.args["reset"].lower().strip() == "true":
+ if self.agent.get_data("subordinate") is None or str(reset).lower().strip() == "true":
# subordinate = Agent(system_prompt=self.agent.system_prompt, tools_prompt=self.agent.tools_prompt, number=self.agent.number+1)
- subordinate = Agent(**self.agent.__dict__, agent_number=self.agent.agent_number+1)
+ config = self.agent.__dict__.copy()
+ config["agent_number"] = self.agent.agent_number+1
+ subordinate = Agent(**config)
subordinate.set_data("superior", self.agent)
self.agent.set_data("subordinate", subordinate)
# run subordinate agent message loop
- return self.agent.get_data("subordinate").message_loop(self.args["task"])
\ No newline at end of file
+ return Response( message=self.agent.get_data("subordinate").message_loop(message), break_loop=False)
\ No newline at end of file
diff --git a/tools/code_execution_tool.py b/tools/code_execution_tool.py
index 6d9aa0de4..7012c8ae8 100644
--- a/tools/code_execution_tool.py
+++ b/tools/code_execution_tool.py
@@ -8,9 +8,10 @@ from tools.helpers.print_style import PrintStyle
class CodeExecution(Tool):
- def execute(self):
+ def execute(self,**kwargs):
- os.chdir(files.get_abs_path("./work_dir")) #change CWD to work_dir
+ # os.chdir(files.get_abs_path("./work_dir")) #change CWD to work_dir
+
runtime = self.args["runtime"].lower().strip()
if runtime == "python":
response = self.execute_python_code(self.args["code"])
@@ -21,7 +22,6 @@ class CodeExecution(Tool):
else:
response = files.read_file("./prompts/fw.code_runtime_wrong.md", runtime=runtime)
- response = messages.truncate_text(response.strip(), 2000) # TODO parameterize
if not response: response = files.read_file("./prompts/fw.code_no_output.md")
return Response(message=response, break_loop=False)
diff --git a/tools/helpers/dirty_json.py b/tools/helpers/dirty_json.py
index cf75e431e..c9e4b4b48 100644
--- a/tools/helpers/dirty_json.py
+++ b/tools/helpers/dirty_json.py
@@ -84,7 +84,7 @@ class DirtyJson:
return self._parse_object()
elif self.current_char == '[':
return self._parse_array()
- elif self.current_char in ['"', "'"]:
+ elif self.current_char in ['"', "'", "`"]:
if self._peek(2) == self.current_char * 2: # type: ignore
return self._parse_multiline_string()
return self._parse_string()
@@ -122,6 +122,7 @@ class DirtyJson:
self.stack.pop()
return
if self.current_char is None:
+ self.stack.pop()
return # End of input reached while parsing object
key = self._parse_key()
@@ -144,6 +145,7 @@ class DirtyJson:
continue
elif self.current_char != '}':
if self.current_char is None:
+ self.stack.pop()
return # End of input reached after value
# Allow missing comma between key-value pairs
continue
@@ -262,6 +264,7 @@ class DirtyJson:
while self.current_char is not None and self.current_char not in [':', ',', '}', ']']:
result += self.current_char
self._advance()
+ self._advance()
return result.strip()
def _peek(self, n):
diff --git a/tools/helpers/errors.py b/tools/helpers/errors.py
index a8b7e08e9..0cacec77e 100644
--- a/tools/helpers/errors.py
+++ b/tools/helpers/errors.py
@@ -1,6 +1,8 @@
+import re
+import traceback
def format_error(e: Exception, max_entries=2):
- traceback_text = str(e.with_traceback(None))
+ traceback_text = traceback.format_exc()
# Split the traceback into lines
lines = traceback_text.split('\n')
diff --git a/tools/helpers/rate_limiter.py b/tools/helpers/rate_limiter.py
index ccf1d8520..cfe75b367 100644
--- a/tools/helpers/rate_limiter.py
+++ b/tools/helpers/rate_limiter.py
@@ -2,12 +2,13 @@ import time
from collections import deque
from dataclasses import dataclass
from typing import List, Tuple
+from .print_style import PrintStyle
@dataclass
class CallRecord:
timestamp: float
input_tokens: int
- output_tokens: int
+ output_tokens: int = 0 # Default to 0, will be set separately
class RateLimiter:
def __init__(self, max_calls: int, max_input_tokens: int, max_output_tokens: int, window_seconds: int = 60):
@@ -27,22 +28,51 @@ class RateLimiter:
output_tokens = sum(record.output_tokens for record in self.call_records)
return calls, input_tokens, output_tokens
- def _wait_if_needed(self, current_time: float):
+ def _wait_if_needed(self, current_time: float, new_input_tokens: int):
while True:
self._clean_old_records(current_time)
calls, input_tokens, output_tokens = self._get_counts()
- if calls < self.max_calls and input_tokens < self.max_input_tokens and output_tokens < self.max_output_tokens:
+ wait_reasons = []
+ if self.max_calls > 0 and calls >= self.max_calls:
+ wait_reasons.append("max calls")
+ if self.max_input_tokens > 0 and input_tokens + new_input_tokens > self.max_input_tokens:
+ wait_reasons.append("max input tokens")
+ if self.max_output_tokens > 0 and output_tokens >= self.max_output_tokens:
+ wait_reasons.append("max output tokens")
+
+ if not wait_reasons:
break
oldest_record = self.call_records[0]
wait_time = oldest_record.timestamp + self.window_seconds - current_time
if wait_time > 0:
+ PrintStyle(font_color="yellow", padding=True).print(f"Rate limit exceeded. Waiting for {wait_time:.2f} seconds due to: {', '.join(wait_reasons)}")
time.sleep(wait_time)
current_time = time.time()
- def limit(self, input_token_count: int, output_token_count: int):
+ def limit_call_and_input(self, input_token_count: int) -> CallRecord:
current_time = time.time()
- self._wait_if_needed(current_time)
- self.call_records.append(CallRecord(current_time, input_token_count, output_token_count))
+ self._wait_if_needed(current_time, input_token_count)
+ new_record = CallRecord(current_time, input_token_count)
+ self.call_records.append(new_record)
+ return new_record
+
+ def set_output_tokens(self, output_token_count: int):
+ if self.call_records:
+ self.call_records[-1].output_tokens += output_token_count
+ return self
+
+# Example usage
+rate_limiter = RateLimiter(max_calls=5, max_input_tokens=1000, max_output_tokens=2000)
+def rate_limited_function(input_token_count: int, output_token_count: int):
+ # First, limit the call and input tokens (this may wait)
+ rate_limiter.limit_call_and_input(input_token_count)
+
+ # Your function logic here
+ print(f"Function called with {input_token_count} input tokens")
+
+ # After processing, set the output tokens (this doesn't wait)
+ rate_limiter.set_output_tokens(output_token_count)
+ print(f"Function completed with {output_token_count} output tokens")
diff --git a/tools/helpers/tool.py b/tools/helpers/tool.py
index 53feca036..1b5979676 100644
--- a/tools/helpers/tool.py
+++ b/tools/helpers/tool.py
@@ -2,7 +2,7 @@ from abc import abstractmethod
from typing import TypedDict
from agent import Agent
from tools.helpers.print_style import PrintStyle
-from tools.helpers import files
+from tools.helpers import files, messages
class Response:
def __init__(self, message: str, break_loop: bool) -> None:
@@ -18,19 +18,20 @@ class Tool:
self.message = message
@abstractmethod
- def execute(self) -> Response:
+ def execute(self,**kwargs) -> Response:
pass
- def before_execution(self):
+ 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}':")
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)+": ")
- PrintStyle(font_color="#85C1E9", padding="\n" in value).stream(value)
+ PrintStyle(font_color="#85C1E9", padding=isinstance(value,str) and "\n" in value).stream(value)
PrintStyle().print()
- def after_execution(self, response: Response):
- msg_response = files.read_file("./prompts/fw.tool_response.md", tool_name=self.name, tool_response=response.message)
+ def after_execution(self, response: Response, **kwargs):
+ text = messages.truncate_text(response.message.strip(), self.agent.max_tool_response_length)
+ msg_response = files.read_file("./prompts/fw.tool_response.md", tool_name=self.name, tool_response=text)
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="#85C1E9").print(response.message)
diff --git a/tools/knowledge_tool.py b/tools/knowledge_tool.py
index 553085d79..062d159ee 100644
--- a/tools/knowledge_tool.py
+++ b/tools/knowledge_tool.py
@@ -9,11 +9,11 @@ from tools.helpers.tool import Tool, Response
from tools.helpers import files
class Knowledge(Tool):
- def execute(self):
+ def execute(self, question="", **kwargs):
with concurrent.futures.ThreadPoolExecutor() as executor:
# Schedule the two functions to be run in parallel
- future_online = executor.submit(online_knowledge_tool.process_question, self.args["question"])
- future_memory = executor.submit(memory_tool.process_query, self.agent, self.args["question"])
+ future_online = executor.submit(online_knowledge_tool.process_question, question)
+ future_memory = executor.submit(memory_tool.process_query, self.agent, question)
# Wait for both functions to complete
online_result = future_online.result()
diff --git a/tools/memorize.py b/tools/memorize.py
index 6eef65eb8..a535d7151 100644
--- a/tools/memorize.py
+++ b/tools/memorize.py
@@ -4,7 +4,7 @@ from tools.helpers.tool import Tool, Response
from tools import memory_tool
class Memorize(Tool):
- def execute(self):
+ def execute(self,**kwargs):
memory_tool.process_query(self.agent, str(self.args), "save")
diff --git a/tools/memory_tool.py b/tools/memory_tool.py
index c77b57e6d..73117079d 100644
--- a/tools/memory_tool.py
+++ b/tools/memory_tool.py
@@ -8,7 +8,7 @@ from tools.helpers.print_style import PrintStyle
db: VectorDB | None = None
class Memory(Tool):
- def execute(self):
+ def execute(self,**kwargs):
#TODO separate param for memory tool result count
result = process_query(self.agent, self.args["memory"],self.args["action"], result_count=self.agent.auto_memory_count)
return Response(message="\n\n".join(result), break_loop=False)
diff --git a/tools/online_knowledge_tool.py b/tools/online_knowledge_tool.py
index 76d431664..8c30bd4ee 100644
--- a/tools/online_knowledge_tool.py
+++ b/tools/online_knowledge_tool.py
@@ -3,7 +3,7 @@ from tools.helpers import perplexity_search
from tools.helpers.tool import Tool, Response
class OnlineKnowledge(Tool):
- def execute(self):
+ def execute(self,**kwargs):
return Response(
message=process_question(self.args["question"]),
break_loop=False,
diff --git a/tools/response.py b/tools/response.py
index 805037290..e5325bc72 100644
--- a/tools/response.py
+++ b/tools/response.py
@@ -9,64 +9,12 @@ from tools.helpers.print_style import PrintStyle
class ResponseTool(Tool):
- def execute(self):
+ def execute(self,**kwargs):
# superior = self.agent.get_data("superior")
# if superior:
+ self.agent.set_data("timeout", 60)
return Response(message=self.args["text"], break_loop=True)
# else:
- def after_execution(self, response):
- pass # do add anything to the history or output
-
-
-# def execute(agent:Agent, message: str, _tools, _tool_index, timeout=15, **kwargs):
-
-# # for models that like to use multiple tools in one response, we do a little trick to help the flow
-# # if there are tools producing output before this message or any other tools after this message,
-# # this message will be sent as information only and will not stop the loop
-# # if this is the last tool in the iteration and no outputing tools we used before, we stop the loop
-# # and wait for user input
-
-
-# # tools called before this one that produce output
-# outputing_tools_before = filter_tools(
-# filters=[
-# {"name":"memory_tool","action":"load"},
-# {"name":"online_knowledge_tool"},
-# {"name":"delegation"},
-# ],
-# tools=_tools[:_tool_index]
-# )
-
-# # tools called after this one
-# other_tools_after = any(tool["name"] != kwargs["_name"] for tool in _tools[_tool_index:]) #are there other tools than messages used after this one?
-
-# agent.set_data("timeout", timeout) # set the timeout for response
-
-# #if there are other tools used, message is only for information, it does not stop the loop
-# if outputing_tools_before or other_tools_after:
-# return non_blocking_message(agent, message, timeout=timeout, **kwargs)
-# else: #if there are only messages used in this iteration, collect them into the loop result
-# return blocking_message(agent, message, timeout=timeout, **kwargs)
-
-# def blocking_message(agent:Agent, message: str, timeout=15, **kwargs):
-# agent.add_result(message)
-# return files.read_file("./prompts/fw.msg_sent.md")
-
-# def non_blocking_message(agent:Agent, message: str, timeout=15, **kwargs):
-# if agent.get_data("superior"): # add to superior messages if it is an agent
-# msg_for_user = files.read_file("./prompts/fw.msg_from_subordinate.md",name=agent.name,message=message)
-# agent.get_data("superior").append_message(msg_for_user, human=True)
-
-# # output to console
-# PrintStyle(font_color="white",background_color="#1D8348", bold=True, padding=True).print(f"{agent.name}: reponse:")
-# PrintStyle(font_color="white").print(f"{message}")
-
-# return files.read_file("./prompts/fw.msg_info_sent.md") #return message o
-
-# def filter_tools(filters, tools):
-# filtered_data = []
-# for data_item in tools:
-# if any(all(data_item.get(key) == value for key, value in filter_item.items()) for filter_item in filters):
-# filtered_data.append(data_item)
-# return filtered_data
\ No newline at end of file
+ def after_execution(self, response, **kwargs):
+ pass # do add anything to the history or output
\ No newline at end of file
diff --git a/tools/task_done.py b/tools/task_done.py
new file mode 100644
index 000000000..bea54a139
--- /dev/null
+++ b/tools/task_done.py
@@ -0,0 +1,20 @@
+from agent import Agent
+from tools.helpers import files
+from tools.helpers.print_style import PrintStyle
+
+from agent import Agent
+from tools.helpers.tool import Tool, Response
+from tools.helpers import files
+from tools.helpers.print_style import PrintStyle
+
+class TaskDone(Tool):
+
+ def execute(self,**kwargs):
+ # superior = self.agent.get_data("superior")
+ # if superior:
+ self.agent.set_data("timeout", 0)
+ return Response(message=self.args["text"], break_loop=True)
+ # else:
+
+ def after_execution(self, response, **kwargs):
+ pass # do add anything to the history or output
\ No newline at end of file
diff --git a/tools/unknown.py b/tools/unknown.py
index 45cf8aabf..47e110e79 100644
--- a/tools/unknown.py
+++ b/tools/unknown.py
@@ -2,7 +2,7 @@ from tools.helpers.tool import Tool, Response
from tools.helpers import files
class Unknown(Tool):
- def execute(self):
+ def execute(self, **kwargs):
return Response(
message=files.read_file("prompts/fw.tool_not_found.md",
tool_name=self.name,