How to create your
first AI agent
AI agents are changing how we interact with technology.
This guide explains how they work and how to create your own.

Introduction
What is an AI agent?


What agents can do
- Executing code
- Web scraping
- Calling APIs
- Query databases
- Search for files
- Or they can even control your computer

About the author
Liam McCormick
Senior AI Engineer - Innovation
For the last two years, I've explored the impact of AI agents and created applications that actually use agents in practice. This guide details what I've learnt about the technology and the best practices that you can follow.
How companies are using AI agents
| Company | Use Case | Description | Link |
|---|---|---|---|
| Klarna | Customer service | Multiple agents are used to handle requests from Klarna's users. The agents are able to handle payments and refunds for customers, with the option to escalate to humans when needed. | Article |
| Anthropic | Software development | Code assistant that is run from the Terminal. It's able to understand your codebase, edit files, and create new software features. | Article Code |
| Uber | Software testing | Automatically generates unit tests for their huge code base. Two agents work together and create the unit tests needed, along with the dependencies. An executor agent runs all the generated test cases and checks if they passed or not. The fixer agent identifies issues with the failed tests and tries to fix them. Once the changes are made, the executor runs the test again. Refactor and validator agents then ensure that the tests follow Uber's code conventions and are making the correct assertions. | Presentation Slides |
| GPT Researcher | Research | Agent that searches the web for info about a specific topic and generates detailed reports. These reports are often several pages long and are broken down into sections. Once the agent is done, you can save the file as a Word document and review it. | Website Code |
| Replit | Software development | Develops an initial plan for how the agent should tackle the problem. It then handles the code generation, environment, dependencies, and finally deploys the application. | Article |
| Vodafone | Information retrieval | Agent is connected to the company's data on Sharepoint and can analyse thousands of files. It's used by engineers to find information quicker, without having to manually search through the documentation. | Article |
| OpenAI | General tasks | General agent that is run from the ChatGPT website. The ChatGPT agent can use the browser, create presentations, spreadsheets, and run terminal commands. | Article |
Benefits of agents
- Incredibly flexible – you can let them work out the steps needed; we don't need to define every stage in the process – like you would when chaining prompts.
- Better results – by splitting a task among several agents, they are more focused than when you only use one LLM.
- Groups of agents – several agents can communicate with each other and decide which agent is best-suited for the task.
- Generate, check, and improve – an agent can generate the first draft, ask other agents to review it and provide feedback, and then use their responses to improve the content.
- Multiple models – you can use a mixture of models from different vendors, such as OpenAI, Anthropic, and Mistral.
- Humans are in-the-loop – you can intervene and tell the agents to go down a different path.

Limitations
As with any technology, there are limitations in what you can do. Many of the issues that we have with LLMs can also be applied to AI agents, since they are underpinned by these models:
- Hallucinations - Large Language Models can occasionally make up information. At first glance, their response looks believable - but it isn't true at all.
- Limited understanding - while these systems can process and generate text that seems intelligent, they don't truly comprehend the meaning behind the words in the way humans do. As a result, it's pretty easy to misdirect and confuse them.
- Biased training data - AI companies have used social media posts and books to train these models, which will often contain different biases. This means the AI can unintentionally reproduce or amplify these biases in its responses.
- Small context windows - LLMs often struggle to maintain context over long interactions and may forget important details that you mentioned earlier in a conversation. To deal with this, I recommend that you divide your task into smaller pieces and assign multiple agents - which will lead to much better results.
Risks
Since AI agents can act on their own and execute code, they also pose new risks that we need to consider:
Human oversight - should a human review the agents' output and be able to stop them?
With most agent frameworks, you can tell the agents to ask a human for advice before they progress.
Misuse - have you added restrictions to prevent your agents being used for another purpose?
For example, users could re-direct your agents and ask them to generate misinformation. Microsoft and AWS offer services that check for abusive prompts and can block them. You should also consider logging how users are prompting the agents, so that abuse can be spotted.
Malicious code - if you have allowed your agents to execute code on a computer, have you ensured that the device doesn't contain confidential information?
For example, users could ask your agents to execute malicious code and wipe the computer - or extract confidential files. You should ensure that the agents are running on a container and can't interact with important files.
Lack of explainability - can you explain and understand how the agents reached a decision?
Do we know why the agents have gone off-course and did the wrong action? You should consider logging the messages that are sent between the agents, as this will give you insight into their discussions and why they made a decision.
Looped conversations - have you restricted the number of messages between the agents?
It's incredibly rare, but agents can sometimes get into a loop and constantly message each other. To prevent this, you should use the latest LLMs, avoid using small language models, and set a hard limit on the number of messages between agents. This will automatically break any message loops that occur and prevent unnecessary costs.
The above isn't an exhaustive list, but they're worth considering to ensure that your project is ready for deployment.

Creating your own agents
Decide on a task you want to automate and simplify
- If you're unsure and need inspiration, you can look at the examples above from other companies
Think about what the agent needs to do
- Does it need to analyse a small or large amount of text?
- Should it have access to tools?
- Do you just need one agent or multiple agents?
Get started and explore different ideas
- The best way to learn is to get started
- I've included a template in the next section, which will help you to try different ideas
Build on your idea and keep improving it
- Learn from techniques and tools that others are using
- Read documentation about the AI agent framework

Getting started


Read by executives at:

Loop