Skip to main content
Botpress Studio runs your bot in Botpress Cloud and lets you run code at fixed points of every turn with Hooks. Two hooks send each turn to the Agnost AI capture API: one collects the bot’s replies, and one sends the user’s message, the replies, the latency, and the turn’s AI spend when the turn ends. Your Workflows do not change. Setup takes about five minutes.

Manual setup: Botpress Studio hooks

1. Store your organization ID

Sign in to app.agnost.ai, open Settings, and copy the Organization ID. It is a UUID. In Botpress Studio, open Bot Settings, scroll to Configuration Variables, select +, and add a variable named AGNOST_ORG_ID with your organization ID as the value.

2. Collect the bot’s replies

Open Hooks, select Create Hook, choose Before Outgoing, and name it agnost-collect-replies. Paste:
This hook runs before each bot message is sent and keeps the message’s plain-text preview in session state.

3. Send each turn to Agnost AI

Create another hook, choose After Turn End, and name it agnost-send-turn. Paste:
After Turn End runs once the bot has received the user’s message, processed it, and replied. axios and env are available in every Studio hook, so no package install is needed. A failed request is logged and never interrupts the conversation. Change botpress-bot to the name you want to see for this bot in Agnost AI. Publish the bot to apply the hooks.

Data mapping

  • event.conversationId becomes the Agnost AI conversation ID. Repeating capture-session on each turn is safe; Agnost AI keeps one conversation.
  • event.userId becomes the user ID.
  • event.preview, the plain text of the user’s message, is the event input.
  • The previews of all bot messages in the turn, joined with newlines, are the output. Buttons and cards appear as their text preview.
  • Latency runs from the user’s message to the end of the turn.
  • Botpress reports the turn’s AI spend in nanodollars. The hook converts it to USD as cost_usd, which Agnost AI counts toward the conversation cost, and keeps billed_tokens as metadata.

Why there is no SDK or OpenTelemetry section

Studio code cannot import external packages, so the Agnost AI SDK cannot run inside a hook. The hooks call the Capture Session and Capture Event API directly instead. Botpress Studio bots run in Botpress Cloud, and Studio has no setting to export OpenTelemetry traces to another backend.

Verify

  1. Open the Studio emulator or your published webchat and send two messages in one conversation.
  2. Open Conversations in app.agnost.ai. The two messages appear as two events in one conversation.
  3. Open an event and confirm the input is your message, the output is the bot’s full reply, and the metadata includes cost_usd.

Troubleshooting

  • Nothing appears in Agnost AI: open the bot’s logs in Studio and look for Agnost AI capture failed. A 400 means AGNOST_ORG_ID is missing or not a UUID.
  • Requests succeed but no data appears: the organization ID is checked after the request is accepted, so a wrong but valid UUID returns 202. Copy it again from Settings in Agnost AI.
  • Outputs are empty: confirm the agnost-collect-replies hook is a Before Outgoing hook and that both hooks are published.
  • The output includes the previous turn’s replies: the After Turn End hook failed before it cleared the session state. Check the bot’s logs for errors in that hook.

References

Next steps

  • Conversations: review complete Botpress conversations.
  • Events: inspect each user message and the bot’s reply.
  • Patterns: organize production conversations by what users wanted.