microsoft / autogen

A programming framework for agentic AI 🤖
https://microsoft.github.io/autogen/
Creative Commons Attribution 4.0 International
31.52k stars 4.58k forks source link

[Bug]: When i use multi-agent to solve problems,therr is the error:"AttributeError: 'NoneType' object has no attribute 'prompt_tokens' " #1002

Closed safa1018 closed 9 months ago

safa1018 commented 9 months ago

Describe the bug

`

llm_config = { "cache_seed": 42, # change the cache_seed for different trials "temperature": 0, "config_list": config_list, "timeout": 120, "functions":[ { "name": "get_account_id", "description": "retrieves the account id for a user given their name", "parameters": { "type": "object", "properties": { "name":{ "type": "string", "description": "The name of the customer that will be used to lookup the account id" } }, "required": ["name"] } }, { "name": "get_last_bill_amount", "description": "Retrieves the last bill amount for a user for a given account id.", "parameters": { "type": "object", "properties": { "account_id":{ "type": "string", "description": "The account id fetched from get_account_id that will be used to lookup the last bill for the customer" } }, "required": ["account_id"] } } ] }

nofunction_llm_config = { "cache_seed": 42, # change the cache_seed for different trials "temperature": 0, "config_list": config_list, "timeout": 120,

}

name_to_account_id = { "Alice": "A123", "Bob": "B456", "Charlie": "C789" }

account_id_to_bill = { "A123": 120.50, "B456": 200.75, "C789": 99.99 }

def get_account_id(name): print("--------------------") print(name_to_account_id.get(name, "Name not found")), return name_to_account_id.get(name, "Name not found")

def get_last_bill_amount(account_id): return account_id_to_bill.get(account_id, "Account ID not found")

user_proxy = autogen.UserProxyAgent( name="user_proxy", system_message="A human user_proxy. 如果你的问题需要执行工具(比如执行函数、请求接口)才能解决,去找task_executor去执行", code_execution_config=False, human_input_mode="TERMINATE",

max_consecutive_auto_reply=3,

# is_termination_msg=lambda x: x.get("content", "") and x.get("content", "").rstrip().endswith("TERMINATE"),
llm_config=nofunction_llm_config,

)

knowledge_responsor = autogen.AssistantAgent( name="knowledge_responsor", system_message=''' 当user_proxy交给你的问题你能解决时,你来负责回复他答案。你的知识如下 { ”tws是一款田所在公司的游戏“ ”tws所在公司还有一个项目叫小智助手“ } ''', human_input_mode="NEVER", max_consecutive_auto_reply=10, llm_config=nofunction_llm_config,

)

task_executor = autogen.AssistantAgent( name="task_executor", llm_config=llm_config,

system_message="""
task_executor. 解决user_proxy发来的执行工具的诉求。
""",
human_input_mode="NEVER",
max_consecutive_auto_reply=10,

)

groupchat = autogen.GroupChat( agents=[user_proxy, knowledge_responsor,task_executor], messages=[], max_round=50, func_call_filter=True,

)

manager = autogen.GroupChatManager( groupchat=groupchat, llm_config=nofunction_llm_config, max_consecutive_auto_reply=20, human_input_mode="NEVER", system_message=""" Group chat manager. 当用户发起问题时,你需要先判断他的意图,根据他的意图决定他的问题交给谁来回复。 如果他的意图需要执行工具(比如执行函数、请求接口)才能解决,你就告诉user_proxy,让他去找task_executor去执行。 如果他的意图是”询问问题,需要对应的知识回复“,你就交给knowledge_responsor让他回复;

如果他的意图knowledge_responsor和task_executor都无法解决,你就返回“对不起,当前我暂无法解决你的问题,你可以尝试转人工”
""",

)

for agent in [user_proxy,knowledge_responsor]:

register functions for all agents.

    agent.register_function(
        function_map={
            "get_account_id": get_account_id,
            "get_last_bill_amount": get_last_bill_amount,
        }
    )

user_proxy.initiate_chat(manager,message="我是Bob,我的账号余额是多少")

user_proxy.initiate_chat(manager,message="我是Bob,我的账户余额还有多少",clear_history=True,silent=True,) `

Steps to reproduce

here is the error:

Traceback (most recent call last): File "C:\Users\safa\PycharmProjects\pythonProject1\function_call+rag.py", line 202, in user_proxy.initiate_chat(manager,message="我是Bob,我的账户余额还有多少",clear_history=True,silent=True,) File "C:\Users\safa\AppData\Roaming\Python\Python310\site-packages\autogen\agentchat\conversable_agent.py", line 556, in initiate_chat self.send(self.generate_init_message(**context), recipient, silent=silent) File "C:\Users\safa\AppData\Roaming\Python\Python310\site-packages\autogen\agentchat\conversable_agent.py", line 354, in send recipient.receive(message, self, request_reply, silent) File "C:\Users\safa\AppData\Roaming\Python\Python310\site-packages\autogen\agentchat\conversable_agent.py", line 487, in receive reply = self.generate_reply(messages=self.chat_messages[sender], sender=sender) File "C:\Users\safa\AppData\Roaming\Python\Python310\site-packages\autogen\agentchat\conversable_agent.py", line 962, in generate_reply final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"]) File "C:\Users\safa\AppData\Roaming\Python\Python310\site-packages\autogen\agentchat\groupchat.py", line 340, in run_chat reply = speaker.generate_reply(sender=self) File "C:\Users\safa\AppData\Roaming\Python\Python310\site-packages\autogen\agentchat\conversable_agent.py", line 962, in generate_reply final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"]) File "C:\Users\safa\AppData\Roaming\Python\Python310\site-packages\autogen\agentchat\conversable_agent.py", line 631, in generate_oai_reply response = client.create( File "C:\Users\safa\AppData\Roaming\Python\Python310\site-packages\autogen\oai\client.py", line 272, in create self._update_usage_summary(response, use_cache=False) File "C:\Users\safa\AppData\Roaming\Python\Python310\site-packages\autogen\oai\client.py", line 372, in _update_usage_summary self.total_usage_summary = update_usage(self.total_usage_summary) File "C:\Users\safa\AppData\Roaming\Python\Python310\site-packages\autogen\oai\client.py", line 364, in update_usage

进程已结束,退出代码1

Expected Behavior

No response

Screenshots and logs

image

Additional Information

python 3.10.9

afourney commented 9 months ago

This looks like #984.

I think @kevin666aa is working on this.