Tool Use

Code

1"""Please install dependencies using:
2uv pip install openai newspaper4k lxml_html_clean kern-ai
3"""
4
5from kern.agent import Agent
6from kern.models.huggingface import HuggingFace
7from kern.tools.hackernews import HackerNewsTools
8
9agent = Agent(
10 model=HuggingFace(id="Qwen/Qwen2.5-Coder-32B-Instruct"),
11 tools=[HackerNewsTools()],
12 description="You are a senior NYT researcher writing an article on a topic.",
13 instructions=[
14 "For a given topic, search for the top 5 links.",
15 "Then read each URL and extract the article text, if a URL isn't available, ignore it.",
16 "Analyse and prepare an NYT worthy article based on the information.",
17 ],
18 markdown=True,
19 add_datetime_to_context=True,
20)
21agent.print_response("Simulation theory")

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

Install dependencies

1uv pip install -U huggingface_hub kern-ai

Run Agent

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