AI agent instructions
AI agent instructions
Writing a Function
Functions are Python scripts with arun() function that serves as the entry point.
Basic Function
The minimal Function structure:hello_function.py
Function with Parameters
Accept input parameters:greet_function.py
Browser Automation Function
Use Notte SDK for browser automation:scraper_function.py
Deploying Functions
Via SDK
Deploy from Python:Deployment Options
path(str, required): Path to your Python filename(str, optional): Function display namedescription(str, optional): What the function doesshared(bool, default=False): Whether other users can view and fork the function. Listing in the marketplace is separate (the read-onlypublishedfield).
Function Requirements
The Handler
Must have arun() function:
handler_examples.py
Dependencies
Import the Notte SDK, the standard library, and common third-party libraries such asrequests and pydantic:
dependencies.py
os, subprocess, pathlib, socket) are rejected by default, as are packages that are not available in the runtime. The upload error lists what is allowed.
Return Values
Return JSON-serializable data:return_values.py
Parameter Types
Supported Types
parameter_types.py
Type Validation
Type hints document what each parameter expects. They are not enforced, so convert or validate values yourself:type_validation.py
Complex Types
Structured parameters arrive as plain JSON values (dicts and lists). Validate them with Pydantic insiderun():
complex_types.py
Secrets
Store API keys and tokens as Function Secrets, either in the Console under Settings > Function Secrets, or withPOST /secrets using the function_env namespace (client.secrets.store(...) in TypeScript). Every run of your functions receives them as environment variables:
read_secrets.py
os module, which the default code check rejects. Upload code that reads secrets with the check relaxed: function.update(path="read_secrets.py", restricted=False) in Python, or fn.update({ path: './read_secrets.py', restricted: false }) in TypeScript.
Error Handling
Graceful Errors
Return error information in results:graceful_errors.py
Raising Exceptions
Let Functions fail explicitly:raising_exceptions.py
Testing Locally
Test Before Deploying
Run your function locally:test_locally.py
Run a Deployed Function Locally
Run the uploaded code on your machine, for example to debug it:local_run.py
Best Practices
1. Document Parameters
Use clear docstrings:document_params.py
2. Return Structured Data
Use consistent return formats:return_structured.py
3. Add Logging
Log key steps for debugging:add_logging.py
4. Set Timeouts
Bound how long each browser session can stay open, so a stuck page does not keep the run alive:set_timeouts.py
5. Validate Inputs
Check parameters before processing:validate_inputs.py
Examples
Simple Scraper
simple_scraper.py
Form Submission
form_submission.py
Data Extraction
structured_extraction.py
Next Steps
Invocations
Learn how to call your Functions
Schedules
Schedule Functions to run automatically
Management
Update and manage Functions
Functions Concept
Back to Functions overview