text stringlengths 0 93.6k |
|---|
match = context_regex.search(response) |
if not match: |
return |
g = match.groups() |
self.context["resources-needed"]=g[0] |
self.context["abilities-needed"]=g[1] |
def split_objective(self): |
directive = AgentOobaVars["directives"]["Split objective directive"].replace("_MAX_TASKS_", str(AgentOobaVars["max-tasks"])) |
prompt = self.make_prompt(directive, include_objectives=True, context_objectives=True) |
response = ooba_call(prompt, self.state).strip() |
task_list_regex = re.compile('((^|\n)[\d]+\.)(.*?)(?=(\n[\d]+\..*)|($))', re.DOTALL) |
match = task_list_regex.search(response) |
task_list = [] |
while match: |
g = match.groups() |
task_list.append(g[2].strip()) |
if g[3]: |
match = task_list_regex.search(g[3]) |
else: |
break |
return task_list |
def assess_tools(self): |
for tool_name in AgentOobaVars["tools"]: |
if AgentOobaVars["tools"][tool_name]["active"]: |
tool_str = f"Tool name: {tool_name}\nTool description: {AgentOobaVars['tools'][tool_name]['desc']}" |
directive = AgentOobaVars["directives"]["Assess tool directive"].replace("_TOOL_NAME_", tool_name) |
old = self.context["resources-available"] |
self.add_resource_no_summary(f"You have the following tool available to you:\n{tool_str}") |
prompt = self.make_prompt(directive, include_objectives=True, context_resources=True) |
if 'yes' in ooba_call(prompt, self.state).strip().lower(): |
directive = AgentOobaVars["directives"]["Use tool directive"].replace("_TOOL_NAME_", tool_name) |
prompt = self.make_prompt(directive, include_objectives=True, context_resources=True) |
response = ooba_call(prompt, self.state).strip() |
negative_responses = ["i cannot", "am unable"] |
if not any([neg in response.lower() for neg in negative_responses]): |
self.context["resources-available"]=old |
return True, AgentOobaVars["tools"][tool_name]["tool"], response |
self.context["resources-available"]=old |
return False, None, None |
def prompt_objective_context(self): |
reverse_context = [] |
p_it = self |
r = self.recursion_level |
while p_it.parent: |
child = p_it |
p_it = p_it.parent |
if AgentOobaVars["expanded-context"]: |
parent_task_list_str = "\n".join([f"Objective {r-1}, Task {str(i+1)}: {p_it.tasks[i] if isinstance(p_it.tasks[i], str) else p_it.tasks[i].objective}" for i in range(len(p_it.tasks))]) |
reverse_context.append(f"We have developed the following numbered list of tasks that one must complete to achieve Objective {r-1}:\n{parent_task_list_str}\n\nThe current task that we are at among these is Objective {r-1}, Task {p_it.current_task_idx+1}. We will refer to Objective {r-1}, Task {p_it.current_task_idx+1} as Objective {r}.") |
else: |
reverse_context.append(f"In order to complete Objective {r-1}, one must complete Objective {r}. Objective {r} is: {child.objective}") |
r -= 1 |
assert r == 1 |
reverse_context.append(f"Objective 1 is: {p_it.objective}") |
reverse_context.reverse() |
return "\n".join(reverse_context) |
def add_resource(self, resource): |
i = 0 |
while get_encoded_length(resource) > (AgentOobaVars["max-context"] / 4) and i < AgentOobaVars["max-summaries"]: |
i += 1 |
docs = text_splitter.create_documents([resource]) |
summaries = [] |
for doc in docs: |
directive = AgentOobaVars["directives"]["Summarize directive"].replace("_TEXT_", doc) |
prompt = self.make_prompt(directive, include_objectives=False) |
summaries.append(ooba_call(prompt, self.state).strip()) |
resource = "\n\n".join(summaries) |
final_length = get_encoded_length(resource) |
if final_length < AgentOobaVars["max-context"]: |
if final_length > (AgentOobaVars["max-context"]/4): |
directive = AgentOobaVars["directives"]["Summarize directive"].replace("_TEXT_", resource) |
prompt = self.make_prompt(directive, include_objectives=False) |
resource = ooba_call(prompt, self.state).strip() |
self.add_resource_no_summary(resource) |
def add_resource_no_summary(self, resource): |
if not "resources-available" in self.context or self.context["resources-available"] == "None": |
self.context["resources-available"] = resource |
else: |
self.context["resources-available"] += f"\n{resource}" |
def try_objective(self): |
tool_found, tool, tool_input = self.assess_tools() |
if tool_found: |
if (AgentOobaVars["tools"][tool.name]["execute"]): |
used_tool_str = f"TOOL USED: \"{tool.name}\"\nINPUT: \"{tool_input}\"\nOUTPUT: \"{tool.run(tool_input)}\"" |
self.output.append(used_tool_str) |
if self.parent: |
self.parent.add_resource(used_tool_str) |
else: |
self.output.append(f"TOOL FOUND: \"{tool.name}\"\nINPUT: \"{tool_input}\"") |
if self.assess_model_ability(): |
response = self.do_objective() |
negative_responses = ["i cannot", "i am unable", "i'm unable"] |
if not any([neg in response.lower() for neg in negative_responses]): |
self.output.append(f"MODEL OUTPUT {response}") |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.