Skip to content

[Bug]: When using Qwen2.5, Swarm cannot work. #1451

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

Open
LianxinGao opened this issue Mar 27, 2025 · 6 comments
Open

[Bug]: When using Qwen2.5, Swarm cannot work. #1451

LianxinGao opened this issue Mar 27, 2025 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@LianxinGao
Copy link

Describe the bug

Follow the guide: https://docs.ag2.ai/docs/user-guide/basic-concepts/orchestration/swarm

_User (to chat_manager):

Today, let's introduce our kids to the solar system.

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

Next speaker: teacher_agent


>>>>>>>> USING AUTO REPLY...
teacher_agent (to chat_manager):

That sounds like a fantastic topic! Introducing students to the solar system can be both educational and exciting. Here’s a detailed lesson plan that covers key concepts and includes engaging activities.

### Lesson Plan: Exploring the Solar System

#### Grade Level:
3rd - 5th Grade

#### Duration:
60 minutes

#### Objectives:
1. Students will be able to identify and name the eight planets in the solar system.
2. Students will understand the basic characteristics of each planet (size, distance from the Sun, and notable features).
3. Students will learn about the Sun and its role in the solar system.
4. Students will explore the concept of orbits and rotations.

#### Materials:
- Interactive whiteboard or projector
- Solar system posters or models
- Handouts with solar system facts
- Art supplies (colored paper, markers, glue, scissors)
- Solar system worksheets
- Videos about the solar system (optional)

#### Lesson Outline:

**Introduction (10 minutes)**
1. **Engage:**
   - Start with a short video or a few images of the solar system to capture students' interest.
   - Ask students what they already know about the solar system and write their responses on the board.

2. **Explain:**
   - Introduce the concept of the solar system and explain that it consists of the Sun and all the objects that orbit around it, including planets, moons, asteroids, and comets.

**Direct Instruction (15 minutes)**
1. **Teach:**
   - Use an interactive whiteboard or projector to display a diagram of the solar system.
   - Go through each planet, starting from the Sun and moving outward.
   - For each planet, discuss:
     - Name
     - Size (relative to Earth)
     - Distance from the Sun
     - Notable features (e.g., rings, moons, atmosphere)
   - Highlight the differences between inner (rocky) and outer (gaseous) planets.

2. **Sun:**
   - Explain the Sun's role as the center of the solar system and its importance in providing light and energy.

**Guided Practice (15 minutes)**
1. **Activity:**
   - Distribute handouts with solar system facts.
   - Have students work in pairs to match each planet with its correct description.
   - Review the answers as a class to ensure understanding.

**Independent Practice (15 minutes)**
1. **Project:**
   - Instruct students to create a model of the solar system using art supplies.
   - They can use colored paper to cut out and label the planets, and string or yarn to show the orbits.
   - Encourage creativity and accuracy in their models.

**Closure (5 minutes)**
1. **Summarize:**
   - Ask students to share one interesting fact they learned about the solar system.
   - Recap the main points of the lesson and emphasize the importance of the Sun and the unique characteristics of each planet.

**Assessment:**
- Observe students during the guided and independent practice activities.
- Collect and review the solar system models to assess understanding.
- Use a quick quiz or worksheet at the end of the lesson to reinforce key concepts.

#### Extensions:
- **Research Project:** Have students choose a planet and create a report or presentation about it.
- **Field Trip:** If possible, organize a visit to a planetarium or science museum.
- **Technology Integration:** Use online resources and virtual tours of the solar system to enhance learning.

This lesson plan should provide a comprehensive and engaging introduction to the solar system for your students. Let me know if you need any adjustments or additional resources!

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

Next speaker: _Swarm_Tool_Executor

