forked from frdel/agent-zero
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
multi-tool xml parser + tool superclass
- Loading branch information
Showing
16 changed files
with
262 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
from agent import Agent | ||
from tools.helpers.tool import Tool, Response | ||
from tools.helpers import files | ||
from tools.helpers.print_style import PrintStyle | ||
|
||
def execute(agent:Agent, message: str, reset: str = "false", **kwargs): | ||
# create subordinate agent using the data object on this agent and set superior agent to his data object | ||
if agent.get_data("subordinate") is None or reset.lower().strip() == "true": | ||
subordinate = Agent(system_prompt=agent.system_prompt, tools_prompt=agent.tools_prompt, number=agent.number+1) | ||
subordinate.set_data("superior", agent) | ||
agent.set_data("subordinate", subordinate) | ||
# run subordinate agent message loop | ||
return agent.get_data("subordinate").message_loop(message) | ||
class Unknown(Tool): | ||
|
||
def execute(self): | ||
# 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": | ||
subordinate = Agent(system_prompt=self.agent.system_prompt, tools_prompt=self.agent.tools_prompt, number=self.agent.number+1) | ||
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.content) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from abc import abstractmethod | ||
from typing import TypedDict | ||
from agent import Agent | ||
from tools.helpers.print_style import PrintStyle | ||
from tools.helpers import files | ||
|
||
class Response: | ||
def __init__(self, message: str, stop_tool_processing: bool, break_loop: bool) -> None: | ||
self.message = message | ||
self.stop_tool_processing = stop_tool_processing | ||
self.break_loop = break_loop | ||
|
||
class Tool: | ||
|
||
def __init__(self, agent: Agent, name: str, content: str, args: dict, message: str, tools: list['Tool'], **kwargs) -> None: | ||
self.agent = agent | ||
self.name = name | ||
self.content = content | ||
self.args = args | ||
self.message = message | ||
self.tools = tools | ||
|
||
@abstractmethod | ||
def execute(self) -> Response: | ||
pass | ||
|
||
def before_execution(self): | ||
PrintStyle(font_color="#1B4F72", padding=True, background_color="white", bold=True).print(f"{self.agent.name}: Using tool {self.name}:") | ||
PrintStyle(font_color="#85C1E9").print(self.args, self.content, sep="\n") if self.args else PrintStyle(font_color="#85C1E9").print(self.content) | ||
|
||
def after_execution(self, response: Response): | ||
msg_response = files.read_file("./prompts/fw.tool_response.md", tool_name=self.name, tool_response=response.message) | ||
self.agent.append_message(msg_response, human=True) | ||
PrintStyle(font_color="#1B4F72", background_color="white", padding=True, bold=True).print(f"{self.agent.name}: Response from {self.name}:") | ||
PrintStyle(font_color="#85C1E9").print(response.message) |
Oops, something went wrong.