Functions are Python files that add deterministic logic to your agent. They can be called by the model, used as flow steps, or run automatically at call start and end.
Functions are how the ADK handles behavior that should not be left to prompt interpretation alone.Where functions live
Function types
What functions are for
Functions are useful when you need deterministic behavior such as:- validating input
- routing based on state
- calling APIs
- writing metrics
- setting variables
- transferring calls
- starting or ending flows explicitly
Global functions
Reusable functions that can be called by the model.
Transition functions
Flow-local functions used for step transitions and routing.
Function steps
Deterministic flow steps with no LLM decision-making.
Lifecycle functions
Hooks that run automatically at the start or end of a call.
File structure rules
Every.py file must define a function with the same name as the file, excluding .py.
That function is the entry point when the file is called by the model or runtime.
Every function file must include this import line:
Decorators
Global and transition functions use decorators to describe themselves to the model.Supported decorators
Function steps do not support
@func_description or @func_parameter.
Parameter types
Supported parameter types map to schema types as follows:Example
Naming guidance
Prefer naming functions after the event that should trigger them, rather than the internal action they perform.Prefer
first_name_providedbooking_confirmed
Avoid
store_first_namesend_confirmation
Returns and control flow
Functions can influence the conversation in several ways.Calling other functions
You can call functions from within functions.Global function call
Flow function call
Start function
start_function.py runs once at call start, before the first user input.
Signature
Typical uses
- initialize state
- read SIP headers
- set language
- write initial metrics
- send the agent into the first flow
End function
end_function.py runs once at call end, after the conversation completes.
Signature
Typical uses
- aggregate metrics
- write final outcome metrics
- trigger post-call behavior in live environments
Utility modules
If a function file is not intended to be called by the model, it still needs a main function matching the filename. Decorate that main function and have it return a utility-module message. Helper functions inside the file should not be decorated.State
Functions read and write conversation state viaconv.state. See the Variables reference for the full details on setting, reading, and referencing state in prompts.
Metrics and logging
Functions are a natural place to write metrics and logs.Metrics
Examples:Logging
Examples:Good practices
- use
SCREAMING_SNAKE_CASEfor metric names - use grouped naming patterns where helpful
- use
write_once=Truefor one-time events - log important outcomes around external calls and failures
Related pages
Flows
See how function steps and transition functions fit into flow design.
Variables
Learn how state variables are discovered and referenced.
Topics
See how functions are called from topic actions using
{{fn:...}}.
