How to Set Up an AI Agent for Small Business: A Step-by-Step Guide
On October 30, 2026, an article was published about five ways small businesses use AI agents. We break down how to build a simple agent to automate routine tasks: from setting a goal to launching and common mistakes.
On October 30, 2026, an article was published about how small businesses use AI agents (programs that perform tasks on their own according to instructions) to combat overload. We are not summarizing the article, but showing how to build one such agent yourself. The guide is intended for an entrepreneur without deep technical knowledge.
What you will need
- A computer with internet access.
- An account with an LLM (large language model) provider. OpenAI, Anthropic, or another will work. You need an API key.
- Python 3.9 or newer. Installer from python.org.
- The pip package manager (comes with Python).
- A text editor (VS Code, Notepad++, or any other).
- Basic understanding of the command line: being able to open a terminal and run a command.
- There is no data on which provider is cheaper or more reliable — choose based on the documentation.
Step 1. Define one task for the agent
Do not try to automate everything at once. Choose a repetitive operation that you do manually. For example: answering typical customer questions, sorting incoming emails, or task reminders.
Write the task in one sentence. Example: “The agent reads incoming emails and marks those that require a response within the day.”
Check: if the task can be described by an algorithm of 3–5 steps, it is suitable for the first agent.
Step 2. Install the library for working with LLM
Open the terminal. Run:
pip install openai python-dotenv
This will install the official OpenAI library (it also works with other providers through a compatible API) and a module for loading keys from a file.
If you use Anthropic, the command will be pip install anthropic python-dotenv.
Step 3. Save the API key in an environment variable
Create a .env file in the project folder. Insert the following line into it:
OPENAI_API_KEY=YOUR_KEY
Replace YOUR_KEY with the key issued by the provider in your account. Do not publish this file in public repositories.

To make Python see the key, add the following to the beginning of the script:
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv("OPENAI_API_KEY")
if not api_key:
raise ValueError("OPENAI_API_KEY not found. Check the .env file")
Step 4. Write a simple agent
Create a file agent.py. Insert the code:
import os
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
def ask_agent(task: str, user_input: str) -> str:
prompt = f"""You are a small business assistant. Your task: {task}.
Input data: {user_input}
Answer briefly and to the point."""
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": prompt}],
temperature=0.3,
)
return response.choices[0].message.content
if __name__ == "__main__":
task = "determine whether the email requires an urgent response. Answer 'yes' or 'no' and explain why in one phrase."
email_text = "Hello! My website is broken, customers cannot place an order. Help urgently."
print(ask_agent(task, email_text))
Run:
python agent.py
You should see a response like “yes, because the client reports a breakdown that blocks orders.” If the response is different, check the key and the model.
Step 5. Connect the agent to a data source
For the agent to work with real emails rather than an example, it needs access to mail. A simple way is to use IMAP (a protocol for reading mail). Install the library:

pip install imap-tools
Add reading of the latest email to the script:
from imap_tools import MailBox, AND
with MailBox("imap.gmail.com").login("YOUR_EMAIL", "YOUR_APP_PASSWORD") as mailbox:
for msg in mailbox.fetch(AND(all=True), limit=1, reverse=True):
email_text = msg.text or msg.html
print(ask_agent(task, email_text))
For Gmail, an app password is required (created in the account settings). A regular password will not work. There is no data on how this works in other email services — check their help.
Step 6. Set up regular execution
The agent should work on its own. On Linux or macOS, use cron. Open the scheduler:
crontab -e
Add the line (run every hour):
0 * * * * cd /path/to/project && /usr/bin/python3 agent.py >> agent.log 2>&1
On Windows, use Task Scheduler: create a task, set the trigger to “every hour” and the action to “Start a program” with the path to python.exe and the argument agent.py.
Check that entries appear in the agent.log file. If not, look for errors in the same log.
Common mistakes and how to recognize them
- Authentication error. In the log you see
AuthenticationErroror401. Cause: incorrect key or it was not loaded. Check that the.envfile is in the same folder as the script and that the variable is named exactlyOPENAI_API_KEY. - The agent answers off-topic. The model produces general phrases. Refine the instruction in
task: add the response format, constraints, examples. Do not give the agent too broad a task. - The script crashes when reading mail. Error
imaplib.IMAP4.error. Check that IMAP is enabled in the mail settings and that an app password is used, not the main one. - Exceeding the request limit. In the log
RateLimitError. Reduce the launch frequency or contact the provider to increase the quota. There is no data on specific limits — see the pricing plan. - The agent sends emails without your knowledge. If you add a sending function, restrict it: for example, send only after manual confirmation. Automatic sending without verification can harm your reputation.
Start with one agent and one task. Once you are sure it works stably, add the next one. This way you will avoid the overload that you were trying to remove in the first place.