Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An error occurred: Error code: 500 - {'error': {'message': 'The model produced invalid content. Consider modifying your prompt if you are seeing this error persistently.', 'type': 'model_error', 'param': None, 'code': None}}[Issue]: #3247

Open
Adibahaq opened this issue Jul 29, 2024 · 3 comments · May be fixed by #3429
Assignees
Labels
0.2 Issues which were filed before re-arch to 0.4 bug Something isn't working function/tool suggestion and execution of function/tool call needs-triage

Comments

@Adibahaq
Copy link

Adibahaq commented Jul 29, 2024

Describe the issue

Hello, I am trying to use Autogen for this multiagent healthcare system. The code looks like this:

config_list = [
{
"model": "gpt-3.5-turbo-16k",
"api_key": "key",
"api_type": "openai",
}

]

llm_config = {
"timeout": 600,
"seed": 42,
"config_list": config_list,
"temperature": 0,
"max_tokens": 400,
}

Define the agents

PrimaryAG = autogen.AssistantAgent(
name="Primary_Agent",
llm_config=llm_config,
system_message="""You are an assistant that processes patient reports. Extract the following general information from the given text:

  • Patient Name
  • Age
  • Sex
  • Admission Date
  • Discharge Date

Also, identify and extract the following sections:

  • Medications
  • Past Medical History
  • Lab Results
  • Discharge Diagnosis
    """,
    code_execution_config={"work_dir": "web", "use_docker": False}
    )

CKDAG = autogen.AssistantAgent(
name="CKD_Agent",
llm_config=llm_config,
system_message="Chronic kidney disease specialist agent",
code_execution_config={"work_dir": "web", "use_docker": False}
)

HFAG = autogen.AssistantAgent(
name="HF_Agent",
llm_config=llm_config,
system_message="Heart failure specialist agent",
code_execution_config={"work_dir": "web", "use_docker": False}
)

LABAG = autogen.AssistantAgent(
name="LAB_Agent",
llm_config=llm_config,
system_message="""
You are a medical lab specialist. In a conversation when the Primary agent identifies the Lab Results from a patient report,
you analyze the informaion in that section (only that section), and provide a comprehensive and concise analysis of the patient's condition based on the lab results or tests""",
code_execution_config={"work_dir": "web", "use_docker": False}
)

MEDAG = autogen.AssistantAgent(
name="Med_Agent",
llm_config=llm_config,
system_message="""
You are a drugs and medicine specialist with extensive pharmaceutical knowledge. In a conversation when the Primary agent identifies the Medications section from a patient report, you analyze the information in that section (only that section), and provide a comprehensive and concise analysis. Include the following in your analysis:
- Verification of prescribed medications
- Potential drug interactions
- Dosage appropriateness
- Suggestions for alternative medications if necessary
- Any recommendations for monitoring or additional tests based on the medications
""",
code_execution_config={"work_dir": "web", "use_docker": False}
)

Critic = autogen.AssistantAgent(
name="Critic_Agent",
llm_config=llm_config,
system_message="You are a critic, known for your thoroughness and commitment to standards. Your task is to scrutinize answers for correctness and any harmful elements, and provide short feedback",
code_execution_config={"work_dir": "web", "use_docker": False}
)

Initialize the UserProxyAgent

user_proxy = autogen.UserProxyAgent(
name="user_proxy",
code_execution_config={"work_dir": "web", "use_docker": False},
llm_config=llm_config,
)

Function to reflect on messages

def reflection_message(messages, sender, config):
return f"Reflect and provide critique on the following answers:\n\n" + "\n".join(
f"Role: {msg['role']}\nContent: {msg['content']}" for msg in messages
)

Function to handle user input

def handle_user_input(conversation_history, user_input):
if user_input.lower() == "exit":
print("Exiting the conversation.")
return False

conversation_history.append({"role": "user", "content": user_input})

# Get the response from the Primary Agent
primary_response = user_proxy.initiate_chat(
    recipient=PrimaryAG,
    message=user_input,
    context=conversation_history,
    max_turns=1,
    summary_method="last_msg"
)

