top of page

How to create Agents in Layla

Layla gives you the ability to create and customise your own Agents, so you can create your own features!


This article will go through creating a basic agent, then give an explanation on how Agents work in Layla. Then we will create a slightly more complex Agent.


If you want to know how Agents work in Layla in general, read this: https://www.layla-network.ai/post/how-to-enable-agents-functions-and-tool-calling-in-layla


Creating an Agent

Without boring you with the details on how Agents work, let's get started immediately!


Go to the Agents mini-app in Layla:


App screen with 6 icons: torch, brain, robot, cloud, light bulb, and books. "Apps" text and red arrow pointing to "Layla Cloud." Dark starry background.
Select the Agents mini-app

The easiest way to create an Agent is to duplicate an existing one (don't worry about the Add New Agent button just yet, those are for advanced users).


UI displaying automation agents with options like Edit, Test, Share. Red arrow highlights Duplicate for "DuckDuckGo: News Search."
Duplicate agent button

After duplicating any existing Agent, you can edit your newly copied agent using the Edit button.


The Edit button will open a popup with the Agent details. We are going to create a simple Agent which obtains a random cat fact from a public API!

Step 1: open the edit Agent popup


Edit Agent screen displays fields for "Name" and "Description," with options like Regex triggers. Buttons for Cancel and Save are at the bottom.

Step 2: delete the triggers and tools


Edit Agent screen showing input fields for Name and Description, with a red delete icon and blue Save button highlighted by a large arrow.

Step 3: Edit the name and description


UI screen for editing an agent. Fields for Name and Description show "Cat facts" and "Get a random cat fact." Options to add tools, cancel, or save.

The name and description are only for your reference, it is not used at the moment (note: in more complex agents, the name and description are important!).


The next step is to add a trigger. Tap the plus sign next to "Triggers" and choose the "Phrase" trigger. This is a simple trigger that will trigger the Agent when you enter a certain phrase in your chat. This is the simplest of triggers. Don't worry about the other options yet!


Edit Agent screen with "Triggers" panel, red arrows point to plus icon and word "Phrase." Black background, blue "Save" button.

We are going to trigger this Agent whenever the words "cat fact" is sent. So, this will include things like "send me a cat fact", "what's a cool cat fact", etc.


Edit Agent screen shows a setup for "Cat Facts," describing it as getting random cat facts. Features include "Triggers" and a blue "Save" button.

The trigger phrase is "cat fact", this is case-insensitive, so it doesn't matter if you enter "cat fact" or "Cat fact". Since we only have one trigger, the exclusivity option does not matter, we will leave it at OR.


Next, we add a tool for this Agent. We will use the HTTP Request tool. Our "cat fact" API is a simple public API here: https://github.com/wh-iterabb-it/meowfacts


UI screen showing "Edit Agent" with a list of options like DuckDuckGo and HTTP Request. Red arrow points to HTTP Request. Options to Cancel or Save.

Add the HTTP Request tool, and configure it as shown below:


Edit Agent screen showing HTTP Request settings. URL is https://meowfacts.herokuapp.com. Options include GET method. Cancel and Save buttons visible.

The Url field is simply the URL given in the documentation link for the API. The request is a GET request. We can leave the other two fields blank.


The first tool is added!


This tool makes the GET request to the specified API and obtains the result. The next step is to tell Layla how to use the result. The simplest way to do this is through the Provide Context tool. This tool takes input and injects the contents of the input into the context of the conversation. Layla will pick up the context and give a response accordingly.


Scroll down to the bottom of this tool and tap on Add Tool again. This time, choose the Provide Context tool. This tool will be chained behind the HTTP Request tool we just added.


Edit Agent screen with options like "Layla: Add to References" and "Spotify: Search." A red arrow points to "Provide Context."

We tell the LLM that this cat fact comes after searching the web:


Edit Agent screen showing text input settings. "Provide Context" section with a toggle for LLM tool call. Buttons labeled "Add Tool," "Cancel," and "Save."

Note we use the special template {{input}}. This is a special template which will be replaced with the output of the previous tool (i.e. the output of the previous tool is the input of the current tool). (Don't worry about other options such as LLM tool call yet).


And voila! The Agent is complete. Save it and go back to start a chat with Layla.


Chat interface with a conversation about cat facts. Text shows cats have 30 vertebrae. Dark hexagonal background, casual mood.

You can see your new Agent in action! It makes an HTTP Request to your URL, and injects the result + instructions into the context!


Conclusion

You can see how Agents work in general in Layla: each Agent is triggered under specific conditions, whether they are phrases, regex, or other more complex conditions. Then the Agent will call each configured tool in sequence, chaining the output of the first tool as the input of the next tool.


The Provide Context tool is a very important tool because of this process! This is usually the last tool you add to your agent, as it provides feedback to the LLM (Layla in this case) of the execution results. Without this tool, the Agent will execute silently, and Layla won't know about it. You will almost always use this tool when creating your own agents.


A slightly more complex agent

Here's an example on how to create a slightly more complex agent that uses your LLMs "brain"!


We make a simple HTTP Request again to an API. The API will get a random picture of a dog: https://random.dog/woof.json


This time, the API returns the URL of an image. We then ask the LLM to format it correctly and display it!

Step 1: the HTTP request tool works similar to before (except we change the API URL). The difference is the instruction we put in the Provide Context tool. We tell the LLM the result is a JSON with the "url" field, which is used to display the image in Markdown format.


Dark interface displaying an "Edit Agent" window with toggle options for LLM tool. Visible buttons: "Add Tool," "Cancel," "Save."

Step 2: Here is the result of executing the agent!


Note this complex agent works best with a bigger model (~8B+), you can still see some artifacts where the LLM did not format the image completely correctly.


Tan dog resting on a beige couch, looking content. Text above reads "Random Dog Picture" and "Random dog pic" in a chat interface.

This demonstrates the powerful functions you can achieve with Layla Agents!


Now, you are ready to learn how to create actually useful Agents in the next articles:

Email

Location

Gold Coast, Australia

SUBSCRIBE

Sign up to receive news and updates from Layla

Thanks for submitting!

© 2024 by Layla Network

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