Execute (Text-only) Action
When the agent invokes an execute-only action, it awaits your execute(params) function, takes whatever you return, and feeds it into its next chat message.
Property | Type | Default | Required | Description |
---|---|---|---|---|
execute | (params: any) => Promise<any> | N/A | Yes | Handler for your async task; must return a Promise with data. |
render | <see Render Options below> | N/A | No | Optional UI: either a built-in component key or a custom render function to inject interactive UI. |
awaitUserInput | boolean | false | No | When true , the agent will pause and wait for user interaction before continuing. |
timeout | number | 5000 | No | Milliseconds to abort the execute call (default 5000 ). |
eucera("when", "ready", () => {
eucera.agent({ /* …common setup… */ })
.addActionHandlers({
create_task: {
execute: async (params) => {
const {title, body} = params;
const response = await fetch('https://jsonplaceholder.typicode.com/posts', {
method: 'POST',
body: JSON.stringify({
title,
body,
userId: 'playground',
}),
headers: {
'Content-type': 'application/json; charset=UTF-8',
},
});
const data = await response.json()
// Return all relevant fields so the agent can reference them later
return {
id: data.id,
title: data.title,
body: data.body,
userId: data.userId,
// Include a link property—if the user asks "What's the link?", the agent can supply this
link: `https://jsonplaceholder.typicode.com/posts/${data.id}`
};
}
}
});
});
Updated 15 days ago