Hello Agno community! I’ve run into an issue with content generation using an Agent with Claude and a Pydantic response model. Here’s what I’m working with:
from phi.agent import Agent
from phi.model.anthropic import Claude
from pydantic import BaseModel, Field
from typing import List, Optional, Literal
class Source(BaseModel):
"""Represents a content source"""
url: str
title: str
content: str
source_type: Literal["arxiv", "web", "wikipedia", "news"]
relevance_score: float = Field(default=1.0)
reasoning: str
class Section(BaseModel):
"""Represents an article section"""
title: str
description: str
content: Optional[str] = None
sources: List[Source] = Field(default_factory=list)
class Article(BaseModel):
"""Represents a complete article"""
title: str
sections: List[Section]
main_sources: List[Source] = Field(default_factory=list)
internal_links: List[str] = Field(default_factory=list)
writer_agent = Agent(
name="Writer Agent",
model=Claude(id=CLAUDE_MODEL_ID, api_key=ANTHROPIC_API_KEY),
team=[search_strategist, researcher_agent, content_planner, content_writer],
response_model=Article
)
When trying to generate content, I’m getting the following error:
Error during content generation: Error code: 400 - {'type': 'error', 'error': {'type': 'invalid_request_error', 'message': 'messages: text content blocks must be non-empty'}}
What makes this particularly interesting is that this error occurs intermittently - most of the time the agent works perfectly fine. Has anyone else encountered this intermittent issue?
Note: I haven’t upgrade to Agno yet.