English
callAgent
About 485 wordsAbout 2 min
2026-10-15
This method is used to invoke an Agent and poll for the execution result at a fixed interval after the task is submitted. Pass business parameters through data and optional settings through options. The method returns a Promise.
Syntax: FxUI.biz.callAgent(data, options)
Parameters
| Parameter | Description | Type | Allowed Values | Default |
|---|---|---|---|---|
| data | Business parameters (required) | Object | — | — |
| options | Additional options | Object | — | {} |
data
| Parameter | Description | Type | Allowed Values | Default |
|---|---|---|---|---|
| apiName | API name of the Agent | string | — | ShareAgent |
| content | Message content, see the example for the item structure | Array | — | [] |
| sessionId | Session ID | string | — | {apiName}__{random UUID} |
| instanceId | Instance ID | string | — | Same as sessionId |
options
| Parameter | Description | Type | Allowed Values | Default |
|---|---|---|---|---|
| signal | AbortSignal used to abort the call | AbortSignal | — | — |
When signal is passed, the method checks whether the call has been aborted before the request is sent and after the execution result is submitted.
Example
Get the execution result with the polling mode:
FxUI.biz.callAgent({
apiName: 'ShareAgent',
content: [
{
type: 'text',
text: 'Query the weather in Beijing today'
},
{
type: 'file',
source: {
path: 'TN_de531073e66c4217b4f17146f0b34f60',
filename: '(This is the class)MRCRMSyncUtil.groovy',
size: 14476,
ext: 'groovy'
}
},
{
type: 'image',
source: {
path: 'TN_7d6da51cb3c8485887631ca618e1e2a9',
filename: '2.Shortcut recommendation configuration.png',
size: 120619,
ext: 'png'
}
}
]
}).then((res) => {
console.log(res);
}).catch((err) => {
console.log(err);
});Abort the call:
const controller = new AbortController();
FxUI.biz.callAgent({
apiName: 'ShareAgent',
content: []
}, {
signal: controller.signal
}).catch((err) => {
console.log(err);
});
// Call this when you need to abort
controller.abort();Return Value
The method submits the execution first and then polls the execution result every 2 seconds until the task is no longer in the running state. The resolved result structure is as follows:
| Field | Description | Type |
|---|---|---|
| code | Execution status. When it is POLLING, polling continues; any other status value means the task has finished | string |
| data | Execution result data | — |
{
code: 'POLLING',
data: {}
}On failure, the Promise rejects with the failed call result:
{
success: false,
error: {}
}If the execution result is submitted successfully but the returned success is not truthy, the Promise rejects with the raw result of the execution submission.
When the call is aborted through signal, the Promise rejects with the error aborted.
Notes
- The polling interval of this method is fixed at 2 seconds, and polling stops when the execution status is no longer
POLLING. - Fields already present in
dataoverride the defaults in the table above. IfsessionIdandinstanceIdare not passed, a new session ID and instance ID are generated asapiName__random UUIDon every call. sessionIdis generated from theapiNameyou pass. IfapiNameis not passed, the prefix isShareAgent.- The abort check happens before and after the execution is submitted; during polling,
options.signalis passed along with the internal calls. - This method is implemented with the
ai-asset agent executeandai-asset agent find-execute-resultoperations in the Operation Center. You can look up the related operations in the Operation Library.
