top of page

How to create a DuckDuckGo news search agent with Python in Layla

In this article, let's look at how to create a DuckDuckGo news search agent. This agent will be running in Python. We will be using the Agents mini-app in Layla to create this. Make sure you have Python enabled in Layla: https://www.layla-network.ai/post/how-to-enable-python-support-in-layla


Step 1: duplicate any existing agent

The easiest way to start is to duplicate any existing agent. Then, edit the copy. Modify their name and description.


Edit Agent screen showing text fields for Name and Description. "DuckDuckGo: News Search (Python)" is entered. Save and Cancel buttons are visible.

Step 2: add triggers

Let's add a few triggers to this agent.


Edit Agent screen showing trigger options: Intent, Regex, Phrase, Date/Time, MCP Tool, Layla Tool, Is Voice Mode. Buttons: Save, Cancel.

We are going to add the "News Search" intent, and a hardcoded "news" phrase. Feel free to add your own triggers depending on how you would like to call this agent.

Dark interface screen showing "Intent: News Query" with buttons labeled AND, OR, NOT, and a trash icon in the top right.
Dark app interface showing the word "News" in a text box labeled "Phrase" with buttons "AND," "OR," and "NOT" below.

Step 3: add the Python tool

Let's add the Execute Python tool next. This section contains the Python code that will actually execute the logic to query DuckDuckGo. You will need some familiarity with Python to understand this part.


Let's take a look at the Python code: https://gist.github.com/l3utterfly/bf9f703c09932fd87dbf68f2118e5ab4 (the link goes to a Github Gist file)


At the top of the file, notice we need the requests library ("re" and "html" are part of Python):

Python code snippet showing imports: requests, re, and html, on a black background.

Let's go to the Python mini-app and add the package "requests": https://www.layla-network.ai/post/how-to-enable-python-support-in-layla


The next part is the "QUERY":

Code snippet with query syntax in blue highlights and "LIMIT = 5" in white against a black background.

Note here that Layla injects the input (from your message or the previous tool's output) into a special template "{{input}}". This is done via simply text replacement, your input is not modified further.


You can use this pattern to receive different kinds of input into your Python script.


For this agent, we will simply pass the whole user query into the Python script.


The Python script then does a standard HTTP request and parses the response with the built in HTML parser.


The next interesting bit is how the Python script passes information back to the LLM. This is done simply via "print" statements.

Code snippet showing a Python loop that checks for news results. If found, it prints the title, source, summary, and URL.

This makes it very flexible. You can just print out what you need the LLM! It could be results, it could be instructions, it could be a combination of both!


Let's copy and paste the whole python script in the input of the Python tool:


Mobile app interface showing an "Edit Agent" screen with Python code. Options to toggle LLM tool, and buttons for "Cancel" and "Save".

And your agent is done!


Lastly: test out the agent

Let's test the agent out! Remember to enable it for use in the default character Layla, or attach it to your existing character!


Chat interface with dark hexagonal background. A message asks, "Whats in the news today?" Python code execution notification displayed.

You can see the agent starts to execute your Python code after when the keyword "news" is triggered (remember you configured this trigger in the first step).


Chat interface with Layla summarizing five news updates, featuring space missions, consumer reports, retirement, romance, and a new development.

Layla will read the output from the Python code, and use it as context to answer your question!


This concludes a simply DuckDuckGo news search agent! In the future articles, we will be creating more complex agents.


Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating

Email

Location

Gold Coast, Australia

SUBSCRIBE

Sign up to receive news and updates from Layla

Thanks for submitting!

© 2026 by Layla Network

  • Discord
  • Youtube
  • TikTok
  • X
  • Facebook
bottom of page