Calling Elements in Service Functions
Within service elements, each service function can call other backend elements to compose complex business processing workflows. JitAi supports both visual element invocation and direct code-based calling within service functions.
Using platform APIs to call other elements
The JitAi application runtime platform provides system-level APIs for use within function logic, including the app.getElement function for element invocation. The app.getElement function returns an element instance object, exposing all declared functions for calling.
element = app.getElement("element fullName")
result = element.func1(params)
The app object is a runtime object provided by the JitAi platform that references the current application. For details, see the App reference documentation.
Typical examples
Calling data model functions
Invoke data model built-in functions or custom data model functions to perform CRUD operations.
# Call data model function
dataModel = app.getElement("models.UserModel")
user = dataModel.getUser(userId=123)
Calling other service functions
Inter-service function calls represent one of the most common patterns, enabling modular business logic design.
# Call user service
userService = app.getElement("services.UserService")
user_info = userService.getUserProfile(userId=123)
Calling external APIs
Invoke functions of external API element instances to retrieve results from corresponding third-party services.
# Call payment API
paymentAPI = app.getElement("externalAPIs.PaymentAPI")
payment_result = paymentAPI.createPayment(
amount=100.0,
currency="CNY",
orderId="ORDER_123"
)
Calling AI large language models
Invoke the runLlm method of AI large language model elements to obtain model-generated results.
# Get AI large language model instance
llm = app.getElement("llms.MyLLM")
# Basic text generation
response = llm.runLlm({
"dataType": "Ltext",
"promptList": [
{"role": "user", "prompt": "Hello, please introduce yourself", "id": "user-1"}
],
"llmConfig": {"model": "qwen-plus"}
}, locals())
Calling AI agents
Invoke the run function of AI Agent elements to leverage AI Agent capabilities within your business logic.
# Get AI Agent instance
agent = app.getElement("aiagents.DataAnalysisAgent")
# Basic invocation
result = agent.run(
user_input="Analyze user behavior trends",
variables={
'data_source': 'models.UserBehaviorModel',
'time_range': 'last_30_days'
}
)