improvement: tweak monitor module in agentUniverse.

This commit is contained in:
wangchongshi
2024-08-14 10:14:28 +08:00
parent b76b7d29ad
commit 53cd289ce0
5 changed files with 22 additions and 15 deletions

View File

@@ -99,7 +99,7 @@ class Monitor(BaseModel):
"""Initialize the invocation chain in the framework context."""
Monitor.init_trace_id()
trace_id = FrameworkContextManager().get_context('trace_id')
if FrameworkContextManager().get_context(trace_id) is None:
if FrameworkContextManager().get_context(trace_id + '_invocation_chain') is None:
FrameworkContextManager().set_context(trace_id + '_invocation_chain', [])
@staticmethod
@@ -108,7 +108,6 @@ class Monitor(BaseModel):
trace_id = FrameworkContextManager().get_context('trace_id')
if trace_id is not None:
FrameworkContextManager().del_context(trace_id + '_invocation_chain')
FrameworkContextManager().del_context('trace_id')
@staticmethod
def add_invocation_chain(source: dict):
@@ -136,7 +135,7 @@ class Monitor(BaseModel):
"""Initialize the token usage in the framework context."""
Monitor.init_trace_id()
trace_id = FrameworkContextManager().get_context('trace_id')
if FrameworkContextManager().get_context(trace_id) is None:
if FrameworkContextManager().get_context(trace_id + '_token_usage') is None:
FrameworkContextManager().set_context(trace_id + '_token_usage', {})
@staticmethod
@@ -147,9 +146,10 @@ class Monitor(BaseModel):
trace_id = FrameworkContextManager().get_context('trace_id')
if trace_id is not None:
old_token_usage: dict = FrameworkContextManager().get_context(trace_id + '_token_usage')
for key, value in cur_token_usage.items():
old_token_usage[key] = old_token_usage[key] + value if key in old_token_usage else value
FrameworkContextManager().set_context(trace_id + '_token_usage', old_token_usage)
if old_token_usage is not None:
for key, value in cur_token_usage.items():
old_token_usage[key] = old_token_usage[key] + value if key in old_token_usage else value
FrameworkContextManager().set_context(trace_id + '_token_usage', old_token_usage)
@staticmethod
def clear_token_usage():

View File

@@ -27,10 +27,16 @@ def update_nested_yaml_value(config_path, updates) -> None:
for path, new_value in updates.items():
keys = path.split('.')
d = config_data
for key in keys[:-1]:
d = d[key]
# modify the value of the target key
d[keys[-1]] = new_value
try:
for key in keys[:-1]:
if key not in d:
raise KeyError(f"Key '{key}' not found in the configuration")
d = d[key]
if keys[-1] in d:
# modify the value of the target key
d[keys[-1]] = new_value
except Exception as e:
print(f"Skipping update for '{path}': {e}")
# write the modified content back to the YAML file
with open(config_path, 'w', encoding='utf-8') as file:

View File

@@ -3,8 +3,8 @@ nickname: peer多智能体组
opening_speech: |
您好欢迎使用PEER多智能体协同范式根据您提出的问题我将通过Planning智能体拆解问题Executing智能体逐个执行子问题Expressing智能体总结任务执行结果Reviewing智能体评估及反馈最终给您提供满意的答案。
你可以这样问我:
问题1: 英伟达股票还能买吗
问题2: 巴菲特为什么减持苹果股票
问题1: 英伟达股票还能买吗?
问题2: 巴菲特为什么减持苹果股票?
type: AGENT
avatar: ../../../resources/peer_agent_logo.png
metadata:

View File

@@ -1,10 +1,10 @@
id: demo_rag_agent
nickname: rag智能体
type: AGENT
opening_speech: |
opening_speech: |
欢迎使用rag chatbot根据您的提问我将结合实时信息及我个人掌握的知识给您提供合理的解答。
你可以这样问我:
问题1: 巴黎奥运会美国男篮队员都有谁
问题1: 巴黎奥运会中国获得了几块奖牌
问题2: 巴菲特为什么减持苹果股票
avatar: ../../../resources/rag_agent_logo.png
metadata:

View File

@@ -3,7 +3,8 @@ nickname: ReAct智能体
opening_speech: |
欢迎使用ReAct智能体根据您预先配置好的工具集结合您的提问我将进行自治的推理并采取行动最终给您提供满意的答案。
你可以这样问我:
问题: 请给出一段python代码可以计算三数之和给出之前必须验证代码是否可以运行最少验证1次
问题1: 请给出一段python代码可以计算三数之和给出之前必须验证代码是否可以运行最少验证1次
问题2: 你有多少种工具可以用?
type: AGENT
avatar: ../../../resources/react_agent_logo.png
metadata: