Skip to main content

Chat that answers from your functions

Every published app has an Ask AI chat, drawn by Studio's host page, that can read what is on the app's screen. This example lets that chat also call the app's own functions, so "what was the failed % on 20 September?" is answered by running order_kpis for that day, with a run and a trace, instead of by a model's guess.

Nothing is coded for this. It is three switches, two of which only a person may flip, plus a test.

What you will have at the end​

In Test KPI app's Ask AI drawer:

You: what was the failed % on 2026-09-20?

Ask AI: On 20 September 2026 there were 1,284 orders and 3.4 % failed (44 orders). (from order_kpis)

The answer is the function's number; the Runs page shows a run of order_kpis started from chat, with the app's id and the same trace as a button press. Check the figure against the app's own tiles for that day and against your dashboard.

What the agent will ask you before it builds​

  1. Which questions should chat be able to answer this way? Only ones a function you have can answer. Here: one day's orders and failed % (order_kpis). The agent should list the app's imports and say which of them chat could use.
  2. Who may switch this on? The "Functions in chat" setting belongs to the app's owner or a workspace admin. If that is not you, the agent needs you to find the right person.
  3. What chat may not do. The agent should say this unprompted: chat calls run as the viewer, so a viewer can only get what they may see anyway; the call goes through the same function with the same limits; chat cannot start a workflow's sends or approve anything; and the answer text is the model's words around the function's number, so the number is what to trust.
  4. The sample. Before switching anything on, the agent runs order_kpis for the day you will ask about and tells you the expected answer: "For 2026-09-20 the function returns 1,284 orders and 3.4 %. When chat says something else, we will know it did not call the function."

The pieces it creates​

PieceNameWhat it is
Nothing newUses Test KPI app and order_kpis from example 1
A switch on the functionorder_kpis: "Chat and agents" onPerson-only; the same switch example 2 needed
A switch on the app"Functions in chat": InheritOwner or admin, in the app's settings

The rule, in one paragraph​

The app's chat may call the app's imported functions and workflows (the ones in bda.manifest.json functions, in the published version) that are exposed to agents (expose.agents on the function), when the app's setting Functions in chat is Inherit (the default) rather than Off. Each one appears to chat as a tool named fn_<local name>, so order_kpis is fn_order_kpis. The app itself never builds a chat: the host page draws it, and the app only reports what is on screen (its cards' titles and query ids) so chat can see them.

Steps, in order​

1. Check the import is published (agent)​

