microsoft / autogen

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

AttributeError: 'AssistantAgent' object has no attribute 'register_for_llm'. Did you mean: 'register_reply'? #2681

Open YinSonglin1997 opened 5 months ago

YinSonglin1997 commented 5 months ago

Describe the issue

Ask what version of pyautogen will support 'register_for_llm' later, because I'm using the local model chatGLM, needs openai<1, so I use pyautogen==0.1.14, but reports an error: AttributeError: 'AssistantAgent' object has no attribute 'register_for_llm'. Did you mean: 'register_reply'?

Steps to reproduce

import autogen
from typing import Literal
from pydantic import BaseModel, Field
from typing_extensions import Annotated

# 1、建立必要配置
config_list = [
    {
        "model": "chatglm2-6b",
        "api_base": "http://localhost:8002/v1",
        "api_type": "open_ai",
        "api_key": "NULL",
    }]

# 2、大模型请求配置
llm_config = {
    "request_timeout": 600,
    "seed": 45,  # change the seed for different trials
    "config_list": config_list,
    "temperature": 0,
    "max_tokens":8192,
}

# 3、新建一个助理智能体
assistant = autogen.AssistantAgent(
    name="assistant",
    llm_config=llm_config,
    system_message="For currency exchange tasks, only use the functions you have been provided with. Reply TERMINATE when the task is done."
)

#创建名为 user_proxy 的用户代理实例,这里定义为进行干预
user_proxy = autogen.UserProxyAgent(
    name="user_proxy",
    human_input_mode="NEVER",
    max_consecutive_auto_reply=10,
    is_termination_msg=lambda x: x.get("content", "").rstrip().endswith("TERMINATE"),
    code_execution_config={"work_dir":"_output", "use_docker":False},
    llm_config=llm_config,
)

CurrencySymbol = Literal["USD", "EUR"]
def exchange_rate(base_currency: CurrencySymbol, quote_currency: CurrencySymbol) -> float:
    if base_currency == quote_currency:
        return 1.0
    elif base_currency == "USD" and quote_currency == "EUR":
        return 1 / 1.1
    elif base_currency == "EUR" and quote_currency == "USD":
        return 1.1
    else:
        raise ValueError(f"Unknown currencies {base_currency}, {quote_currency}")

@assistant.register_for_llm(description="Currency exchange calculator.")
@user_proxy.register_for_execution()
def currency_calculator(
base_amount: Annotated[float, "Amount of currency in base_currency"],
base_currency: Annotated[CurrencySymbol, "Base currency"] = "USD",
quote_currency: Annotated[CurrencySymbol, "Quote currency"] = "EUR",
) -> str:
    quote_amount = exchange_rate(base_currency, quote_currency) * base_amount
    return f"{quote_amount} {quote_currency}"

task1 = """How much is 123.45 USD in EUR?"""
user_proxy.initiate_chat(assistant,message=task1)

Screenshots and logs

Traceback (most recent call last):
  File "/ldata/llms/autogen/ZY/test.py", line 59, in <module>
    @assistant.register_for_llm(description="Currency exchange calculator.")
AttributeError: 'AssistantAgent' object has no attribute 'register_for_llm'. Did you mean: 'register_reply'?

Additional Information

No response

ekzhu commented 5 months ago

Odd. Which pyautogen version are you using?

YinSonglin1997 commented 5 months ago

Odd. Which pyautogen version are you using?

I have tried 0.1.14 and 0.2.3 ,the problem same.