Agent with Tools

Give your agent tools to interact with external services.

Give an agent tools to interact with external services. The agent uses HackerNewsTools to fetch trending stories and user details.

Create a Python file

1from kern.agent import Agent
2from kern.models.anthropic import Claude
3from kern.tools.hackernews import HackerNewsTools
4
5agent = Agent(
6 model=Claude(id="claude-sonnet-4-5"),
7 tools=[HackerNewsTools()],
8 instructions="Write a report on the topic.",
9 markdown=True,
10)
11
12agent.print_response("Trending AI startups on Hacker News", stream=True)

Set up your virtual environment

1uv venv --python 3.12
2source .venv/bin/activate
1uv venv --python 3.12
2.venv\Scripts\activate

Install dependencies

1uv pip install -U kern-ai anthropic

Export your Anthropic API key

1export ANTHROPIC_API_KEY="your_anthropic_api_key_here"
1$Env:ANTHROPIC_API_KEY="your_anthropic_api_key_here"

Run Agent

1python tools.py