You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Refactor ai_news_generator to use CrewAI Flows (#173)
This commit refactors the ai_news_generator project to use CrewAI Flows for
an agentic workflow, replacing the simple crew-based orchestration with a
Flow-based approach that provides better state management, task chaining,
and event-driven execution.
Key Changes:
- 🌊 Implement AINewsGeneratorFlow class extending Flow[NewsGenerationState]
- 🎯 Add structured state management with Pydantic models
- ⚙️ Use @start() decorator for research_phase initialization
- 🔊 Use @listen(research_phase) for content_writing_phase chaining
- 📊 Enhanced Streamlit UI with flow visualization and execution feedback
- 📁 Added requirements.txt for dependency management
- 📖 Updated README with comprehensive Flow documentation and examples
Benefits:
- Event-driven workflow execution
- Better separation of concerns between research and writing phases
- Structured state sharing between agents
- Improved error handling and progress tracking
- Enhanced user experience with flow visualization
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <[email protected]>
st.info("This application uses CrewAI Flows for structured, event-driven content generation:\n1. **Research Phase**: AI agent researches the topic\n2. **Writing Phase**: AI agent transforms research into engaging content")
56
+
38
57
# Add some helpful information
39
58
withst.expander("ℹ️ How to use"):
40
59
st.markdown("""
@@ -45,121 +64,179 @@
45
64
5. Download the result as a markdown file
46
65
""")
47
66
48
-
defgenerate_content(topic):
49
-
llm=LLM(
50
-
model="command-r",
51
-
temperature=0.7
52
-
)
53
-
54
-
search_tool=SerperDevTool(n_results=10)
55
-
56
-
# First Agent: Senior Research Analyst
57
-
senior_research_analyst=Agent(
58
-
role="Senior Research Analyst",
59
-
goal=f"Research, analyze, and synthesize comprehensive information on {topic} from reliable web sources",
60
-
backstory="You're an expert research analyst with advanced web research skills. "
61
-
"You excel at finding, analyzing, and synthesizing information from "
62
-
"across the internet using search tools. You're skilled at "
63
-
"distinguishing reliable sources from unreliable ones, "
64
-
"fact-checking, cross-referencing information, and "
65
-
"identifying key patterns and insights. You provide "
66
-
"well-organized research briefs with proper citations "
67
-
"and source verification. Your analysis includes both "
68
-
"raw data and interpreted insights, making complex "
69
-
"information accessible and actionable.",
70
-
allow_delegation=False,
71
-
verbose=True,
72
-
tools=[search_tool],
73
-
llm=llm
74
-
)
75
-
76
-
# Second Agent: Content Writer
77
-
content_writer=Agent(
78
-
role="Content Writer",
79
-
goal="Transform research findings into engaging blog posts while maintaining accuracy",
80
-
backstory="You're a skilled content writer specialized in creating "
81
-
"engaging, accessible content from technical research. "
82
-
"You work closely with the Senior Research Analyst and excel at maintaining the perfect "
83
-
"balance between informative and entertaining writing, "
84
-
"while ensuring all facts and citations from the research "
85
-
"are properly incorporated. You have a talent for making "
86
-
"complex topics approachable without oversimplifying them.",
87
-
allow_delegation=False,
88
-
verbose=True,
89
-
llm=llm
90
-
)
67
+
classNewsGenerationState(BaseModel):
68
+
topic: str=""
69
+
research_report: str=""
70
+
final_article: str=""
71
+
temperature: float=0.7
91
72
92
-
# Research Task
93
-
research_task=Task(
94
-
description=("""
95
-
1. Conduct comprehensive research on {topic} including:
96
-
- Recent developments and news
97
-
- Key industry trends and innovations
98
-
- Expert opinions and analyses
99
-
- Statistical data and market insights
100
-
2. Evaluate source credibility and fact-check all information
101
-
3. Organize findings into a structured research brief
102
-
4. Include all relevant citations and sources
103
-
"""),
104
-
expected_output="""A detailed research report containing:
105
-
- Executive summary of key findings
106
-
- Comprehensive analysis of current trends and developments
107
-
- List of verified facts and statistics
108
-
- All citations and links to original sources
109
-
- Clear categorization of main themes and patterns
110
-
Please format with clear sections and bullet points for easy reference.""",
111
-
agent=senior_research_analyst
112
-
)
113
-
114
-
# Writing Task
115
-
writing_task=Task(
116
-
description=("""
117
-
Using the research brief provided, create an engaging blog post that:
118
-
1. Transforms technical information into accessible content
119
-
2. Maintains all factual accuracy and citations from the research
120
-
3. Includes:
121
-
- Attention-grabbing introduction
122
-
- Well-structured body sections with clear headings
123
-
- Compelling conclusion
124
-
4. Preserves all source citations in [Source: URL] format
125
-
5. Includes a References section at the end
126
-
"""),
127
-
expected_output="""A polished blog post in markdown format that:
128
-
- Engages readers while maintaining accuracy
129
-
- Contains properly structured sections
130
-
- Includes Inline citations hyperlinked to the original source url
131
-
- Presents information in an accessible yet informative way
132
-
- Follows proper markdown formatting, use H1 for the title and H3 for the sub-sections""",
0 commit comments