Agent with Tools

Code

1from kern.agent import Agent
2from kern.models.groq import Groq
3from kern.tools.hackernews import HackerNewsTools
4from kern.tools.newspaper4k import Newspaper4kTools
5
6agent = Agent(
7 model=Groq(id="llama-3.3-70b-versatile"),
8 tools=[HackerNewsTools(), Newspaper4kTools()],
9 description="You are a senior NYT researcher writing an article on a topic.",
10 instructions=[
11 "For a given topic, search for the top 5 links.",
12 "Then read each URL and extract the article text, if a URL isn't available, ignore it.",
13 "Analyse and prepare an NYT worthy article based on the information.",
14 ],
15 markdown=True,
16 add_datetime_to_context=True,
17)
18agent.print_response("Simulation theory", stream=True)

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 GROQ_API_KEY=xxx

Install dependencies

1uv pip install -U groq newspaper4k lxml_html_clean kern-ai

Run Agent

1python cookbook/11_models/groq/tool_use.py