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:

  1. Research: Searches 10+ authoritative sources using DuckDuckGo
  2. Extract: Uses Newspaper4k to pull content from relevant articles
  3. Analyze: Cross-references facts, identifies patterns and trends
  4. Write: Structures findings into NYT-style articles with balanced perspectives
  5. Verify: Ensures all facts and attributions are accurate

The agent maintains journalistic standards of objectivity and includes proper sourcing throughout.

Code

1from textwrap import dedent
2
3from kern.agent import Agent
4from kern.models.openai import OpenAIResponses
5from kern.tools.duckduckgo import DuckDuckGoTools
6from kern.tools.newspaper4k import Newspaper4kTools
7
8# Initialize the research agent with advanced journalistic capabilities
9research_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:
15
16 - Deep investigative research and analysis
17 - Meticulous fact-checking and source verification
18 - Compelling narrative construction
19 - Data-driven reporting and visualization
20 - Expert interview synthesis
21 - Trend analysis and future predictions
22 - Complex topic simplification
23 - Ethical journalism practices
24 - Balanced perspective presentation
25 - Global context integration\
26 """),
27 instructions=dedent("""\
28 1. Research Phase
29 - Search for 10+ authoritative sources on the topic
30 - Prioritize recent publications and expert opinions
31 - Identify key stakeholders and perspectives
32
33 2. Analysis Phase
34 - Extract and verify critical information
35 - Cross-reference facts across multiple sources
36 - Identify emerging patterns and trends
37 - Evaluate conflicting viewpoints
38
39 3. Writing Phase
40 - Craft an attention-grabbing headline
41 - Structure content in NYT style
42 - Include relevant quotes and statistics
43 - Maintain objectivity and balance
44 - Explain complex concepts clearly
45
46 4. Quality Control
47 - Verify all facts and attributions
48 - Ensure narrative flow and readability
49 - Add context where necessary
50 - Include future implications
51 """),
52 expected_output=dedent("""\
53 # {Compelling Headline} 📰
54
55 ## Executive Summary
56 {Concise overview of key findings and significance}
57
58 ## Background & Context
59 {Historical context and importance}
60 {Current landscape overview}
61
62 ## Key Findings
63 {Main discoveries and analysis}
64 {Expert insights and quotes}
65 {Statistical evidence}
66
67 ## Impact Analysis
68 {Current implications}
69 {Stakeholder perspectives}
70 {Industry/societal effects}
71
72 ## Future Outlook
73 {Emerging trends}
74 {Expert predictions}
75 {Potential challenges and opportunities}
76
77 ## Expert Insights
78 {Notable quotes and analysis from industry leaders}
79 {Contrasting viewpoints}
80
81 ## Sources & Methodology
82 {List of primary sources with key contributions}
83 {Research methodology overview}
84
85 ---
86 Research conducted by AI Investigative Journalist
87 New York Times Style Report
88 Published: {current_date}
89 Last Updated: {current_time}\
90 """),
91 markdown=True,
92 add_datetime_to_context=True,
93)
94
95# Example usage with detailed research request
96if __name__ == "__main__":
97 research_agent.print_response(
98 "Analyze the current state and future implications of artificial intelligence regulation worldwide",
99 stream=True,
100 )
101
102# 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"
109
110Environmental & 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"
115
116Healthcare & 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"
121
122Societal 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.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Set your API key

1export OPENAI_API_KEY=xxx

Install dependencies

1uv pip install -U kern-ai openai ddgs newspaper4k lxml_html_clean

Run Agent

1python research_agent.py
1python research_agent.py

Next Steps

  • Modify the research topic to explore different subjects
  • Adjust the number of sources searched for more comprehensive coverage
  • Customize the expected_output template to match your preferred article style
  • Explore DuckDuckGo Tools for advanced search options