# Extract chat history from Primary Agent's response
primary_response_history = primary_response.chat_history

# Print the type of primary_response content
print(f"Type of primary_response_history: {type(primary_response_history)}")
print(f"Primary Response History: {primary_response_history}")

# Extract the content of the last message from the chat history
primary_response_content = primary_response_history[-1]['content'] if primary_response_history else ""

# Determine which agents to invoke based on the primary response content
agents_to_invoke = []
if "Lab Results" in primary_response_content:
    agents_to_invoke.append(LABAG)
if "CKD" in primary_response_content:
    agents_to_invoke.append(CKDAG)
if "Heart Failure" in primary_response_content:
    agents_to_invoke.append(HFAG)
if "Medication" in primary_response_content:
    agents_to_invoke.append(MEDAG)

# Ensure Primary Agent's response is always first
if not agents_to_invoke:
    agents_to_invoke.append(PrimaryAG)

# Register nested chats for Critic agent
group_chat = autogen.GroupChat(
    agents=agents_to_invoke,
    messages=conversation_history,
    allow_repeat_speaker=False,
    max_round=len(agents_to_invoke) + 1,
    send_introductions=True,
)

group_chat_manager = autogen.GroupChatManager(
    groupchat=group_chat,
    llm_config=llm_config,
)

response = user_proxy.initiate_chat(
    recipient=group_chat_manager,
    message=user_input,
    context=conversation_history,
    max_turns=1,
    summary_method="last_msg"
)

conversation_history.append({"role": "agent", "content": response})

# Critic agent feedback
critic_response = user_proxy.initiate_chat(
    recipient=Critic,
    message=reflection_message(conversation_history, None, None),
    context=conversation_history,
    max_turns=1,
    summary_method="last_msg"
)

conversation_history.append({"role": "critic", "content": critic_response})

print(f"Agent Response: {response}")
print(f"Critic Feedback: {critic_response}")

return True

Main conversation loop

def main():
print("Start your conversation. Type 'exit' to end.")
conversation_history = []
while True:
user_input = input("User: ")
if not handle_user_input(conversation_history, user_input):
break

if name == "main":
main()

Can anyone please tell me why I am getting this error message:
An error occurred: Error code: 500 - {'error': {'message': 'The model produced invalid content. Consider modifying your prompt if you are seeing this error persistently.', 'type': 'model_error', 'param': None, 'code': None}}

I get an output first, which looks like this:

Primary_Agent (to user_proxy):

Patient Name: Not mentioned
Age: 41 years old
Sex: Male
Admission Date: November 3, 2203
Discharge Date: November 12, 2203

Sections:

  • Medications:
    • Cefazolin
    • Methadone
    • Prednisone
    • Lovenox
    • Prilosec
    • Aspirin
    • Colace
    • Clonazepam
    • Sennekot
    • Morphine sulfate
    • Promethazine
  • Past Medical History:
    • HIV/AIDS
    • Hepatitis C
    • Hepatitis B
    • Myocardial Infarction
    • Endocarditis with grade 4 tricuspid regurgitation
    • Recurrent epididymitis
    • IV drug use on methadone
    • Asthma
    • Osteomyelitis
  • Lab Results:
    • Other body fluid: Total protein, glucose, LDH, amylase, albumin
    • Other body fluid: WBC, HCT, polys, lymphs, monos, eos, metas
    • Lactate
    • Glucose, urea, creatinine, sodium, potassium, chloride, total CO2, anion gap
    • Estimated GFR
    • CK (CPK)
    • CTropnt
    • WBC, RBC, HGB, HCT, MCV, MCH, MCHC, RDW
    • Neuts, lymphs, monos, eos, basos
    • Platelet count
    • PT, PTT, INR
  • Discharge Diagnosis:
    • Primary diagnosis: Cardiac tamponade, GI bleeding, atrial flutter
    • Secondary diagnosis: Pancytopenia, HIV/AIDS, hepatitis B and C, endocarditis with flail tricuspid valve, right heart failure, recurrent epididymitis, IV drug use on methadone, myocardial infarction, asthma, LLE medial MSSA foot abscess/osteomyelitis, gout, traumatic right AKA, PCP, anxiety and depression, PPD (+) treated with 6 months

