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 lines1516171818192032 unmodified lines5354555756575859175 unmodified lines23523623723924023823924024124224224324424524324424524624724824924724824925025125225025125225325425525625725825926014 unmodified lines
@dataclassclass AgentConfig: agent_number: int chat_model:BaseChatModel embeddings_model:Embeddings memory_subdir: str = ""32 unmodified lines
# non-config vars self.number = number self.agent_name = f"Agent {self.config.agent_number}" self.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 lines def process_tools(self, msg: str): # search for tool usage requests in agent message tool_request = extract_tools.json_parse_dirty(msg) tool_name = tool_request.get("tool_name", "") tool_args = tool_request.get("tool_args", {})
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) tool = self.get_tool( tool_name, tool_args, msg) if self.handle_intervention(): return # wait if paused and handle intervention message if needed if self.handle_intervention(): return # wait if paused and handle intervention message if needed tool.before_execution(**tool_args) response = tool.execute(**tool_args) tool.after_execution(response) if response.break_loop: return response.message tool.before_execution(**tool_args) response = tool.execute(**tool_args) tool.after_execution(response) if response.break_loop: return response.message else: 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 lines91011121213149 unmodified lines242526272829303132331 unmodified line353637353839408 unmodified lines
input_lock = threading.Lock()
os.chdir(files.get_abs_path("./work_dir")) #change CWD to work_dir
9 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 configuration config = AgentConfig( agent_number = 0, chat_model = chat_llm, embeddings_model = embedding_llm, # memory_subdir = "",67 unmodified lines68697071727374757667 unmodified lines api_key = api_key or get_api_key("groq") return ChatGroq(model_name="Llama3-8b-8192", temperature=temperature, api_key=api_key) # type: ignore
def 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: ignore85 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 lines353637383839404134 unmodified lines #print(f"Container with name '{self.name}' is already running with ID: {existing_container.id}") pass else: print(f"Initializing docker container {self.name}...") print(f"Initializing docker container {self.name} for safe code execution...") self.container = self.client.containers.run( self.image, detach=True,5 unmodified lines678991011111213141213141516171819192021225 unmodified linesimport regex
def json_parse_dirty(json:str) -> dict[str,Any]:def 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 data return {} # ext_json = fix_json_string(ext_json) data = DirtyJson.parse_string(ext_json) if isinstance(data,dict): return data return None
def extract_json_object_string(content): start = content.find('{') if start == -1: print("No JSON content found.") 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