HackerNews Team

Build a team that aggregates, curates, and analyzes trending HackerNews stories. This example combines multiple specialized agents to research topics, read articles, and generate comprehensive summaries with structured output.

What You'll Learn

By building this team, you'll understand:

  • How to integrate multiple data sources (HackerNews API, web search, article readers)
  • How to define structured output schemas using Pydantic models
  • How to coordinate agents with specific instructions for complex workflows
  • How to combine real-time data with web research for comprehensive analysis

Use Cases

Build news aggregation platforms, trend analysis systems, content curation tools, or automated newsletter generators.

How It Works

The team coordinates three specialized agents to create detailed articles:

  1. Discover: HackerNews researcher finds trending stories from HackerNews
  2. Read: Article reader extracts full content from story URLs
  3. Research: Web searcher finds additional context and related information
  4. Synthesize: Team combines all findings into structured articles with summaries and references

The team outputs structured data following a defined schema with title, summary, and reference links.

Code

1from typing import List
2
3from kern.agent import Agent
4from kern.models.openai import OpenAIResponses
5from kern.team import Team
6from kern.tools.duckduckgo import DuckDuckGoTools
7from kern.tools.hackernews import HackerNewsTools
8from kern.tools.newspaper4k import Newspaper4kTools
9from pydantic import BaseModel
10
11
12class Article(BaseModel):
13 title: str
14 summary: str
15 reference_links: List[str]
16
17
18hn_researcher = Agent(
19 name="HackerNews Researcher",
20 model=OpenAIResponses(id="gpt-5.2"),
21 role="Gets top stories from hackernews.",
22 tools=[HackerNewsTools()],
23)
24
25web_searcher = Agent(
26 name="Web Searcher",
27 model=OpenAIResponses(id="gpt-5.2"),
28 role="Searches the web for information on a topic",
29 tools=[DuckDuckGoTools()],
30 add_datetime_to_context=True,
31)
32
33article_reader = Agent(
34 name="Article Reader",
35 role="Reads articles from URLs.",
36 tools=[Newspaper4kTools()],
37)
38
39hn_team = Team(
40 name="HackerNews Team",
41 model=OpenAIResponses(id="gpt-5.2"),
42 members=[hn_researcher, web_searcher, article_reader],
43 instructions=[
44 "First, search hackernews for what the user is asking about.",
45 "Then, ask the article reader to read the links for the stories to get more information.",
46 "Important: you must provide the article reader with the links to read.",
47 "Then, ask the web searcher to search for each story to get more information.",
48 "Finally, provide a thoughtful and engaging summary.",
49 ],
50 output_schema=Article,
51 markdown=True,
52 show_members_responses=True,
53)
54
55hn_team.print_response("Write an article about the top 2 stories on hackernews")

What to Expect

The team will research HackerNews stories, read the full articles, and search for additional context. Each agent contributes their specialized capability: finding stories, extracting article content, and web research.

The output is a structured Article object with a title, comprehensive summary, and reference links. You'll see responses from all team members showing how they collaborate to gather and synthesize information.

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 Team

1python hackernews_team.py
1python hackernews_team.py

Next Steps

  • Modify the query to track specific topics or keywords on HackerNews
  • Adjust the Article schema to include additional fields like categories or sentiment
  • Change the number of stories analyzed in the prompt
  • Explore Input & Output for custom data schemas