microsoft / autogen

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

[Issue]: GPT agent >>>>>>>> EXECUTING FUNCTION nonstop #1136

Open kuanlinhuang opened 8 months ago

kuanlinhuang commented 8 months ago

Describe the issue

I wrote a function that mapped to a GPT assistant successfully. However, when executing the code, I just get >>>>>>>> EXECUTING FUNCTION nonstop. Could you help me see how I can stop this behavior?

def search_pubmed(query, top_n=10): ... ... (happy to provide the code block if needed, basically call PubMed API)

# Create researcher agent
Pubmed_Researcher = GPTAssistantAgent(
    name="Pubmed_Researcher",
    llm_config={
        "config_list": config_list,
        "assistant_id": "asst_XXXXX"
    }
)

# create a UserProxyAgent instance named "user_proxy"
user_proxy = autogen.UserProxyAgent(
    name="User_proxy",
    code_execution_config={"last_n_messages": 2, "work_dir": "coding"},
    is_termination_msg=lambda x: x["content"] == "TERMINATE",
    default_auto_reply="TERMINATE",
)

# Register functions for assistant and user proxy
Pubmed_Researcher.register_function(
        function_map={
            "search_pubmed": search_pubmed,
        }
    )

task1 = """
write a report on the use of LLM in prediction of genome variant functions based on articles found on pubmed
"""

user_proxy.initiate_chat(Pubmed_Researcher, message=task1)

However, all I get in my output is

User_proxy (to Pubmed_Researcher):

write a report on the use of LLM in prediction of genome variant functions based on articles found on pubmed

--------------------------------------------------------------------------------

>>>>>>>> EXECUTING FUNCTION search_pubmed...

>>>>>>>> EXECUTING FUNCTION search_pubmed...

>>>>>>>> EXECUTING FUNCTION search_pubmed...

>>>>>>>> EXECUTING FUNCTION search_pubmed...

>>>>>>>> EXECUTING FUNCTION search_pubmed...

>>>>>>>> EXECUTING FUNCTION search_pubmed...

... ...

Steps to reproduce

No response

Screenshots and logs

No response

Additional Information

No response

rickyloynd-microsoft commented 8 months ago

What LLM are you using? Have you been able to run this notebook successfully?

kuanlinhuang commented 8 months ago

Thank you @rickyloynd-microsoft

I can run the notebook successfully.

For my openai assistant, I have tried both gpt-4 and gpt-4-1106_preview

Here is its instruction

You are a world class researcher, who can do detailed research on any topic and produce facts based results; you do not make things up, you will try as hard as possible to gather facts & data to back up the research

Please make sure you complete the objective above with the following rules:
1/ You should do one pubmed research to gather as much information as possible about the objective. Wait 20 seconds for response after doing a PubMed search query. 
2/ If there are url of relevant links & articles, you will gather all relevant information
3/ In the final output, You should include all reference data & links to back up your research; You should include all reference data & links to back up your research
rickyloynd-microsoft commented 8 months ago

Have you tried submitting this instruction to the assistant through the openai playground?

kuanlinhuang commented 8 months ago

Yes that's what I am doing

kuanlinhuang commented 8 months ago

If it may help, the function in the openai playground is defined as

{
  "name": "search_pubmed",
  "description": "[pubmed] search to return results of search keywords",
  "parameters": {
    "type": "object",
    "properties": {
      "search_keyword": {
        "type": "string",
        "description": "A great search keyword that most likely to return result for the information you are looking for"
      }
    },
    "required": [
      "search_keyword"
    ]
  }
}

And in my notebook is defined as


def search_pubmed(query, top_n=10):
    url = "https://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi"
    params = {
        "db": "pubmed",
        "term": query,
        "retmode": "json",
        "sort": "relevance",
        "retmax": top_n
    }
    response = requests.get(url, params=params)
    if response.status_code == 200:
        search_results = response.json()
        pmid_list = search_results["esearchresult"].get("idlist", [])
        if pmid_list:
            abstracts = fetch_abstracts(pmid_list)
            return pmid_list, abstracts
        else:
            return None, "No results found."
    else:
        print(f"Failed to retrieve data: {response.status_code}")
        return None, None```
gagb commented 5 months ago

@kuanlinhuang was this issue resolved. Does it happen with the current version of AutoGen? Sorry for missing it.

qingyun-wu commented 2 months ago

Hi @kuanlinhuang was this issue resolved? Thank you!