functions tool is the core orchestrator of MyAi. It allows you to deploy custom Python code (3.10+ environment) that serves as the “brain” of your system — orchestrating other tools, transforming data, and implementing complex business logic.
Why Use Custom Functions?
- Custom Logic — implement any business rule, calculation, or data transformation not natively covered by existing tools.
- Tool Orchestration — call multiple tools (
api_client,sql_client,email,canvas_editor,file_processor) in a specific sequence. - Reusable Components — publish functions as callable artifacts, acting like internal APIs for other Workflows, Dimensions, or Functions.
Functions run in a sandboxed environment. They only have access to the
default_api tools and the data explicitly passed to them.The Function Lifecycle
Run (Test)
Use
functions(operation="run") to execute code privately and temporarily. Returns an execution_ref for testing with other tools. Always test thoroughly before publishing.Publish (Deploy)
Use
functions(operation="publish") to create a permanent, versioned artifact with a defined API contract. Once published, the function is discoverable and callable by Workflows, Dimensions, and other Functions.Patch (Update)
Use
functions(operation="patch") for targeted line-level updates to live functions, minimizing deployment risk.Parameters vs. Inputs
Understanding the distinction is important:| Concept | When | Purpose |
|---|---|---|
| Parameters | Defined at publish time | The API contract — names, types, descriptions of expected arguments. Visible to other tools and Workflows. |
| Inputs | Provided at run time | The actual runtime values for testing (e.g., inputs={"customer_id": "CUST-001"}). Not part of the permanent definition. |
Example: Multi-Tool Orchestration
This function fetches customer data from a CRM, queries an internal database, and generates a Canvas report:Best Practices
Security First
Security First
Always use
integration_credentials for authenticating with external services. Never hardcode sensitive information directly in function code.Orchestrate, Don't Re-implement
Orchestrate, Don't Re-implement
Whenever an existing
default_api tool can perform a task, use it rather than writing custom Python to replicate the functionality (e.g., use default_api.email() instead of a custom email library).Keep Functions Modular
Keep Functions Modular
Each function should do one thing well. Smaller functions are easier to test, debug, and reuse across Workflows.
Handle Errors Gracefully
Handle Errors Gracefully
Implement
try-except blocks for external API and database calls. Return meaningful error messages that help with debugging.Learn More
Data & Integration Tools
The tools your functions will call most: api_client, sql_client, file_processor.
Architecture
How Functions relate to Skills, Dimensions, and Artifacts.