Test and debug agent functions
Test an agent function with the Run button while you build it, and add console logs to see what it did, both in the editor and in live conversations.
Test with Run
Click Run in the function editor, enter a value for each input, and run it. The panel shows:
- Result: what the function returned, or the error that stopped it
- Console: the lines the function logged
- Variable updates: the global variables the function would change
A test run is real for everything except variables. Table changes and API calls happen exactly as they would in a conversation, so test against data you don't mind changing. Variable updates are only listed, never saved.
During a test run there's no conversation, so context.invokedBy is "dev-run" and sessionId, messageId and userMessage are empty.
Log with console
Each log line takes a short label and, optionally, one value. The label is the line's name; the value sits behind it.
console.log("Orders found", orders.length);
console.info("Customer details", { email, tier });
console.warn("Phone number missing");
console.error("Payment API failed", error);
console.debug and console.trace work too.
- Errors show their message.
console.error("Payment API failed", error)recordsError: <message>, including the status and body of a failed API call. - Objects are converted to text, and the value is shortened after 300 characters.
- One value per line. To log several values, group them into one object:
console.log("Found", { count, email }). A line with more than two arguments, or with a label that isn't text, isn't logged; aconsole-misusewarning appears in its place. - Labels can be up to 100 characters, and a run keeps up to 30 lines.
Logs in live conversations
When an agent calls a function, or a flow reaches a Function node, open the conversation in Analysis to see what the function did. Its rows appear under the step that ran it: Tool: <function name> for an agent, or the Function node in a flow.
- Each
consoleline, at the moment it was logged. - One row per database call, for example Database SEARCH: 1 record(s) found or Database INSERT: record inserted, with the table, the number of records and how long it took.
- One row per API call, for example Executed API getOrderStatus. Returned HTTP 200 or Failed with HTTP 401, with the status code and how long it took.
On staging and sandbox agents you can open each row to see the details: the query and response for a database call, the response for an API call, and the value you logged. Production agents show the rows and their numbers but hide the details. Header and parameter values that look like credentials, such as Authorization or cookie, are always masked.
Test runs from the Run button don't write to Analysis.