Spaces:
Paused
Paused
frdel commited on
Commit ·
c425c40
1
Parent(s): ba0986b
docker files, agent number fix, json misformat message
Browse filesFiles changed (10)
- agent.py+19-14
- docker/.bashrcAdded+9
- docker/DockerfileAdded+43
- docker/initialize.shAdded+16
- main.py+4-2
- models.py+3
- prompts/agent.tools.md+1
- prompts/fw.msg_misformat.mdAdded+5
- python/helpers/docker.py+1-1
- python/helpers/extract_tools.py+6-6
14 unmodified lines1516171819202132 unmodified lines54555657585960175 unmodified lines23623723823924024124224324424524624724824925025125225325425514 unmodified lines@dataclassclass AgentConfig:agent_number: intchat_model:BaseChatModelembeddings_model:Embeddingsmemory_subdir: str = ""32 unmodified lines# non-config varsself.number = numberself.agent_name = f"Agent {self.config.agent_number}"self.system_prompt = files.read_file("./prompts/agent.system.md").replace("{", "{{").replace("}", "}}")self.tools_prompt = files.read_file("./prompts/agent.tools.md").replace("{", "{{").replace("}", "}}")175 unmodified linesdef process_tools(self, msg: str):# search for tool usage requests in agent messagetool_request = extract_tools.json_parse_dirty(msg)tool_name = tool_request.get("tool_name", "")tool_args = tool_request.get("tool_args", {})tool = self.get_tool(tool_name,tool_args,msg)if self.handle_intervention(): return # wait if paused and handle intervention message if neededtool.before_execution(**tool_args)response = tool.execute(**tool_args)tool.after_execution(response)if response.break_loop: return response.messagedef get_tool(self, name: str, args: dict, message: str, **kwargs):14 unmodified lines15161718192032 unmodified lines53545556575859175 unmodified lines23523623723823924024124224324424524624724824925025125225325425525625725825926014 unmodified lines@dataclassclass AgentConfig:chat_model:BaseChatModelembeddings_model:Embeddingsmemory_subdir: str = ""32 unmodified lines# non-config varsself.number = numberself.agent_name = f"Agent {self.number}"self.system_prompt = files.read_file("./prompts/agent.system.md").replace("{", "{{").replace("}", "}}")self.tools_prompt = files.read_file("./prompts/agent.tools.md").replace("{", "{{").replace("}", "}}")175 unmodified linesdef process_tools(self, msg: str):# search for tool usage requests in agent messagetool_request = extract_tools.json_parse_dirty(msg)if tool_request is not None:tool_name = tool_request.get("tool_name", "")tool_args = tool_request.get("tool_args", {})tool = self.get_tool(tool_name,tool_args,msg)if self.handle_intervention(): return # wait if paused and handle intervention message if neededtool.before_execution(**tool_args)response = tool.execute(**tool_args)tool.after_execution(response)if response.break_loop: return response.messageelse:msg = files.read_file("prompts/fw.msg_misformat.md")self.append_message(msg, human=True)PrintStyle(font_color="red", padding=True).print(msg)def get_tool(self, name: str, args: dict, message: str, **kwargs):
123456789# .bashrc
# Source global definitionsif [ -f /etc/bashrc ]; then . /etc/bashrcfi
# Activate the virtual environmentsource /opt/venv/bin/activate12345678910111213141516171819202122232425262728293031323334353637383940414243# Use the latest slim version of DebianFROM --platform=$TARGETPLATFORM debian:bookworm-slim
# Set ARG for platform-specific commandsARG TARGETPLATFORM
# Update and install necessary packagesRUN apt-get update && apt-get install -y \ python3 \ python3-pip \ python3-venv \ nodejs \ npm \ openssh-server \ sudo \ && rm -rf /var/lib/apt/lists/*
# Set up SSHRUN mkdir /var/run/sshd && \ echo 'root:toor' | chpasswd && \ sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
# Create and activate Python virtual environmentENV VIRTUAL_ENV=/opt/venvRUN python3 -m venv $VIRTUAL_ENV
# Copy initial .bashrc with virtual environment activation to a temporary locationCOPY .bashrc /etc/skel/.bashrc
# Copy the script to ensure .bashrc is in the root directoryCOPY initialize.sh /usr/local/bin/initialize.shRUN chmod +x /usr/local/bin/initialize.sh
# Ensure the virtual environment and pip setupRUN $VIRTUAL_ENV/bin/pip install --upgrade pip
# Expose SSH portEXPOSE 22
# Init .bashrcCMD ["/usr/local/bin/initialize.sh"]
12345678910111213141516#!/bin/bash
# Ensure .bashrc is in the root directoryif [ ! -f /root/.bashrc ]; then cp /etc/skel/.bashrc /root/.bashrc chmod 444 /root/.bashrcfi
# Ensure .profile is in the root directoryif [ ! -f /root/.profile ]; then cp /etc/skel/.bashrc /root/.profile chmod 444 /root/.profilefi
# Start SSH serviceexec /usr/sbin/sshd -D8 unmodified lines91011121314159 unmodified lines2526272829301 unmodified line323334353637388 unmodified linesinput_lock = threading.Lock()os.chdir(files.get_abs_path("./work_dir")) #change CWD to work_dir9 unmodified lines# chat_llm = models.get_anthropic_sonnet_35(temperature=0)# chat_llm = models.get_anthropic_haiku(temperature=0)# chat_llm = models.get_ollama_dolphin()# embedding model used for memory# embedding_llm = models.get_embedding_openai()1 unmodified line# agent configurationconfig = AgentConfig(agent_number = 0,chat_model = chat_llm,embeddings_model = embedding_llm,# memory_subdir = "",8 unmodified lines910111213149 unmodified lines242526272829303132331 unmodified line3536373839408 unmodified linesinput_lock = threading.Lock()os.chdir(files.get_abs_path("./work_dir")) #change CWD to work_dir9 unmodified lines# chat_llm = models.get_anthropic_sonnet_35(temperature=0)# chat_llm = models.get_anthropic_haiku(temperature=0)# chat_llm = models.get_ollama_dolphin()# chat_llm = models.get_ollama(model_name="gemma2:27b")# chat_llm = models.get_ollama(model_name="llama3:8b-text-fp16")# chat_llm = models.get_ollama(model_name="gemma2:latest")# chat_llm = models.get_ollama(model_name="qwen:14b")# embedding model used for memory# embedding_llm = models.get_embedding_openai()1 unmodified line# agent configurationconfig = AgentConfig(chat_model = chat_llm,embeddings_model = embedding_llm,# memory_subdir = "",
67 unmodified lines68697071727367 unmodified linesapi_key = api_key or get_api_key("groq")return ChatGroq(model_name="Llama3-8b-8192", temperature=temperature, api_key=api_key) # type: ignoredef get_groq_gemma(api_key=None, temperature=DEFAULT_TEMPERATURE):api_key = api_key or get_api_key("groq")return ChatGroq(model_name="gemma-7b-it", temperature=temperature, api_key=api_key) # type: ignore67 unmodified lines68697071727374757667 unmodified linesapi_key = api_key or get_api_key("groq")return ChatGroq(model_name="Llama3-8b-8192", temperature=temperature, api_key=api_key) # type: ignoredef get_ollama(model_name, temperature=DEFAULT_TEMPERATURE):return Ollama(model=model_name,temperature=temperature)def get_groq_gemma(api_key=None, temperature=DEFAULT_TEMPERATURE):api_key = api_key or get_api_key("groq")return ChatGroq(model_name="gemma-7b-it", temperature=temperature, api_key=api_key) # type: ignore
85 unmodified lines86878889909185 unmodified linesThis tool can be used to achieve any task that requires computation, or any other software related activity.Place your code escaped and properly indented in the "code" argument.Select the corresponding runtime with "runtime" argument. Possible values are "terminal", "python" and "nodejs".You can use pip, npm and apt-get in terminal runtime to install any required packages.IMPORTANT: Never use implicit print or implicit output, it does not work! If you need output of your code, you MUST use print() or console.log() to output selected variables.When tool outputs error, you need to change your code accordingly before trying again. knowledge_tool can help analyze errors.85 unmodified lines8687888990919285 unmodified linesThis tool can be used to achieve any task that requires computation, or any other software related activity.Place your code escaped and properly indented in the "code" argument.Select the corresponding runtime with "runtime" argument. Possible values are "terminal", "python" and "nodejs".Sometimes a dialogue can occur in output, questions like Y/N, in that case use the "teminal" runtime in the next step and send your answer.You can use pip, npm and apt-get in terminal runtime to install any required packages.IMPORTANT: Never use implicit print or implicit output, it does not work! If you need output of your code, you MUST use print() or console.log() to output selected variables.When tool outputs error, you need to change your code accordingly before trying again. knowledge_tool can help analyze errors.
12345~~~json{ "system_warning": "You have misformatted your message. Follow system prompt instructions on JSON message formatting precisely."}~~~34 unmodified lines3536373839404134 unmodified lines#print(f"Container with name '{self.name}' is already running with ID: {existing_container.id}")passelse:print(f"Initializing docker container {self.name}...")self.container = self.client.containers.run(self.image,detach=True,34 unmodified lines3536373839404134 unmodified lines#print(f"Container with name '{self.name}' is already running with ID: {existing_container.id}")passelse:print(f"Initializing docker container {self.name} for safe code execution...")self.container = self.client.containers.run(self.image,detach=True,
5 unmodified lines6789101112131415161718192021225 unmodified linesimport regexdef json_parse_dirty(json:str) -> dict[str,Any]:ext_json = extract_json_object_string(json)# ext_json = fix_json_string(ext_json)data = DirtyJson.parse_string(ext_json)if isinstance(data,dict): return datareturn {}def extract_json_object_string(content):start = content.find('{')if start == -1:print("No JSON content found.")return ""# Find the first '{'5 unmodified lines6789101112131415161718192021225 unmodified linesimport regexdef json_parse_dirty(json:str) -> dict[str,Any] | None:ext_json = extract_json_object_string(json)if ext_json:# ext_json = fix_json_string(ext_json)data = DirtyJson.parse_string(ext_json)if isinstance(data,dict): return datareturn Nonedef extract_json_object_string(content):start = content.find('{')if start == -1:return ""# Find the first '{'
agent.py+19-14
docker/.bashrcAdded+9
docker/DockerfileAdded+43
docker/initialize.shAdded+16
main.py+4-2
models.py+3
prompts/agent.tools.md+1
prompts/fw.msg_misformat.mdAdded+5
python/helpers/docker.py+1-1
python/helpers/extract_tools.py+6-6