Swarm flight refund demo is not working with ollama models
There is a travel_agent/flight_refunder demo on the Swarm docs page. I've copied and pasted it into jupyter notebook and tried to run it with different local models via ollama using OpenAIChatCompletionClient (OpenAI like ollama endpoint) as well as OllamaChatCompletionClient. Both produced the same weird behavior when the swarm immediately hands off control to the user via transfer_to_user function call.
So, the demo run logs from the page look like this:
---------- user ----------
I need to refund my flight.
---------- travel_agent ----------
[FunctionCall(id='call_ZQ2rGjq4Z29pd0yP2sNcuyd2', arguments='{}', name='transfer_to_flights_refunder')]
[Prompt tokens: 119, Completion tokens: 14]
---------- travel_agent ----------
[FunctionExecutionResult(content='Transferred to flights_refunder, adopting the role of flights_refunder immediately.', call_id='call_ZQ2rGjq4Z29pd0yP2sNcuyd2')]
---------- travel_agent ----------
Transferred to flights_refunder, adopting the role of flights_refunder immediately.
---------- flights_refunder ----------
Could you please provide me with the flight reference number so I can process the refund for you?
[Prompt tokens: 191, Completion tokens: 20]
---------- flights_refunder ----------
[FunctionCall(id='call_1iRfzNpxTJhRTW2ww9aQJ8sK', arguments='{}', name='transfer_to_user')]
[Prompt tokens: 219, Completion tokens: 11]
---------- flights_refunder ----------
[FunctionExecutionResult(content='Transferred to user, adopting the role of user immediately.', call_id='call_1iRfzNpxTJhRTW2ww9aQJ8sK')]
---------- flights_refunder ----------
Transferred to user, adopting the role of user immediately.
---------- Summary ----------
Number of messages: 8
Finish reason: Handoff to user from flights_refunder detected.
Total prompt tokens: 529
Total completion tokens: 45
Duration: 2.05 seconds
---------- user ----------
Sure, it's 507811
.....
What happens here is: the flights_refunder agent generates the message to the user "Could you please provide me with the flight reference number so I can process the refund for you?" and then asks for user input.
My multiple attempts to reproduce the demo using ollama hosted models (deepseek-r1 and gemma3 to be specific) produce the following results:
---------- user ----------
I need to refund my flight.
---------- travel_agent ----------
[FunctionCall(id='0', arguments='{}', name='transfer_to_user')]
---------- travel_agent ----------
[FunctionExecutionResult(content='Transferred to user, adopting the role of user immediately.', name='transfer_to_user', call_id='0', is_error=False)]
---------- travel_agent ----------
Transferred to user, adopting the role of user immediately.
---------- user ----------
So instead of travel_agent saying what it expects the user to enter it asks for an input immediately.
Same behavior I see when I try to port a couple of very basic agents from llamaindex based code with prompts that worked there.
Here's my configuration for model_client:
model_client = OpenAIChatCompletionClient(
model="gemma3-tools:27b",
temperature=0.1,
base_url='https://.../v1/',
timeout=600,
model_info=ModelInfo(
vision=True,
function_calling=True,
structured_output=True,
json_output=True,
family='unknown',
),
parallel_tool_calls=False, # type: ignore
)
The rest is just the original demo code from the docs.
I am not sure if it's a model specific problem.
Which packages was the bug in?
Python AgentChat (autogen-agentchat>=0.4.0)
AutoGen library version.
Python 0.5.1
Other library version.
No response
Model used
multiple tried
Model provider
Ollama
Other model provider
No response
Python version
3.12
.NET version
None
Operating system
MacOS
Link to #5931 under swarm improvement.