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
- Google sued after claims Gemini gave suicide-related content to a teenagerNov 5, 2026 · Health
- Veszprém's AIéjszakája event includes a methods exchange for teachersNov 3, 2026 · Education & Family
- Australian investigation: chatbot suggested suicide method despite child modeOct 28, 2026 · Education & Family
- Hungarian and Argentine researchers improve uncertainty estimation in image-analysis AIOct 28, 2026 · Health
- Polish AI regulator's decisions to be reviewed by SOKiK under new civil procedure sectionOct 23, 2026 · Jog
- Google brings Gemini into software engineer interviewsOct 19, 2026 · Code
- Open-source REA project links AI agents to binary analysis tools to replicate paid softwareOct 19, 2026 · Code
- Survey: hospital cyberattacks delay tests and procedures and raise complication ratesOct 19, 2026 · Health
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.