Next speaker: LAB_Agent

LAB_Agent (to chat_manager):

Based on the lab results provided in the patient report, here is a comprehensive analysis of the patient's condition:

  1. Hematology:
  • The patient has anemia with a low hemoglobin level (9.2 g/dl) and hematocrit (28.6%). This could be due to chronic disease or blood loss from the gastrointestinal bleeding.
  • The white blood cell count (6.2) and platelet count (295) are within normal range.
  1. Chemistry:
  • The patient has slightly elevated lactate levels (3.2 mg/dl), which could indicate tissue hypoxia or impaired oxygen utilization.
  • The glucose level is elevated (126 mg/dl), indicating possible diabetes or stress-induced hyperglycemia.
  • The kidney function tests show elevated creatinine (1.8 mg/dl) and decreased estimated glomerular filtration rate (eGFR), suggesting impaired kidney function.
  • The electrolyte levels (sodium, potassium, chloride, total CO2) are within normal range.
  1. Cardiac Markers:
  • The troponin level is very low (<0.01), indicating no evidence of acute myocardial infarction.
  • CK (CPK) level is normal (29 U/L), suggesting no significant muscle damage.
  1. Coagulation:
  • The prothrombin time (PT) is slightly prolonged (15.1 seconds), indicating a mild impairment in the clotting process.
  • The partial thromboplastin time (PTT) is within normal range (38.2 seconds).
  • The international normalized ratio (INR) is slightly elevated (1.4), indicating a mild impairment in the clotting process.
  1. Other findings:
  • The pericardial fluid analysis shows elevated total protein (6.1 g/dl) and lactate dehydrogenase (LDH) levels (650 U/L), indicating inflammation or infection in the pericardium.
  • The white blood cell count in the pericardial fluid (2,122) is elevated, suggesting an inflammatory process.
  • The echocardiogram findings indicate a large pericardial effusion with signs of tamponade physiology, as well as tricuspid regurgitation and mild primary pulmonary hypertension.

Based on these results, the patient's primary diagnosis is cardiac tamponade, which is a medical emergency requiring immediate intervention. The pericardial effusion is likely the cause of the patient's symptoms of shortness of breath and chest pain. The underlying cause of the effusion needs further investigation, as no specific cause was identified in the report.

Other notable findings include anemia, possible gastrointestinal bleeding, impaired kidney function, and elevated glucose levels. These findings may require further evaluation and management.

The patient's medical history of HIV/AIDS, previous endocarditis, and tricuspid regurgitation are important factors to consider in the overall management and treatment plan.

Further monitoring of the patient's cardiac function, including regular echocardiograms, is recommended to assess for fluid reaccumulation and to evaluate the severity of tricuspid regurgitation.

Overall, the patient's condition is complex and requires a multidisciplinary approach involving cardiology, infectious disease, gastroenterology, and orthopedics to address the various medical issues identified in the report.


Next speaker: Med_Agent


and then I get the error message.

Steps to reproduce

No response

Screenshots and logs

No response

Additional Information

No response

@davorrunje davorrunje self-assigned this Aug 27, 2024
@davorrunje
Copy link
Collaborator

@Adibahaq This issue is most likely the following error introduced by more strict JSON checking:

https://community.openai.com/t/error-the-model-produced-invalid-content/747511

I will create a pull request shortly and I would appreciate if you could test your example against it.

@davorrunje davorrunje added bug Something isn't working function/tool suggestion and execution of function/tool call labels Aug 27, 2024
@davorrunje
Copy link
Collaborator

@Adibahaq please check if your code works with the fix in PR #3429

@LittleLittleCloud
Copy link
Collaborator

Also see this issue from .net end. Will push a fix in AutoGen.Net as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.2 Issues which were filed before re-arch to 0.4 bug Something isn't working function/tool suggestion and execution of function/tool call needs-triage
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants