Skip to main content

Overview

Hacker News tool allows you to fetch top stories, new stories, and comments from Hacker News. No API key required. The user asks for tech news; the agent fetches Hacker News stories and returns them.

Installation

pip install "praisonai[tools]"
No API key required!

Quick Start

1

Simple Usage

from praisonai_tools import HackerNewsTool

# Initialize
hn = HackerNewsTool()

# Get top stories
stories = hn.get_top_stories(limit=5)
print(stories)
2

With Configuration

Use the same tool with an agent — see Usage with Agent below, or pass env vars and options from the sections above.

Usage with Agent

from praisonaiagents import Agent
from praisonai_tools import HackerNewsTool

agent = Agent(
    name="TechNews",
    instructions="You are a tech news assistant. Use Hacker News to find trending stories.",
    tools=[HackerNewsTool()]
)

response = agent.chat("What are the top stories on Hacker News today?")
print(response)

Available Methods

get_top_stories(limit=10)

Get top stories from Hacker News.
from praisonai_tools import HackerNewsTool

hn = HackerNewsTool()
stories = hn.get_top_stories(limit=5)

# Returns:
# [
#     {"title": "...", "url": "...", "score": 150, "comments": 45},
#     ...
# ]

get_new_stories(limit=10)

Get newest stories.
stories = hn.get_new_stories(limit=5)

get_best_stories(limit=10)

Get best stories.
stories = hn.get_best_stories(limit=5)

get_story(story_id)

Get a specific story by ID.
story = hn.get_story(12345678)

Function-Based Usage

from praisonai_tools import get_hackernews_top

# Quick access without instantiating class
stories = get_hackernews_top(limit=5)

CLI Usage

# Use with praisonai
praisonai --tools HackerNewsTool "What are the trending tech stories today?"

Error Handling

from praisonai_tools import HackerNewsTool

hn = HackerNewsTool()
stories = hn.get_top_stories(limit=5)

if stories and "error" in stories[0]:
    print(f"Error: {stories[0]['error']}")
else:
    for story in stories:
        print(f"- {story['title']} ({story['score']} points)")

Common Errors

ErrorCauseSolution
requests not installedMissing dependencyRun pip install requests
Connection errorNetwork issueCheck internet connection
Rate limitedToo many requestsAdd delay between requests

How It Works


Best Practices

The Hacker News API is public — no credentials required.
Fetch the top N stories so the agent summarises a focused set instead of the full feed.
The front page changes slowly — cache it briefly to avoid repeated calls.

Reddit

Reddit discussions

ArXiv

Academic papers

DuckDuckGo

Web search