Skip to content

Commit

Permalink
Merge pull request #183 from Maplemx/dev
Browse files Browse the repository at this point in the history
v3.4.0.5
  • Loading branch information
Maplemx authored Nov 14, 2024
2 parents f2a45e8 + 6bd0057 commit 80cba54
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
14 changes: 8 additions & 6 deletions Agently/Agent/Agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,11 @@ def __init__(self, agent: object):
self.get_debug_status = lambda: self.agent.settings.get_trace_back("is_debug")
self.settings = RuntimeCtxNamespace(f"plugin_settings.agent_component.{ name }", self.agent.settings)

def start_workflow(self, init_inputs: dict=None, init_storage: dict={}):
if not isinstance(init_storage, dict):
raise Exception("[Workflow] Initial storage must be a dict.")
init_storage.update({ "$agent": self.agent })
return workflow.start(init_inputs, storage=init_storage)
def start_workflow(self, init_inputs: dict=None, **kwargs):
if not kwargs:
kwargs = {}
kwargs.update({ "$agent": self.agent })
return workflow.start(init_inputs, storage=kwargs)

def export(self):
return {
Expand Down Expand Up @@ -271,7 +271,9 @@ async def handle_response(response):
self.request_runtime_ctx.empty()
return self.request.response_cache["reply"]
except Exception as e:
retry_time = self.settings.get_trace_back("request.retry_times", 2)
retry_time = self.settings.get_trace_back("request.retry_times")
if not isinstance(retry_time, int):
retry_time = 0
retry_count = self.request_runtime_ctx.get_trace_back("retry_count", 0)
if retry_count >= retry_time:
self.response_generator.end()
Expand Down
15 changes: 9 additions & 6 deletions Agently/plugins/agent_component/ResponseGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ def get_complete_generator(self):
thread.start()
while True:
try:
item = self.data_queue.get_nowait()
item = self.data_queue.get()
if item == (None, None):
break
yield item
except:
continue
self.data_queue = queue.Queue()
thread.join()

def get_instant_keys_generator(self, keys):
Expand Down Expand Up @@ -53,7 +54,7 @@ def get_instant_keys_generator(self, keys):
thread.start()
while True:
try:
item = self.data_queue.get_nowait()
item = self.data_queue.get()
if item == (None, None):
break
if item[0] == "instant":
Expand All @@ -72,36 +73,38 @@ def get_instant_keys_generator(self, keys):
break
except:
continue
self.data_queue = queue.Queue()
thread.join()


def get_instant_generator(self):
self.agent.settings.set("use_instant", True)
thread = threading.Thread(target=self.agent.start)
thread.start()
while True:
try:
item = self.data_queue.get_nowait()
item = self.data_queue.get()
if item == (None, None):
break
if item[0] == "instant":
yield item[1]
except:
except Exception as e:
continue
self.data_queue = queue.Queue()
thread.join()

def get_generator(self):
thread = threading.Thread(target=self.agent.start)
thread.start()
while True:
try:
item = self.data_queue.get_nowait()
item = self.data_queue.get()
if item == (None, None):
break
if not item[0].endswith(("_origin")):
yield item
except:
continue
self.data_queue = queue.Queue()
thread.join()

def _suffix(self, event, data):
Expand Down
12 changes: 9 additions & 3 deletions Agently/plugins/agent_component/Tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,13 @@ async def call_plan_func(self, tool):
if self.is_debug():
print("[Tool Error]: ", e)
if call_result:
info_key = str(step["purpose"])
info_key = str(step["using_tool"]["tool_name"])
purpose = step["purpose"]
info_value = call_result["for_agent"] if isinstance(call_result, dict) and "for_agent" in call_result else call_result
tool_results[info_key] = info_value
tool_results[info_key] = {
"purpose": purpose,
"result": info_value
}
await self.agent.call_event_listeners(
"tool:response",
{
Expand Down Expand Up @@ -203,7 +207,9 @@ async def _prefix(self):
tool_results = await self.call_plan_func(self)
if tool_results and len(tool_results.keys()) > 0:
return {
"info": tool_results,
"info": {
"tool_using_results": tool_results,
},
"instruct": "Response according {helpful information} provided.\nProvide URL for keywords in markdown format if needed.\nIf error occured or not enough information, response you don't know honestly unless you are very sure about the answer without information support."
}
else:
Expand Down
4 changes: 2 additions & 2 deletions Agently/plugins/agent_component/YAMLLoader.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ def transform_to_agently_style(self, target: any, variables: dict={}):
return result
else:
result = str(target)
for key, value in variables.items():
result = result.replace("${" + str(key) + "}", str(value))
global_variables = self.agent.settings.get("global_variables")
if global_variables:
for key, value in global_variables.items():
result = result.replace("${" + str(key) + "}", str(value))
for key, value in variables.items():
result = result.replace("${" + str(key) + "}", str(value))
return result

def load_yaml_prompt(self, *, path:str=None, yaml:str=None, use_agently_style:bool=True, variables:dict={}):
Expand Down
10 changes: 5 additions & 5 deletions Agently/utils/RuntimeCtx.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ class RuntimeCtxNamespace(NamespaceOps):
def __init__(self, namespace_name: str, runtime_ctx: object, *, return_to: object=None):
super().__init__(namespace_name, runtime_ctx, return_to = return_to)

def get_trace_back(self, keys_with_dots: (str, None) = None, default: str=None):
def get_trace_back(self, keys_with_dots: str=None, default: str=None):
return self.data_ops.get_trace_back(f"{ self.namespace_name }.{ keys_with_dots }" if keys_with_dots else self.namespace_name, default)

def get(self, keys_with_dots: (str, None) = None, default: str=None, *, trace_back = True):
def get(self, keys_with_dots: str=None, default: str=None, *, trace_back=True):
if trace_back:
return self.get_trace_back(keys_with_dots, default)
else:
Expand All @@ -31,19 +31,19 @@ def __update_trace_back_result(self, parent_result, result):
parent_result[key] = result[key]
return parent_result

def get_trace_back(self, keys_with_dots: (str, None) = None, default: str=None):
def get_trace_back(self, keys_with_dots:str=None, default: str=None):
result = self.get(keys_with_dots, trace_back = False)
parent_result = self.parent.get_trace_back(keys_with_dots) if self.parent else None
if result or parent_result:
if isinstance(result, dict):
parent_result = parent_result if isinstance(parent_result, dict) else {}
return self.__update_trace_back_result(parent_result, result)
else:
return result if result else parent_result
return result if result is not None else parent_result
else:
return default

def get(self, keys_with_dots: (str, None) = None, default: str=None, *, trace_back = True):
def get(self, keys_with_dots: str=None, default: str=None, *, trace_back=True):
if trace_back:
return self.get_trace_back(keys_with_dots, default)
else:
Expand Down

0 comments on commit 80cba54

Please sign in to comment.