dataapp_describe (or the app's page in Studio) shows the app's imports. order_kpis must be in the published version, not only in a draft. If the app is at a version without it, the agent makes and publishes a version that imports it (a person confirms that version, as in example 1).

2. Expose order_kpis to agents: Only a person​

Chat is an agent, for this purpose. If you did example 2, this is already on. If not:

Only a person: in Studio, open Functions, open order_kpis, and switch on "Chat and agents". Studio may make this a new version to confirm; if it does, the app's import should be re-pinned to it in a new app version (person-confirmed).

The agent cannot do this (person_required), and it should not try.

3. Set "Functions in chat" to Inherit: owner or admin​

Only a person (the app's owner or a workspace admin): in Studio, open Apps, open Test KPI app, open its settings, and check that Functions in chat is Inherit. It is the default, so usually there is nothing to change; Off is the switch for apps whose chat should never call functions. There is no agent tool for this setting yet (landing); the agent tells you where it is rather than guessing a tool.

4. Test through the agent (agent)​

The agent asks the app's chat the way a viewer would:

dataapp_ask(app_id, "what was the failed % on 2026-09-20?")

and compares the answer with the sample from question 4. It then checks the Runs page (or describes the run): a run of order_kpis, started from chat, with the app's id, status Done.

5. Prove the Off switch (person, then agent)​

To be sure the answer came from the function and not from a lucky guess:

Only a person: set Functions in chat to Off on the app. The agent asks the same question again. Now chat has no fn_order_kpis tool: it either says it cannot compute that or answers from what is on screen, and no new run of order_kpis appears. Then set it back to Inherit and ask once more: the run appears again.

How to test it​

  1. Open the app, open the Ask AI drawer, and type: what was the failed % on 2026-09-20? Use a date inside the model's data window (the agent told you the window in example 1).
  2. The answer should carry the function's number (3.4 % in the illustration) and say where it came from. Compare with the tile in the app for that day, and with your dashboard.
  3. Open Runs. There is a new run of order_kpis, started from chat, on this app, Done, with input {"day": "2026-09-20"} and the output in its trace. A code function answers in seconds; chat waits for it.
  4. Ask something the function cannot answer ("what was the failed % by region?"). Chat should say it cannot compute that with the tools it has, or answer from the screen; it should not invent a per-region number. If it does invent one, that is a model guess: tell the agent, and consider a function or a declared query that answers it properly.
  5. With the setting Off (step 5 above), the same question makes no run.

How to switch it off​

  • For this app: owner or admin sets Functions in chat to Off in the app's settings. Chat keeps working; it just has no function tools.
  • For the function everywhere: switch off "Chat and agents" on order_kpis in Studio. Then no chat and no agent may call it; apps and workflows still can. Remember example 2's triage agent needs it on.
  • Chat altogether: the app's manifest chat.enabled: false in a new version turns the drawer off for that app.

Ending the series: what you built, and how to disable each piece​

If you did all six examples, the agent should give you a list like this at the end; if it does not, ask for one.

PieceWhereOff switch
Test KPI app (versions 1 to 4)AppsUnpublish
Test Digest appAppsUnshare, then unpublish
order_kpis, triage_failed_order, ml_train, ml_predictFunctionsDisable on each function's page (owners and admins); pinned callers stop, nothing is deleted
Weekly failed orders digestWorkflowsPause the weekly trigger; then Disable on the workflow's page
Train weekly, predict dailyWorkflowsPause weekly_train and daily_predict; then Disable
The declared analysisin the app's manifestRemove in a new version, or unpublish the app
"Chat and agents" on order_kpisthe function's pageSwitch off when nothing needs it

Every run any of them made stays on the Runs page, so you can always see what happened and what it cost.

What you learned​

  • Chat calls imported functions exposed to agents when "Functions in chat" is Inherit; the app builds no chat.
  • Two switches are a person's: "Chat and agents" on the function, and the app's chat setting.
  • A chat call is a run like any other, on the Runs page, started from chat, on the app.
  • The number is the function's; the words around it are the model's.

Read more: using functions in apps, a function's life from draft to disabled, publishing and sharing an app, Runs and traces.

Copy for your agent
Let people ask my "Test KPI app"'s chat on preview things like "what was the failed % on
2026-09-20?" and have it answer from my order_kpis function, not by guessing.

How to work with me:
- Explain the rule first: the app's chat may call the app's imported functions that are exposed
to agents when the app's "Functions in chat" setting is Inherit. Do not build a chat UI in the app.
- Check the published version of the app imports order_kpis; if not, make a version that does and
give me the link to confirm it.
- Check order_kpis has "Chat and agents" (expose.agents) on. If not, tell me where in Studio to
switch it on and wait; you cannot do it.
- Tell me where the "Functions in chat" setting is in the app's settings (owner or admin) rather
than guessing a tool for it.
- Run order_kpis for 2026-09-20 first and tell me the expected answer. Then ask the app's chat
with dataapp_ask and compare. Show me the run on the Runs page (started from chat, on this app).
- Then ask me to set the setting to Off, ask again, confirm no run was made, and ask me to set it
back to Inherit.
- At the end, list everything we created across the examples (apps, functions, workflows, which
schedules are paused) and how to disable each one in Studio.
- Only create things titled "Test ...". Never change an existing app.