Traceback (most recent call last):
  File "/Users/xxx/Documents/Projects/ag2_demo/swarm_demo.py", line 63, in <module>
    result, _, _ = initiate_swarm_chat(
                   ^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/yyy/lib/python3.12/site-packages/autogen/agentchat/contrib/swarm_agent.py", line 988, in initiate_swarm_chat
    chat_result = last_agent.initiate_chat(  # type: ignore[attr-defined]
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/yyy/lib/python3.12/site-packages/autogen/agentchat/conversable_agent.py", line 1508, in initiate_chat
    self.send(msg2send, recipient, silent=silent)
  File "/opt/anaconda3/envs/yyy/lib/python3.12/site-packages/autogen/agentchat/conversable_agent.py", line 1189, in send
    recipient.receive(message, self, request_reply, silent)
  File "/opt/anaconda3/envs/yyy/lib/python3.12/site-packages/autogen/agentchat/conversable_agent.py", line 1297, in receive
    reply = self.generate_reply(messages=self.chat_messages[sender], sender=sender)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/yyy/lib/python3.12/site-packages/autogen/agentchat/conversable_agent.py", line 2508, in generate_reply
    final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"])
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/yyy/lib/python3.12/site-packages/autogen/agentchat/groupchat.py", line 1198, in run_chat
    reply = speaker.generate_reply(sender=self)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/yyy/lib/python3.12/site-packages/autogen/agentchat/conversable_agent.py", line 2508, in generate_reply
    final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"])
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/anaconda3/envs/yyy/lib/python3.12/site-packages/autogen/agentchat/contrib/swarm_agent.py", line 1297, in _generate_swarm_tool_reply
    if tool_message is None:
       ^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'tool_message' where it is not associated with a value

Steps to reproduce

Code:

from dotenv import load_dotenv
import os

from autogen import (
    AfterWorkOption,
    ConversableAgent,
    initiate_swarm_chat,
    LLMConfig
)

load_dotenv()


llm_config = {
     "api_key": os.environ["TEST_API_KEY"],
     "base_url": os.environ["TEST_BASE_URL"],
     "model": "Qwen2.5-72B-Instruct",
 }
llm_config = LLMConfig(**llm_config)

planner_message = """You are a classroom lesson planner.
Given a topic, write a lesson plan for a fourth grade class.
If you are given revision feedback, update your lesson plan and record it.
Use the following format:
<title>Lesson plan title</title>
<learning_objectives>Key learning objectives</learning_objectives>
<script>How to introduce the topic to the kids</script>
"""

reviewer_message = """You are a classroom lesson reviewer.
You compare the lesson plan to the fourth grade curriculum
and provide a maximum of 3 recommended changes for each review.
Make sure you provide recommendations each time the plan is updated.
"""

teacher_message = """You are a classroom teacher.
You decide topics for lessons and work with a lesson planner.
and reviewer to create and finalise lesson plans.
"""

with llm_config:
    lesson_planner = ConversableAgent(
        name="planner_agent",
        system_message=planner_message
    )

    lesson_reviewer = ConversableAgent(
        name="reviewer_agent",
        system_message=reviewer_message
    )

    teacher = ConversableAgent(
        name="teacher_agent",
        system_message=teacher_message
    )

result, _, _ = initiate_swarm_chat(
    initial_agent=teacher,
    agents=[lesson_planner, lesson_reviewer, teacher],
    messages="Today, let's introduce our kids to the solar system.",
    max_rounds=10,
    after_work=AfterWorkOption.TERMINATE
)

Model Used

Qwen2.5-72B-Instruct

Expected Behavior

No response

Screenshots and logs

No response

Additional Information

No response

@LianxinGao LianxinGao added the bug Something isn't working label Mar 27, 2025
@CAROLZXYZXY
Copy link
Collaborator

Which LLM provider did you use?

@CAROLZXYZXY CAROLZXYZXY self-assigned this Mar 27, 2025
@CAROLZXYZXY
Copy link
Collaborator

CAROLZXYZXY commented Mar 27, 2025

I am able to run Qwen2.5-72B-Instruct with together.ai client using your script. This is my output.


Today, let's introduce our kids to the solar system.

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

Next speaker: teacher_agent


>>>>>>>> USING AUTO REPLY...

Great idea! Introducing the solar system to kids can be both fun and educational. Here's a draft outline for a lesson plan on the solar system for elementary school students:

### Lesson Title: Journey Through the Solar System

### Age Group: Elementary (6-10 years old)

### Lesson Duration: 60 minutes

### Learning Objectives:
1. Students will understand the concept of a solar system.
2. Students will identify the eight planets in our solar system and their order from the Sun.
3. Students will learn basic characteristics of each planet.
4. Students will understand the concept of orbits and rotation.

### Materials Needed:
- Large solar system poster or images of each planet
- Solar system model (real or digital)
- Flashcards with planet names and pictures
- Interactive whiteboard (if available)
- Fact sheets about each planet
- Art supplies (for creating mini-books or posters)

### Lesson Plan:

#### Introduction (10 minutes):
1. **Hook Activity**: Start with a brief discussion about the stars and the night sky, asking students if they have ever seen a shooting star or a constellation.
2. **Objective Setting**: Explain that today they will learn about the solar system, including the planets and their characteristics.

#### Main Activity (30 minutes):
1. **Solar System Overview**: Use the interactive whiteboard or large poster to show the solar system. Explain that our solar system consists of the Sun and everything that orbits it, including planets, moons, asteroids, and comets.
2. **Planet Tour**: Use the flashcards or digital model to give a quick overview of each planet, starting from the Sun. Highlight key characteristics such as size, distance from the Sun, and notable features.
    - Mercury: Closest to the Sun, small, no moons.
    - Venus: Similar in size to Earth, hottest planet.
    - Earth: Our home planet, third from the Sun, has one moon.
    - Mars: Fourth from the Sun, called the Red Planet, has two small moons.
    - Jupiter: Largest planet, has a ring system, and many moons.
    - Saturn: Known for its impressive ring system, has numerous moons.
    - Uranus: Seventh from the Sun, rotates on its side.
    - Neptune: Farthest from the Sun, has a strong wind system.

3. **Interactive Activity**: Divide the class into small groups. Each group will be assigned a planet. They will use the fact sheets to create a mini-book or a poster

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

>>>>>>>> TERMINATING RUN (fd9e8335-e0cb-442a-a28a-93e35302c202): No next speaker selected```

@LianxinGao
Copy link
Author

LianxinGao commented Mar 28, 2025

Which LLM provider did you use?

@CAROLZXYZXY I use vllm(v0.8.2) to deploy this model.

@marklysze
Copy link
Collaborator

@LianxinGao, are you able to share your LLMConfig/llm config dictionary (with sensitive information replaced). Also, have you tried Ollama (to understand if it's vLLM).

@LianxinGao
Copy link
Author

LianxinGao commented Mar 29, 2025

@LianxinGao, are you able to share your LLMConfig/llm config dictionary (with sensitive information replaced). Also, have you tried Ollama (to understand if it's vLLM).

The code has already been provided above(include LLMConfig).

vllm settings:

--model /models/Qwen/Qwen2.5-72B-Instruct --tensor-parallel-size 4 --disable-log-requests --trust-remote-code --enforce-eager --enable-auto-tool-choice --tool-call-parser hermes --max-model-len 300000

vllm env:

VLLM_HOST_IP=0.0.0.0
VLLM_PORT=8000
VLLM_ALLOW_LONG_MAX_MODEL_LEN=1

I have only used vLLM and haven't tried Ollama yet.

@CAROLZXYZXY
Copy link
Collaborator

@LianxinGao are you hosting the qwen model with vllm locally?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants