How an AI agent is built and how it works, from the model to human control
An AI agent works in a loop: it receives a task, the language model drafts a plan, the agent calls the tools it is allowed to use (searching documents, writing to the CRM, sending a notification), looks at the result and decides what to do next, until the task is done or a human is needed. Memory gives it the conversation context and access to your data, while permissions, confirmations and a log keep its actions under control. Agents are connected to your systems through APIs and configured with instructions, test examples and narrow permissions.
Open the software development page
How an AI agent works: a four-step loop
From the outside an agent looks like a colleague you can hand work to. Inside, it is a program that repeats the same loop many times in a row. Understanding that loop helps both the client and the people who will work with the agent: it makes it easier to set tasks and to see where the agent can go wrong.
- Task. The agent receives an assignment: an employee question, a customer email, a new request or an event in a system.
- Reasoning and plan. The language model breaks the task down and decides which step comes first: find a document, read the customer record, ask a clarifying question.
- Action. The agent calls one of its permitted tools and gets a result: a document fragment, CRM data, a response from another system.
- Check. The model looks at the result and decides whether it is enough. If not, it takes the next step; if yes, it produces the outcome: an answer, a draft or a completed action.
The loop repeats until the task is solved, the step limit runs out, or the agent hits a rule that says a human is needed here. This ability to choose the next step on its own is what separates an agent from an ordinary chatbot and from rigid rule-based automation. What agents are useful for in business and which tasks companies hand them is covered in our guide on the AI agent for business; this guide is about how they are built.
The model: what it does and what it does not
The language model is the brain of the agent. It understands a task phrased in plain words, picks a tool, writes the request to it and composes the final text. An agent needs the AI model not to store facts but to reason and to work with text.
It is important to understand the limits. The model does not know your policies, prices or customers until they are passed to it in the request. It can be confidently wrong when it has nothing to rely on. And it does nothing in your systems by itself: every action is carried out by the agent code, which takes the decision from the model and checks whether it is allowed.
That is why the choice of model is not the main decision in a project. The model is chosen for the task: answer quality, speed, running cost and requirements on where data is processed. The agent is built so that the model can be replaced without rebuilding the whole system. Where the model can run, on your servers or at a provider, is covered in our guide on local vs cloud AI agents.
Tools: how the agent acts in your systems
A tool is a described action the agent is allowed to perform. Each tool has a name, a description the model can understand, input fields and limits. For example: find a contract by counterparty name, create a CRM task with an owner and a deadline, send a notification to a manager.
The model does not press buttons or write directly to a database. It replies with something like: call the search tool with this query. The agent code validates the request, executes it through the system API and returns the result to the model. This design gives three important things:
- The agent can only do what it was explicitly given. If there is no delete-record tool, it cannot delete a record, however the task is worded.
- Every call can be checked: are the fields correct, does the user have the right to this action, has a limit been exceeded.
- Every call is written to the log: what the agent asked for, what it received and what it did next.
There is an open protocol, MCP, for connecting tools and data sources in a uniform way. It simplifies linking an agent to your systems, but it does not replace access rights and the log; those are still defined separately.
Agent memory: what it remembers and how it knows things
The word memory means several different things for agents, and it helps to tell them apart.
- Task context. Everything the agent sees right now: instructions, the question, results of previous steps. Context size is limited, so a long conversation or a large document is given to the agent in parts or in condensed form.
- Company knowledge. Documents, policies, product descriptions. They are not loaded into the model in full; they are searched by meaning, and only the relevant fragments go into the request. How this search works and why it reduces made-up answers is covered in our guide on the AI assistant for a knowledge base.
- Work state. What has already been done on the task: which steps are complete, what awaits confirmation, where the agent stopped. This is stored in the agent database, not inside the model.
- Interaction history. Past customer requests or decisions on similar questions, if storing them is allowed and the task needs it.
The model itself remembers nothing between requests and does not learn from your conversations. Everything the agent remembers is stored and supplied by code, which means you can see exactly what it remembers and who has access to it.
The action plan and limits on autonomy
The agent splits a complex task into steps. For example, for an email saying please send the statement for last month, the agent might find the customer in the CRM, check payments, find or generate the document, prepare a reply and pass it to a manager to send.
The longer the chain of steps, the higher the chance the agent takes a wrong turn somewhere. So the plan includes safeguards:
- a limit on steps and time per task, so the agent does not go in circles;
- explicit stop points: if data is missing or the question is ambiguous, the agent asks instead of guessing;
- a split between safe actions (read, search, prepare a draft) and important ones (send to a customer, change a record, make a payment);
- narrow scenarios instead of one agent for everything: several agents with clear tasks are easier to test than one universal agent.
Human control: confirmations, permissions and the log
An agent is given exactly as much autonomy as can be verified. In practice that means three mechanisms.
- Confirmation. The agent only prepares important actions, and a person carries them out with one click: send, save, approve. The company sets the threshold.
- Permissions. The agent sees only the sources it has been given and acts within the role of the user on whose behalf it works.
- Log. You can see who set the task, which documents the agent opened, which tools it called and what happened. The log is needed for analysing mistakes and for checking quality.
Responsibility for the agent's actions stays with the company that runs it, so these mechanisms are not a formality. As the agent shows stable results on a specific task, the range of actions without confirmation can be widened.
How to connect an AI agent to your systems
Connection starts not with the model but with a question: what data does the agent need and what actions will it perform.
- List the systems: CRM, email, accounting system, knowledge base, spreadsheets, messengers.
- For each, find out how it can be accessed programmatically: is there an API, exports, webhooks. If there is no API, look for another reliable route, such as a scheduled export or an intermediate database.
- Give the agent a separate account or access key with minimal rights: read-only wherever writing is not needed.
- Describe the tools: which actions, with which fields and checks.
- Keep keys and secrets outside the code and outside the repository.
- Turn on the log and failure alerts: if a system is unavailable, the agent must stop and report it rather than invent a result.
Most often the agent is built into an existing process: a request arrives from a form, the agent parses it and creates a record, and ordinary automation takes it from there. How such links are built is described on the business process automation page.
How to configure an AI agent
Configuring an agent is not writing one good prompt once. It is several layers, each checked on real examples.
- Instructions: the agent's role, tone, what it does and does not do, when it must hand the task to a person.
- Sources: which documents and data are connected, and who keeps them up to date.
- Tools and permissions: the list of actions and where confirmation is required.
- Test set: a few dozen real tasks with a known correct result. It is run before launch and after every change.
- Monitoring: the log of the first weeks, analysis of mistakes, new cases added to the test set.
The good news is that the client does not need to understand models to configure an agent. What you need are people who know the process and can say whether the agent did the right thing. How we run such projects step by step, from reviewing the task to launch, is described on the AI agent development page.
AI agents for programming: an overview
A separate class of agents works with code. They are built the same way, with a model, tools, memory and a loop of steps, but the tools are different: read project files, find a place in the code, propose a change, run the build and tests, look at the error and try again.
Such agents handle clear, verifiable tasks well: finding the cause of a bug from an error message, writing a test, making a routine change in several places, explaining unfamiliar code. They do worse with tasks that require understanding business meaning, keeping the architecture of a large product in mind or making security decisions.
So the rules for them are the same as for any agent: work in a separate copy of the project, narrow permissions, mandatory human review before release and a green build with tests before deployment. The agent speeds development up, but responsibility for the code stays with the team.
Common mistakes when launching an agent
- Starting with a smart assistant for everything instead of one task with a clear result.
- Granting broad rights just in case and postponing the log until the first problem.
- Connecting outdated or contradictory documents and expecting accurate answers.
- Judging the agent by the impression from a demo instead of a set of real examples.
- Forgetting about maintenance: processes and documents change, and the agent has to be updated with them.
If it is not yet clear whether you need an agent, a bot or rule-based automation, describe the task in your own words on the software development page. We will review it and suggest the simplest solution.
Frequently asked questions
How does an AI agent work in simple terms?
It receives a task, the language model picks the next step, the agent performs it through a permitted tool, looks at the result and repeats the loop until the task is done or a person is needed.
How is an AI agent different from rule-based automation?
Automation runs a predefined event-to-action scheme. An agent understands free text and chooses the steps itself, so it needs safeguards, confirmations and a log.
Does the agent remember our conversations?
The model itself remembers nothing between requests. History and task state are stored by the agent code in its own database, and only what is allowed to be stored.
How do you connect an AI agent to a CRM or email?
Through the system API, or through an intermediate service if there is no API. The agent gets separate access with minimal rights, and every action is written to the log.
Do I need to understand neural networks to configure an agent?
No. The developer handles the technical side; the company provides people who know the process and can judge on real examples whether the agent acted correctly.
Can an AI agent write code?
It can take on clear, verifiable tasks: finding a bug, writing a test, making a routine change. A person reviews the result, and release happens only after the build and tests pass.
What happens if the agent makes a mistake?
The mistake is visible in the log. It is analysed, the case is added to the test set, and instructions, sources or permissions are fixed so that it does not happen again.