SSH output cleanup, delegation fix

frdel committed Jul 7, 2024 at 14:28 UTC 281061f351f06ecdd47da04c6185cfad4d79700d
3 files changed +22 -12
main.py
+2 -2
@@ -18,11 +18,11 @@ def initialize():
18 # chat_llm = models.get_groq_llama70b(temperature=0.2)
19 # chat_llm = models.get_groq_llama70b_json(temperature=0.2)
20 # chat_llm = models.get_groq_llama8b(temperature=0.2)
21 - # chat_llm = models.get_openai_gpt35(temperature=0)
21 + chat_llm = models.get_openai_gpt35(temperature=0)
22 # chat_llm = models.get_openai_gpt4o(temperature=0)
23 # chat_llm = models.get_anthropic_opus(temperature=0)
24 # chat_llm = models.get_anthropic_sonnet(temperature=0)
25 - chat_llm = models.get_anthropic_sonnet_35(temperature=0)
25 + # chat_llm = models.get_anthropic_sonnet_35(temperature=0)
26 # chat_llm = models.get_anthropic_haiku(temperature=0)
27 # chat_llm = models.get_ollama_dolphin()
28
python/helpers/shell_ssh.py
+19 -6
@@ -4,6 +4,11 @@ import re
4 from typing import Optional, Tuple
5
6 class SSHInteractiveSession:
7 +
8 + end_comment = "# @@==>> SSHInteractiveSession End-of-Command <<==@@"
9 +
10 + ps1_label = "SSHInteractiveSession CLI>"
11 +
12 def __init__(self, hostname: str, port: int, username: str, password: str):
13 self.hostname = hostname
14 self.port = port
@@ -20,11 +25,13 @@ class SSHInteractiveSession:
25 while True:
26 try:
27 self.client.connect(self.hostname, self.port, self.username, self.password)
23 - self.shell = self.client.invoke_shell()
24 - while True: # wait for end of initial output
25 - full, part = self.read_output()
26 - if full and not part: return
27 - time.sleep(0.1)
28 + self.shell = self.client.invoke_shell(width=160,height=48)
29 + # self.shell.send(f'PS1="{SSHInteractiveSession.ps1_label}"'.encode())
30 + return
31 + # while True: # wait for end of initial output
32 + # full, part = self.read_output()
33 + # if full and not part: return
34 + # time.sleep(0.1)
35 except Exception as e:
36 errors += 1
37 if errors < 3:
@@ -43,7 +50,7 @@ class SSHInteractiveSession:
50 if not self.shell:
51 raise Exception("Shell not connected")
52 self.full_output = ""
46 - self.shell.send((command + '\n').encode())
53 + self.shell.send((command + " \\\n" +SSHInteractiveSession.end_comment + "\n").encode())
54
55 def read_output(self) -> Tuple[str, str]:
56 if not self.shell:
@@ -58,6 +65,12 @@ class SSHInteractiveSession:
65 time.sleep(0.1) # Prevent busy waiting
66
67 self.full_output = self.clean_string(self.full_output)
68 +
69 + # split output at end_comment
70 + if SSHInteractiveSession.end_comment in self.full_output:
71 + self.full_output = self.full_output.split(SSHInteractiveSession.end_comment)[-1].lstrip("\r\n")
72 + partial_output = partial_output.split(SSHInteractiveSession.end_comment)[-1].lstrip("\r\n")
73 +
74 return self.full_output, partial_output
75
76 def clean_string(self, input_string):
python/tools/call_subordinate.py
+1 -4
@@ -8,10 +8,7 @@ class Delegation(Tool):
8 def execute(self, message="", reset="", **kwargs):
9 # create subordinate agent using the data object on this agent and set superior agent to his data object
10 if self.agent.get_data("subordinate") is None or str(reset).lower().strip() == "true":
11 - # subordinate = Agent(system_prompt=self.agent.system_prompt, tools_prompt=self.agent.tools_prompt, number=self.agent.number+1)
12 - config = self.agent.__dict__.copy()
13 - config["agent_number"] = self.agent.number+1
14 - subordinate = Agent(**config)
11 + subordinate = Agent(self.agent.number+1, self.agent.config)
12 subordinate.set_data("superior", self.agent)
13 self.agent.set_data("subordinate", subordinate)
14 # run subordinate agent message loop