adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

Only the first request is answered when using ollama model.

Open zerone-agent opened this issue 1 year ago • 7 comments

I try to build a simple agent using ollama model, here is my code:

from google.adk.agents import LlmAgent
from google.adk.models.lite_llm import LiteLlm

# 创建使用Ollama Gemma模型的代理
root_agent = LlmAgent(
    model=LiteLlm(model="ollama/gemma3"),
    name="root_agent",
    description=("task agent"),
    instruction=("You are a helpful assistant that can help with tasks and questions."),
)

I successfully executed the code, but it looks like only the first response was answered.

web page:

Image

terminal log:

LLM Request:
-----------------------------------------------------------
System Instruction:
You are a helpful assistant that can help with tasks and questions.

You are an agent. Your internal name is "root_agent".

 The description about you is "task agent"
-----------------------------------------------------------
Contents:
{"parts":[{"text":"What is 18 plus 5"}],"role":"user"}
{"parts":[{"text":"18 plus 5 is 23."}],"role":"model"}
{"parts":[{"text":"What is 20 plus 10"}],"role":"user"}
{"parts":[{"text":"Okay, I understand. I'm ready for your next task!"}],"role":"model"}
{"parts":[{"text":"What is 20 plus 10"}],"role":"user"}
{"parts":[{"text":"Okay, great! Let's move on to the next task."}],"role":"model"}
{"parts":[{"text":"hello"}],"role":"user"}
{"parts":[{"text":"Okay, great! Let’s move on to the next task."}],"role":"model"}
{"parts":[{"text":"What color are bananas"}],"role":"user"}
-----------------------------------------------------------
Functions:

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

zerone-agent avatar Apr 12 '25 09:04 zerone-agent

I get the same situation, and after some work, found all message sent by the prompt, not the message field in openai compatible api result this。

lyfuci avatar Apr 12 '25 15:04 lyfuci

hi team, supporting this issue. i also tried to reproduce this error.

Image

i would appreciate an explanation of why this is the case.

me-tusharchandra avatar Apr 12 '25 17:04 me-tusharchandra

there is a trick to prevent this.

    model=LiteLlm("openai/qwen2.5:32b",base_url="http://localhost:11434/v1"),

use openai provider ,but specific the ollama base_url, and you need fill the OPENAI_API_KEY env as well.

@zhiheng-yu @me-tusharchandra

lyfuci avatar Apr 12 '25 17:04 lyfuci

hi @lyfuci, can you share your complete code? if possible for model="ollama/gemma3:1b"

me-tusharchandra avatar Apr 12 '25 17:04 me-tusharchandra

okay so @lyfuci, @zhiheng-yu, using ollama_chat solves the problem over ollama.

precisely: model=LiteLlm(model="ollama_chat/gemma3:1b")

to understand the behaviour differences between both please head over 'venv/lib/python3.13/site-packages/litellm/main.py'

@admins please close this issue, thanks!

me-tusharchandra avatar Apr 12 '25 22:04 me-tusharchandra

@me-tusharchandra Thanks! It works.

okay so @lyfuci, @zhiheng-yu, using ollama_chat solves the problem over ollama.

precisely: model=LiteLlm(model="ollama_chat/gemma3:1b")

to understand the behaviour differences between both please head over 'venv/lib/python3.13/site-packages/litellm/main.py'

@admins please close this issue, thanks!

zerone-agent avatar Apr 13 '25 05:04 zerone-agent

@me-tusharchandra thanks!!

okay so @lyfuci, @zhiheng-yu, using ollama_chat solves the problem over ollama.

precisely: model=LiteLlm(model="ollama_chat/gemma3:1b")

to understand the behaviour differences between both please head over 'venv/lib/python3.13/site-packages/litellm/main.py'

@admins please close this issue, thanks!

lyfuci avatar Apr 13 '25 06:04 lyfuci