AI · Technical case

A customer-service AI agent in production,
on BigQuery and Claude.

A Dribba case with CityXerpa: a customer-service agent that takes tickets from chat, email and Freshdesk, identifies the customer against BigQuery and writes the reply citing its sources. The model never writes SQL, the agent replies to the customer directly, and fixed rules hand the delicate cases to a person: refunds, VIP customers or complaints.

It is in production, connected to CityXerpa's Freshdesk and BigQuery. Here is how it is built, what the code decides and what the model decides.

Respuesta directa

In production at CityXerpa (Andorra's SuperApp): a customer-service agent built as an 8-step TypeScript pipeline with Claude (Anthropic) over chat, email and Freshdesk. It identifies the customer against BigQuery using closed queries (the model never writes SQL), answers with cited sources from a hybrid RAG in pgvector, and a rule-based judge decides escalation. It replies to the customer directly; delicate cases and compensations go to a person.

8 steps

Fixed pipeline; only the drafting step uses tools

0 SQL

Written by the model: it fills parameters of closed queries

€100

Refunds above this always go to a person

4 languages

Catalan by default; Spanish, English or French to match the customer

The actual problem

A lot of what arrives as “we need AI in support” is questions about data that already sits in a data warehouse.

At CityXerpa, almost everything a customer asks is answered by their own data: where their order is, what they were charged, what happened with a delivery. That data lives in BigQuery, and the support knowledge (opening hours, delivery areas, billing, style guide) lives in documents. To answer well you need to know who is asking before looking at anything.

The usual trap is to build a generic RAG over the documentation and find out later that the answer was in that customer's order history, which no PDF contains. The opposite trap is letting the model write free-form SQL against the warehouse.

What we did: code identifies the customer and pins their ID; the model can only pick from predefined queries and fill in their parameters. Documentation goes through a hybrid RAG that cites its source. And before anything leaves, a judge with fixed rules decides whether the reply is sent or handed to a person.

Stack

Three layers, with control kept in code.

A Next.js console that orchestrates the steps, Claude to read and write, and BigQuery plus Postgres with pgvector as sources. Every step is logged and the console shows it live.

AI agent architecture: TypeScript pipeline, Claude, BigQuery and pgvectorFlow diagram: a ticket arrives via chat, email or Freshdesk at an eight-step pipeline built with Next.js and TypeScript. The pipeline calls Claude, which can only use parameterised tools; code runs the closed queries on BigQuery and the pgvector search, validates the output and applies the judge's rules before sending the reply.01Customerchat · email · Freshdesk02TSPipelineNext.js · TypeScript8 fixed stepsrule-based judge · trace03ClaudeHaiku · Sonnetparameterised toolsstructured output04aBigQuerycustomer · ordersclosed queries04bpgvectorknowledge basehybrid RAG · sourcesinputtool usevalidated JSONparamsembeddings
⚡

Orchestration

TypeScript pipeline (Next.js)

Console and pipeline in Next.js and TypeScript on Node, with Postgres and pgvector. Eight fixed steps: Intake, Identity, Profile, Router, Responder, Judge, Output and Memory. Each step writes its trace and the console streams it over SSE. If a step fails, the ticket is retried with growing back-off and, if it keeps failing, it goes to the human queue with the reason.

When to scale: A fixed-step workflow goes further than people expect. When volume calls for it, the next move is splitting channel intake and the pipeline into queue-backed workers, without touching the steps.

🧠

Reading, drafting and tool use

Claude (Anthropic)

Haiku on the fast steps (Intake, Router, Judge and support for Identity) and Sonnet on the Responder, the only step that calls tools. Steps that return JSON use structured output validated with Zod. Customer text always enters delimited as data, so it cannot smuggle in instructions.

When to scale: The model for each step can be changed from the console, with cost per ticket in view. Opus is kept for cases that genuinely need long reasoning.

🗄️

Data

BigQuery + pgvector

BigQuery to identify the customer and read their orders, order lines and incidents, always through fixed parameterised queries with a cap on billed bytes. Postgres with pgvector for the knowledge base: hybrid search (vector plus full text) whose answers cite the source document.

When to scale: A new question that no query covers gets a new query, reviewed and tested in code. The model still does not write SQL.

Real case

CityXerpa: AI customer service that answers on its own and hands the delicate cases to a person.

CityXerpa is Andorra's SuperApp, with more than 120,000 active users. The agent, in production, handles support questions about orders, deliveries, accounts and billing, connected to their Freshdesk and BigQuery. This page gives no outcome figures: they are the client's data.

Identity

Verified

The customer is identified against BigQuery and Freshdesk. Two identities are only merged on a strong identifier that matches exactly (email, phone, customer ID or order ID). Without one, the profile stays provisional and receives no personal data.

Reply

With sources

The Responder looks up the customer's orders through closed queries, searches the knowledge base and writes in Catalan or in the customer's language, citing the documents it used.

Escalation

Fixed rules

Low confidence, a refund over €100, a VIP customer with an incident, a legal complaint, a request to talk to a person… The judge applies these rules in code, and the model can only make the decision stricter, never softer.

How it works

Eight fixed steps. Only one of them calls tools.

  1. 01Intake and identity: Intake (Haiku) reads the message and extracts the useful data. Identity matches the customer against BigQuery and Freshdesk, combining code and Haiku. Profile gathers what is known about them and stores explicit facts separately from what the AI has inferred, as GDPR requires.
  2. 02Routing and reply: Router (Haiku) decides the type of question and the knowledge collection. Responder (Sonnet) is the only loop with tools: it looks up orders with parameters that code validates, with the verified customer's ID already pinned, and searches a hybrid RAG that returns its sources.
  3. 03Judge and output: Judge combines Haiku with deterministic rules. Output replies to the customer through the original channel (a public reply in Freshdesk, chat or email). Whatever the judge's rules flag goes to a person, and monetary compensation needs a supervisor's approval, with per-role limits.
  4. 04Memory and ratings: Memory keeps what is useful for the next conversation (area, preferred language, pending matters) with expiry, and any fact can be forgotten from the customer record. Customers rate every reply.

Next steps

What comes next.

What we would do next, in order. Each item says what changes and the effort we estimate.

01More questions answered without opening SQL to the model

More closed queries

Each frequent question that escalates today for lack of data becomes a new parameterised BigQuery query, reviewed and tested. The catalogue grows and the model still writes no queries.

Estimated effort: 1–3 days per query

02Lower cost on the fixed part of the prompt

Anthropic prompt caching

The style guide, rules and per-step instructions repeat on every call. With prompt caching, that part is billed at a fraction of the price within the cache window.

Estimated effort: 1–2 days

03Regressions caught before customers see them

Evaluation on every prompt or model change

The agent already has a scripted set of cases and compares against the team's real replies on anonymised tickets. The next step is running it with Claude on every change and blocking the deploy if results get worse.

Estimated effort: 1 week

04The reply starts showing sooner

Streaming to the chat with cancellation

In the chat, token streaming from Anthropic to the widget over Server-Sent Events. An AbortController carries a closed browser tab all the way to the model call and cuts it. If data has to be looked up first, clear microcopy (“Checking your order…”) instead of a silent spinner.

Estimated effort: 1 week

05Cost and latency per step, in your usual tooling

OpenTelemetry in Node

Each ticket's trace already lives in the database. Exporting it as OpenTelemetry spans (one per step, per Claude call and per BigQuery query, with tokens and bytes scanned) lets you see it in Cloud Trace, Datadog or Grafana next to your other systems.

Estimated effort: 1 week

06Peaks do not slow the console down

Queue-backed workers for peaks

Split channel intake from the pipeline: tickets go into a queue (Pub/Sub, or a Postgres table with SKIP LOCKED) and Node workers process them with bounded concurrency. The console stays responsive even when a flood of emails arrives.

Estimated effort: 1–2 weeks

Other use cases

The same pattern works beyond support.

If your company has data in BigQuery (or Snowflake, Redshift, ClickHouse) and a team that loses hours pulling answers by hand, this pattern applies.

📊

Ad-hoc analysis over the data warehouse

Non-technical staff ask in natural language and the agent answers from a catalogue of reviewed queries, with the result and the chart. Repetitive questions stop landing on the data team.

🛒

Dynamic-pricing assistant

Agents that combine business rules with competitor data and historical demand in BigQuery to suggest prices, with a person validating before anything is published.

🛡️

Fraud and anomaly detection

The agent cross-references warehouse signals, contextualises the suspicion and proposes opening or closing the case with a readable rationale. Cuts noise in risk teams.

📑

Executive report generation

Weekly or monthly summaries combining structured data (KPIs in BigQuery) with LLM-generated narrative. Each figure is backed by the query that produced it.

🤝

Onboarding and internal support

Agent over the HR and operations knowledge base. Employee onboarding, questions about leave, expenses or internal policy without flooding the helpdesk.

🔁

Reconciliation and audit

The agent compares records across systems, identifies discrepancies and proposes resolutions. For finance, ops and compliance.

Technical FAQ

The questions every CTO asks us in week one.

Partly. The knowledge base (opening hours, delivery areas, billing, style guide) goes through a hybrid RAG in pgvector that combines vector and full-text search and cites its source. Customer data comes from BigQuery through tools with predefined queries. Two different sources for two different kinds of question.

Because “where is my order?” is answered by a row in a table, and searching for a similar paragraph does nothing for it. Vectorising BigQuery would add complexity with no benefit. Where there is real text (the support documentation), pgvector in the console's own Postgres avoids running yet another database.

Because of how it uses tools: it fills in the parameters it is asked for and rarely invents one that does not exist, which is exactly what a closed-query design needs. Haiku covers the fast steps at low cost and Sonnet the drafting step. The model for each step can be changed from the console, so trying another provider on one step does not mean rebuilding anything.

Because in customer service, being able to explain every decision matters more than flexibility. With fixed steps, every ticket leaves a readable trace: what the model understood, who it identified, what it looked up, which rules fired and why it was or was not escalated. Only the reply step iterates with tools, and it does so within a closed set.

Yes, except for the delicate cases. The agent posts the reply directly on the customer's channel, and whatever the judge's rules flag (low confidence, refunds over €100, VIP customers with an incident, legal complaints) goes to a person. Monetary compensation always needs a supervisor's approval. The model can make the judge's decision stricter, never softer. No design guarantees a model is never wrong, but this one narrows where it can be: customer data comes from fixed queries, documentation is cited and, if no source clears the confidence bar, a rule escalates the ticket.

With the right model on each step (Haiku to classify and judge, Sonnet only to write the reply), with a judge that only asks the model when the rules have not already decided, and with BigQuery queries capped on billed bytes. The console shows cost per step and per ticket, and Anthropic prompt caching is one of the next steps.

Yes, with caveats. The pipeline and its Postgres deploy on the customer's infrastructure (Cloud Run or GKE with VPC Service Controls, or their own servers), and BigQuery supports VPC Service Controls too. For Claude, Anthropic offers the model via AWS Bedrock or Google Vertex AI, both with private connectivity, so data never leaves your cloud. Under full restriction (banking, defence) a self-hosted LLM can be used instead, accepting that quality drops a notch.

For a focused agent over a bounded domain (one ticket type, one set of BigQuery tables), 4 to 8 weeks with two senior engineers. The bottleneck is never the code — it is scoping correctly, getting access to the data, and building the eval dataset with real queries. ROI is unclear in month one; from month two onwards it is usually obvious.

A well-scoped agent with BigQuery + Claude + a TypeScript pipeline and a bounded domain starts at €35,000–50,000 in development. With an added vector layer, legacy-system integrations or a mature eval pipeline, it climbs to €60,000–90,000. Monthly support and evolution from €3,500/month depending on volume and SLA.

Got data in BigQuery and a similar case?

30 minutes with a partner.
No pitch, no script.

Tell us the case, show us the schema and we will tell you whether an agent makes sense, what stack fits and what it costs at your real volume. If it does not fit, you will know on the same call.

100% senior in-house team in Barcelona and Andorra · Reply within 1 h

Más sobre IA aplicada