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

[Bug] When Gemini model, agent will only return string response even when response_model is set. #2038

Open
DataSolveProblems opened this issue Feb 7, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@DataSolveProblems
Copy link

DataSolveProblems commented Feb 7, 2025

When using Gemini models, agent is unable to convert the output into the correct structured output type. For example, from the agent run below, the expected output should be a NewsArticle object, but string output is returned instead. This only happens to Gemini models.

Code to reproduce the issue

from typing import Optional
from pydantic import BaseModel, Field
from agno.agent import Agent
from agno.models.google import Gemini
from agno.tools.duckduckgo import DuckDuckGoTools

class NewsArticle(BaseModel):
    title: str = Field(..., description="Title of the article.")
    url: str = Field(..., description="Link to the article.")
    summary: Optional[str] = Field(..., description="Summary of the article if available.")

class SearchResults(BaseModel):
    articles: list[NewsArticle]

agent = Agent(
    # model=Gemini(id='gemini-2.0-flash'),
    model=Gemini(id='gemini-2.0-flash-lite-preview-02-05'),
    tools=[DuckDuckGoTools()],
    instructions=['Given a topic, search for the top 5 articles.'],
    add_datetime_to_instructions=True, # add the current date
    response_model=SearchResults,
    structured_outputs=True,
    debug_mode=True,
    show_tool_calls=True,
)

response = agent.run('Search for today\'s top news')

Log

DEBUG    *********** Agent Run End:
         20d98dba-126b-4129-ada8-7cec33cf246b ***********
WARNING  Failed to convert response to response_model
@DataSolveProblems DataSolveProblems added the bug Something isn't working label Feb 7, 2025
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

1 participant