What is an AI Agent
An AI agent is a software system that perceives its environment, decides on the next action towards a defined objective and executes that action through external tools. Most modern AI agents use a large language model to select each action, repeating this cycle until the objective is achieved or a configured limit is reached.
- Objective: It receives a task to complete, such as "repair the failing build", rather than a single question to answer.
- Perception: It collects information from its environment, including application logs, performance metrics, source files and previous tool results.
- Decision-making: A large language model (LLM) or a predefined set of rules determines the next action.
- Action: It operates through tools, which are functions that retrieve information or modify an external system.
- Iteration: It evaluates every result and decides again, instead of terminating after a single response.
For example, a coding agent inspects a failing continuous integration (CI) log, searches the repository, verifies a correction with the test suite and opens a pull request.
Key Characteristics of an AI Agent
- Autonomy: The agent selects its next action without individual human approval, within boundaries defined by the engineering team.
- Tool use: The model requests a specific function with arguments through tool calling, and application code executes it.
- State management: The agent retains the results of earlier actions, as described in memory in AI agents.
- Reactivity: It responds to new observations, such as an unexpected error message after a test execution.
- Limited permissions: It operates only with the specific tools, credentials and repositories it has been assigned.
- Termination conditions: It stops when the objective is satisfied, when an iteration limit is reached or when a human decision is necessary.
How AI Agents Work
- Receive the objective: The agent obtains a task and its constraints, including the repository and the permitted tools.
- Perceive the environment: It retrieves the current state, for example the complete log of the failed CI job.
- Select an action: The model chooses one tool and its arguments, frequently returned as structured output in JSON format.
- Execute the action: Application code invokes the selected tool, such as a code search or an automated test execution.
- Record the observation: The tool result is appended to the agent's context for the following decision.
- Continue or terminate: The cycle repeats until the objective is achieved, a limit is exceeded or the task is escalated to a developer.
This alternation of reasoning and action is formalised in the ReAct agent pattern. The individual components are examined in AI agent architecture. The distinction from conversational systems is explained in AI agent vs chatbot.
Example: A Minimal AI Agent in Python
The following program implements an agent with a tool registry and a rule-based policy, which substitutes for an LLM.
# A minimal coding agent: a tool registry, a rule-based policy and a loop.
# Standard library only. The policy is a stand-in for an LLM.
CI_LOG = "FAILED test_dates.py: ImportError: cannot import name 'parse_iso'"
SOURCE = {"app/dates.py": "def parse_iso_date(text):"}
def read_ci_log(job):
return CI_LOG
def search_code(name):
for path, code in SOURCE.items():
if name in code:
return f"{path} defines {code.split()[1].split('(')[0]}"
return "no match"
def run_tests(change):
return "12 passed, 0 failed" if change else "11 passed, 1 failed"
def open_pull_request(title):
return f"PR #481 opened: {title}"
TOOLS = { # tool registry: name -> function
"read_ci_log": read_ci_log,
"search_code": search_code,
"run_tests": run_tests,
"open_pull_request": open_pull_request,
}
def policy(memory):
# Stand-in for the LLM: choose the next tool from what is already known.
if "read_ci_log" not in memory:
return "read_ci_log", "build-main-812"
if "search_code" not in memory:
return "search_code", memory["read_ci_log"].split("'")[1]
if "run_tests" not in memory:
new_name = memory["search_code"].split()[-1]
return "run_tests", f"import {new_name} instead"
if "0 failed" in memory["run_tests"] and "open_pull_request" not in memory:
return "open_pull_request", "Fix renamed import in test_dates.py"
return "stop", None
def run(goal, max_steps=6):
print("Goal:", goal)
memory = {} # observations so far, keyed by tool name
for step in range(1, max_steps + 1):
tool, arg = policy(memory)
if tool == "stop":
print(f"{step}. stop: goal reached")
return
memory[tool] = TOOLS[tool](arg)
print(f"{step}. {tool}({arg!r})\n -> {memory[tool]}")
print("Step limit reached, handing over to a developer")
run("Make the failing CI job on main pass")Goal: Make the failing CI job on main pass
1. read_ci_log('build-main-812')
-> FAILED test_dates.py: ImportError: cannot import name 'parse_iso'
2. search_code('parse_iso')
-> app/dates.py defines parse_iso_date
3. run_tests('import parse_iso_date instead')
-> 12 passed, 0 failed
4. open_pull_request('Fix renamed import in test_dates.py')
-> PR #481 opened: Fix renamed import in test_dates.py
5. stop: goal reached- Tool registry: The policy identifies a tool by name, and the control loop locates and invokes the corresponding function.
- Observation-driven decisions: Every decision depends on previous results, such as the missing function name extracted from the log.
- Production systems: In an LLM agent, a model call replaces the policy function, while the iteration limit and the permitted tools remain in application code.
AI Agent Examples and Applications
- Coding agents: Repairing failing tests, updating dependencies and preparing pull requests for review.
- DevOps triage: Analysing alerts, logs and metrics, then creating a ticket with the probable cause.
- Data engineering: Detecting a failed pipeline execution, identifying the invalid input and rerunning safe operations.
- IT service management: Processing routine requests, such as access permissions, through approved integrations.
- Security operations: Collecting contextual information about an alert before an analyst reviews it.
- Research assistance: Retrieving relevant documentation with RAG and compiling a summary with citations.
Advantages
- Reduced repetitive work: Engineers evaluate a proposed correction instead of repeating identical diagnostic procedures.
- Faster response: Diagnostic evidence is collected within seconds of a failure, at any hour.
- Multi-step automation: A single agent can coordinate several systems, such as CI, the code repository and the issue tracker.
- Adaptability: The agent can select an alternative tool when an operation returns an unexpected result.
Limitations
- Incorrect actions: A misinterpreted log can produce an incorrect modification, so code review and testing remain necessary.
- Cost and latency: Every iteration requires a model call, so extended tasks are more expensive and slower.
- Security exposure: Text inside a log or a source file can contain hidden instructions, a vulnerability called prompt injection.
- Evaluation difficulty: Identical objectives can produce different execution paths, which complicates reproducible testing.
- Oversight requirements: Risky operations, such as merging into the main branch, still require human-in-the-loop approval.
AI agents are the individual components of larger goal-driven systems, which are described in what is agentic AI.
Quick Quiz
Pick an answer to check yourself. Nothing is saved.
Question 1 / 3
1. Which feature separates an AI agent from a single LLM call?
Frequently Asked Questions
What is an AI agent in simple terms?
An AI agent is a program that is given a goal and works towards it by choosing and running actions. It reads the result of each action and decides what to do next. A coding agent, for instance, can read a failing test log, change the code and open a pull request.
Is ChatGPT an AI agent?
A chat assistant that only answers messages is not an agent in the strict sense. It behaves as an agent when it is given tools, such as code execution or search, and runs several steps on its own towards a task. The setup decides this, not the product name.
What are the main components of an AI agent?
Most AI agents have four parts: a model that decides, tools that act, memory that stores results and a control loop that repeats the cycle. Guardrails, such as step limits and approval rules, sit around these parts.
What is the difference between an AI agent and agentic AI?
An AI agent is one worker: a model with tools running a loop to finish a task. Agentic AI is the wider approach of building goal-driven systems with some autonomy, which may combine several agents and human approval steps.
Do AI agents need an LLM?
No. Classic agents in robotics and games use fixed rules, search or reinforcement learning. Most current software agents use an LLM because it can read unstructured text, such as logs and error messages, and choose a tool from a description.
Related Articles
- Types of AI AgentsThe types of AI agents compared: simple reflex, model-based, goal-based, utility-based, learning and LLM-based agents, plus a Python CI agent example.
- AI Agent ArchitectureAI agent architecture explained: the model, tools, memory, control loop and guardrails, how they interact, and a traced Python skeleton for a DevOps agent.
- Tool Calling (Function Calling) in LLMLearn how tool calling works in LLMs: JSON Schema tool definitions, model tool calls, argument validation and tool results, with a Python DevOps example.
- AI Agent vs Chatbot vs AI AssistantAI agent vs chatbot vs AI assistant: a comparison table of autonomy, tools, memory and risk, when to use each, and one CI failure handled by all three.
- ReAct Agent ExplainedLearn how a ReAct agent alternates thought, action and observation, with a Python example that traces a failing unit test to a commit and opens a ticket.
- What is Agentic AIAgentic AI explained: what it is, its key characteristics, how the agent loop plans and uses tools, a Python incident agent example, uses and limitations.