aiwaves-cn / agents

An Open-source Framework for Data-centric, Self-evolving Autonomous Language Agents
Apache License 2.0
5.15k stars 403 forks source link

assert engine_name in WebSearchComponent.__ENGINE_NAME__ > AssertionError #151

Closed wodecki closed 10 months ago

wodecki commented 10 months ago

My config.json looks like:

{
    "config": {
        "API_KEY": "sk-mAPN8QMPJKY56xifrpT3BlbkFJCxEKRHRBMfMtNWFALpoq",
        "PROXY": "",
        "API_BASE": "",
        "MAX_CHAT_HISTORY": "1000",
        "User_Names": "[\"alexander\"]"
    },
    "WebSearchComponent": {
        "engine_name": "google",
        "api": {
            "google": {
                "cse_id": "94ecfac400840f5",
                "api_key": "AIzaSyWP6l-rxAHsV6VFs-mZUPBAhZBOSq-Ck"
            },
            "bing": "Your bing key"
        }
    },
    "LLM_type": "OpenAI",
    ...

cse_id and api_key are correct: I tested them in a separate script.

I call it with python run.py --agent config.json and get:

File "/Users/wodecki/anaconda3/envs/aiagents/lib/python3.10/site-packages/agents/State.py", line 123, in init_components
    component_dict["WebSearchComponent"] = WebSearchComponent(
  File "/Users/wodecki/anaconda3/envs/aiagents/lib/python3.10/site-packages/agents/Component/ToolComponent.py", line 184, in __init__
    assert engine_name in WebSearchComponent.__ENGINE_NAME__
AssertionError

Any idea why?

jianghuyihei commented 10 months ago

My config.json looks like:

{
    "config": {
        "API_KEY": "sk-mAPN8QMPJKY56xifrpT3BlbkFJCxEKRHRBMfMtNWFALpoq",
        "PROXY": "",
        "API_BASE": "",
        "MAX_CHAT_HISTORY": "1000",
        "User_Names": "[\"alexander\"]"
    },
    "WebSearchComponent": {
        "engine_name": "google",
        "api": {
            "google": {
                "cse_id": "94ecfac400840f5",
                "api_key": "AIzaSyWP6l-rxAHsV6VFs-mZUPBAhZBOSq-Ck"
            },
            "bing": "Your bing key"
        }
    },
    "LLM_type": "OpenAI",
    ...

cse_id and api_key are correct: I tested them in a separate script.

I call it with python run.py --agent config.json and get:

File "/Users/wodecki/anaconda3/envs/aiagents/lib/python3.10/site-packages/agents/State.py", line 123, in init_components
    component_dict["WebSearchComponent"] = WebSearchComponent(
  File "/Users/wodecki/anaconda3/envs/aiagents/lib/python3.10/site-packages/agents/Component/ToolComponent.py", line 184, in __init__
    assert engine_name in WebSearchComponent.__ENGINE_NAME__
AssertionError

Any idea why?

You can check line 174 of the code in agents/component/toolcomponent to see_ ENGINE NAME__ Is the setting correct

wodecki commented 10 months ago

It looks like this:

class WebSearchComponent(ToolComponent):
    """search engines"""

    __ENGINE_NAME__: List = ["google", "bing", "serpapi"]
callanwu commented 10 months ago

maybe your json format has some problems, you can refer to https://github.com/aiwaves-cn/agents/blob/master/examples/Single_Agent/customer_service/customer_websearch.json

wodecki commented 10 months ago

I started with this json (https://github.com/aiwaves-cn/agents/blob/master/examples/Single_Agent/customer_service/customer_websearch.json), but it generates the same error.

Thus, I followed the recommendation from https://github.com/aiwaves-cn/agents/tree/master/examples#2-single-agent%EF%B8%8F: Note that if you want to use WebSearchComponent, you also need set the config!

 "WebSearchComponent": {
                        "engine_name": "bing",
                        "api": {
                            "google": {
                                "cse_id": "Your cse_id",
                                "api_key": "Your api_key"
                            },
                            "bing": "Your bing key"
                        }
                    }

And it results with the same error again.

wodecki commented 10 months ago

debug: when i printout engine_name from the WebSearchComponent class:

class WebSearchComponent(ToolComponent):
    """search engines"""

    __ENGINE_NAME__: List = ["google", "bing", "serpapi"]

    def __init__(self, engine_name: str, api: Dict):
        """
        :param engine_name: The name of the search engine used
        :param api: Pass in a dictionary, such as {"bing":"key1", "google":"key2", ...}, of course each value can also be a list, or more complicated
        """
        super(WebSearchComponent, self).__init__()
        """Determine whether the key and engine_name of the api are legal"""
        print("engine_name from the component:", engine_name) # <<< printout here
        assert engine_name in WebSearchComponent.__ENGINE_NAME__

I get: engine_name from the component: bing or google or serpapi

callanwu commented 10 months ago

"WebSearchComponent": { "engine_name": "google", "api": { "google": { "cse_id": "", "api_key": "" } } } @wodecki hi, i use the above key-value to https://github.com/aiwaves-cn/agents/blob/48526f8e4e4ea7cf39ef0c1b34e064e382666686/examples/Single_Agent/customer_service/customer_websearch.json#L68, it can work.

callanwu commented 10 months ago

debug: when i printout engine_name from the WebSearchComponent class:

class WebSearchComponent(ToolComponent):
    """search engines"""

    __ENGINE_NAME__: List = ["google", "bing", "serpapi"]

    def __init__(self, engine_name: str, api: Dict):
        """
        :param engine_name: The name of the search engine used
        :param api: Pass in a dictionary, such as {"bing":"key1", "google":"key2", ...}, of course each value can also be a list, or more complicated
        """
        super(WebSearchComponent, self).__init__()
        """Determine whether the key and engine_name of the api are legal"""
        print("engine_name from the component:", engine_name) # <<< printout here
        assert engine_name in WebSearchComponent.__ENGINE_NAME__

I get: engine_name from the component: bing or google or serpapi

that means "google" is not loaded, "bing or google or serpapi" is loaded, you can check your json

wodecki commented 10 months ago

Super :) Now it works: I thought I should set a WebSearchComponent in the config part, but it should be in the agent_states part... Now it works.

Is it possible to set it on top of the config, to be a "universal" configuration for all the agent_states?

callanwu commented 10 months ago

We believe that the capability of the tool usage should belong to an individual agent, which is why we set it this way:)