mirror of
https://github.com/agentuniverse-ai/agentUniverse.git
synced 2026-02-09 01:59:19 +08:00
improvement: tweak monitor module in agentUniverse.
This commit is contained in:
@@ -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():
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -3,7 +3,8 @@ nickname: ReAct智能体
|
||||
opening_speech: |
|
||||
欢迎使用ReAct智能体!根据您预先配置好的工具集,结合您的提问,我将进行自治的推理并采取行动,最终给您提供满意的答案。
|
||||
你可以这样问我:
|
||||
问题: 请给出一段python代码,可以计算三数之和,给出之前必须验证代码是否可以运行,最少验证1次
|
||||
问题1: 请给出一段python代码,可以计算三数之和,给出之前必须验证代码是否可以运行,最少验证1次
|
||||
问题2: 你有多少种工具可以用?
|
||||
type: AGENT
|
||||
avatar: ../../../resources/react_agent_logo.png
|
||||
metadata:
|
||||
|
||||
Reference in New Issue
Block a user