Research Agent
Build an AI research agent that combines web search with professional journalism to perform comprehensive research, fact-check information, and deliver well-structured NYT-style articles.
What You'll Learn
By building this agent, you'll understand:
- How to use web search tools (DuckDuckGo) for multi-source research
- How to extract and analyze content from web articles using Newspaper4k
- How to structure professional journalistic writing with clear instructions
- How to define output templates for consistent article formatting
Use Cases
Build investigative journalism tools, research report generators, fact-checking systems, or content analysis platforms.
How It Works
The agent follows a professional journalism research workflow:
- Research: Searches 10+ authoritative sources using DuckDuckGo
- Extract: Uses Newspaper4k to pull content from relevant articles
- Analyze: Cross-references facts, identifies patterns and trends
- Write: Structures findings into NYT-style articles with balanced perspectives
- Verify: Ensures all facts and attributions are accurate
The agent maintains journalistic standards of objectivity and includes proper sourcing throughout.
Code
1from textwrap import dedent23from kern.agent import Agent4from kern.models.openai import OpenAIResponses5from kern.tools.duckduckgo import DuckDuckGoTools6from kern.tools.newspaper4k import Newspaper4kTools78# Initialize the research agent with advanced journalistic capabilities9research_agent = Agent(10 model=OpenAIResponses(id="gpt-5.2"),11 tools=[DuckDuckGoTools(), Newspaper4kTools()],12 description=dedent("""\13 You are an elite investigative journalist with decades of experience at the New York Times.14 Your expertise encompasses: ��1516 - Deep investigative research and analysis17 - Meticulous fact-checking and source verification18 - Compelling narrative construction19 - Data-driven reporting and visualization20 - Expert interview synthesis21 - Trend analysis and future predictions22 - Complex topic simplification23 - Ethical journalism practices24 - Balanced perspective presentation25 - Global context integration\26 """),27 instructions=dedent("""\28 1. Research Phase ��29 - Search for 10+ authoritative sources on the topic30 - Prioritize recent publications and expert opinions31 - Identify key stakeholders and perspectives3233 2. Analysis Phase ��34 - Extract and verify critical information35 - Cross-reference facts across multiple sources36 - Identify emerging patterns and trends37 - Evaluate conflicting viewpoints3839 3. Writing Phase ✍️40 - Craft an attention-grabbing headline41 - Structure content in NYT style42 - Include relevant quotes and statistics43 - Maintain objectivity and balance44 - Explain complex concepts clearly4546 4. Quality Control ✓47 - Verify all facts and attributions48 - Ensure narrative flow and readability49 - Add context where necessary50 - Include future implications51 """),52 expected_output=dedent("""\53 # {Compelling Headline} 📰5455 ## Executive Summary56 {Concise overview of key findings and significance}5758 ## Background & Context59 {Historical context and importance}60 {Current landscape overview}6162 ## Key Findings63 {Main discoveries and analysis}64 {Expert insights and quotes}65 {Statistical evidence}6667 ## Impact Analysis68 {Current implications}69 {Stakeholder perspectives}70 {Industry/societal effects}7172 ## Future Outlook73 {Emerging trends}74 {Expert predictions}75 {Potential challenges and opportunities}7677 ## Expert Insights78 {Notable quotes and analysis from industry leaders}79 {Contrasting viewpoints}8081 ## Sources & Methodology82 {List of primary sources with key contributions}83 {Research methodology overview}8485 ---86 Research conducted by AI Investigative Journalist87 New York Times Style Report88 Published: {current_date}89 Last Updated: {current_time}\90 """),91 markdown=True,92 add_datetime_to_context=True,93)9495# Example usage with detailed research request96if __name__ == "__main__":97 research_agent.print_response(98 "Analyze the current state and future implications of artificial intelligence regulation worldwide",99 stream=True,100 )101102# Advanced research topics to explore:103"""104Technology & Innovation:1051. "Investigate the development and impact of large language models in 2024"1062. "Research the current state of quantum computing and its practical applications"1073. "Analyze the evolution and future of edge computing technologies"1084. "Explore the latest advances in brain-computer interface technology"109110Environmental & Sustainability:1111. "Report on innovative carbon capture technologies and their effectiveness"1122. "Investigate the global progress in renewable energy adoption"1133. "Analyze the impact of circular economy practices on global sustainability"1144. "Research the development of sustainable aviation technologies"115116Healthcare & Biotechnology:1171. "Explore the latest developments in CRISPR gene editing technology"1182. "Analyze the impact of AI on drug discovery and development"1193. "Investigate the evolution of personalized medicine approaches"1204. "Research the current state of longevity science and anti-aging research"121122Societal Impact:1231. "Examine the effects of social media on democratic processes"1242. "Analyze the impact of remote work on urban development"1253. "Investigate the role of blockchain in transforming financial systems"1264. "Research the evolution of digital privacy and data protection measures"127"""What to Expect
The agent will conduct comprehensive research on your query using DuckDuckGo to find multiple authoritative sources. It extracts content from relevant articles using Newspaper4k, cross-references information, and synthesizes findings into a professional NYT-style article.
The output includes an executive summary, background context, key findings with expert quotes and statistics, impact analysis, future outlook, and a complete list of sources. All content follows journalistic standards with balanced perspectives and verified facts.
Usage
Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateSet your API key
1export OPENAI_API_KEY=xxxInstall dependencies
1uv pip install -U kern-ai openai ddgs newspaper4k lxml_html_cleanRun Agent
1python research_agent.py1python research_agent.pyNext Steps
- Modify the research topic to explore different subjects
- Adjust the number of sources searched for more comprehensive coverage
- Customize the
expected_outputtemplate to match your preferred article style - Explore DuckDuckGo Tools for advanced search options