News Agency Team
This example shows how to create a news agency team that can search the web, write an article, and edit it.
Code
1from pathlib import Path23from kern.agent import Agent4from kern.models.openai import OpenAIResponses5from kern.team import Team6from kern.tools.duckduckgo import DuckDuckGoTools7from kern.tools.newspaper4k import Newspaper4kTools89urls_file = Path(__file__).parent.joinpath("tmp", "urls__{session_id}.md")10urls_file.parent.mkdir(parents=True, exist_ok=True)111213searcher = Agent(14 name="Searcher",15 role="Searches the top URLs for a topic",16 instructions=[17 "Given a topic, first generate a list of 3 search terms related to that topic.",18 "For each search term, search the web and analyze the results.Return the 10 most relevant URLs to the topic.",19 "You are writing for the New York Times, so the quality of the sources is important.",20 ],21 tools=[DuckDuckGoTools()],22 add_datetime_to_context=True,23)24writer = Agent(25 name="Writer",26 role="Writes a high-quality article",27 description=(28 "You are a senior writer for the New York Times. Given a topic and a list of URLs, "29 "your goal is to write a high-quality NYT-worthy article on the topic."30 ),31 instructions=[32 "First read all urls using `read_article`."33 "Then write a high-quality NYT-worthy article on the topic."34 "The article should be well-structured, informative, engaging and catchy.",35 "Ensure the length is at least as long as a NYT cover story -- at a minimum, 15 paragraphs.",36 "Ensure you provide a nuanced and balanced opinion, quoting facts where possible.",37 "Focus on clarity, coherence, and overall quality.",38 "Never make up facts or plagiarize. Always provide proper attribution.",39 "Remember: you are writing for the New York Times, so the quality of the article is important.",40 ],41 tools=[Newspaper4kTools()],42 add_datetime_to_context=True,43)4445editor = Team(46 name="Editor",47 model=OpenAIResponses(id="gpt-5.2"),48 members=[searcher, writer],49 description="You are a senior NYT editor. Given a topic, your goal is to write a NYT worthy article.",50 instructions=[51 "First ask the search journalist to search for the most relevant URLs for that topic.",52 "Then ask the writer to get an engaging draft of the article.",53 "Edit, proofread, and refine the article to ensure it meets the high standards of the New York Times.",54 "The article should be extremely articulate and well written. "55 "Focus on clarity, coherence, and overall quality.",56 "Remember: you are the final gatekeeper before the article is published, so make sure the article is perfect.",57 ],58 add_datetime_to_context=True,59 markdown=True,60 debug_mode=True,61 show_members_responses=True,62)63editor.print_response("Write an article about latest developments in AI.")Usage
Set up your virtual environment
1uv venv --python 3.122source .venv/bin/activate1uv venv --python 3.122.venv\Scripts\activateInstall dependencies
1uv pip install openai ddgs newspaper4k lxml_html_cleanSet environment variables
1export OPENAI_API_KEY=****Run Team
1python news_agency_team.py