function
A function is a reusable, named part of a program that performs a well-defined task and usually returns a result.
In plain terms
Imagine a function as a recipe in the kitchen. The recipe has a name (for example, 'pancake batter'), specifies the required ingredients, and always yields the same type of result. You do not need to figure it out anew each time; it is enough to say, 'make the pancake batter for four people.'
Programmers break software into functions so they do not have to write the same operation a hundred times. If the step that calculates the gross price from the net price lives in a single function, then fixing a bug or changing a VAT rate has to be made in only one place.
In the AI world, the word has gained new significance. A language model alone only writes text, but functions are its 'hands': through them, an agent can query the weather, send emails, or search a database. This is called function calling or tool use.
How it works
- The developer writes the function: gives it a name, specifies what input data (parameters) it expects, and describes the steps to be executed.
- At other points in the program, the function is called by its name and passed specific values, such as a price of 10,000 forints and a VAT rate of 27 percent.
- The function executes its own steps, can even call other functions in the process, and then returns the result (return value) to where it was called from.
- The program continues from where it left off before the call and proceeds using the received result.
- In the case of an AI agent, the developer pre-defines which functions are available. The model only indicates which one it requests and with what data; the actual execution is performed by the surrounding program, which returns the result to the model.
An everyday example
When you type =SUM(A1:A10) in Excel, you call a function: you specify the cells, and you get their sum back. Something similar happens when you ask a chat AI about tomorrow's weather and the AI is connected to a weather-query tool. In this case, this function runs in the background, and the AI formulates the answer based on its result.
Who is affected
A common misconception
Limits and risks
- A function is only as reliable as how carefully it was written: it may produce incorrect results on faulty or unexpected input, even without an error message.
- The function name is no guarantee that it actually does what it promises; therefore, it must be tested and documented.
- An AI agent may choose the wrong function or call it with incorrect data, so for irreversible operations (payment, deletion, sending emails) it is advisable to request human approval.
- The more functions and the stronger the capabilities an agent has, the greater the damage if it is deceived or makes a mistake, so it is advisable to grant only the permissions necessary for the task.
Similar, but not the same
- mathematical function – A mathematical function only maps one value to another, whereas a program function can also perform operations, such as saving a file or sending a message.
- API – An API is an external interface to a full service that typically aggregates many callable functions, while a function is a single operation.
- algorithm – An algorithm is the theoretical description of the steps of a solution, while a function is the specific, named code segment in which it is implemented.
Related concepts
programming, source code, szoftver
function calling, parameter, return value, method, recursion
A brief history
The word moved from mathematics into programming. The idea of reusable program parts (subroutines) dates back to the late 1940s. The first practical solutions were developed for the British EDSAC computer. The second version of the FORTRAN language, in 1958, already let programmers write their own functions and subroutines. The function-calling capability of language models became widely available in 2023.
Where things stand
The function is a basic element of practically every programming language. By the end of 2026, it had also become standard practice for AI agents to carry out tasks through functions, that is, tools.
In the news
- Anthropic reports theoretical weakness in some post-quantum encryption methodsNov 30, 2026 · Agent Age
- OpenAI leaders propose tying superintelligence development limits to the reliability of safety methodsNov 30, 2026 · Work & HR
- South Korea deploys 8500 extra invigilators for university entrance examNov 30, 2026 · Education & Family
- How much electrical load will a new GPU server add?Nov 30, 2026 · Industry
- US open-weight models performed better on legal tasks after post-trainingNov 30, 2026 · Law
- Combining data sources improved AI predictions of atrial fibrillation, review findsNov 30, 2026 · Health
- Swiggy Instamart restructuring affects around 340 jobsNov 27, 2026 · Work & HR
- Coding agents can check for video errors during renderingNov 27, 2026 · Code
Also known as
function · function · function · szubrutin · procedure · method · function calling · function calling
Sources
This entry was machine-edited and has undergone machine expert review; the “In the news” section updates automatically from Agent Age stories.