SelectorGroupChat leveraging Ollama model does not select speaker #5384
-
Hey folks, I've been experimenting with autogen 0.4.5 and running into issues leveraging the SelectorGroupChat with ollama. I was looking for assistance first before opening an issue. I'm attempting to run examples from documentation: https://microsoft.github.io/autogen/stable//user-guide/agentchat-user-guide/selector-group-chat.html Speaker selection fails to select a speaker
For environment, everything is running everything locally on docker containers. I'm leveraging ollama/ollama:latest to serve various models. I've tried a few different models (llama3:8b, llama3.2:3b, llama3.3:70b) with the same result. Here is my OpenAIChatCompletionChat for reference OpenAIChatCompletionClient(
model="llama3.3:70b",
base_url="http://localhost:8443/v1",
api_key="placeholder",
model_info={
"vision": False,
"function_calling": True,
"json_output": False,
"family": "unknown",
},
) Troubleshooting
def selector_func(messages: Sequence[AgentEvent | ChatMessage]) -> str | None:
if messages[-1].source != planning_agent.name:
return planning_agent.name
return None
|
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 5 replies
-
cc @afourney for related interest. @brettbourgeois have you tried to customize the selector's prompt as part of the Alternatively, just try to call the llama model directly in the |
Beta Was this translation helpful? Give feedback.
-
Yeah, I've been working with llama, and other smaller models, for the last little while, slowly improving compatibility with built-in agents. I have not yet tackled SelectorGroupChat. Does this happen right away, or after the conversation grows for a bit? I will look into this tomorrow (hopefully), and see if we can tailor the prompts or context setup better for llama. |
Beta Was this translation helpful? Give feedback.
-
Issue DiagnosisHey @brettbourgeois, @ekzhu, @afourney, I believe the issue comes down to how Ollama handles system vs. user messages. Right now, the selector prompt includes the entire conversation history inside the system message, which works fine for GPT-4 but doesn’t seem to work well with Llama-based models. From what I’ve seen, Llama models need the conversation history explicitly separated as user input rather than being embedded inside system instructions. Otherwise, they don’t return anything useful, leading to Proposed FixInstead of embedding
This keeps the selector prompt as a system instruction while providing the conversation history as structured user input, which seems to work better for Llama models. Before (doesn’t work)select_speaker_messages = [
SystemMessage(content=select_speaker_prompt) # Instructions to model
] After (fixes it)select_speaker_messages = [
SystemMessage(content=select_speaker_prompt), # Instructions to the model
UserMessage(content=history, source="user") # Conversation history as user input
] ResultsWith this change, Ollama actually picks a speaker instead of failing silently. Autogen Client Output:
Relevant Ollama Log (showing updated request):
This confirms that Ollama is now receiving a properly formatted message and returning a valid selection. |
Beta Was this translation helpful? Give feedback.
-
@nickrwann I came to the same conclusion, and was working on an independent PR: #5409 Please have a look and let me know if it addresses the issue for you. |
Beta Was this translation helpful? Give feedback.
-
Ok, I think this should be fixed. I will close the thread, but please re-open if the patch isn't working for you. |
Beta Was this translation helpful? Give feedback.
@nickrwann I came to the same conclusion, and was working on an independent PR: #5409
Please have a look and let me know if it addresses the issue for you.