A collections agent needed to answer quickly without losing control. I improved its speed, safety and operating signals so people could understand what happened.
01 · The need
People needed timely replies by message or voice, while the team needed to understand failures.
02 · What I changed
I traced the slow path, removed a repeated AI call, strengthened early safety checks, grounded answers in retrieved knowledge and narrow live-data tools, and made outcomes easier to diagnose.
03 · Result or scope
One recorded baseline was about 37 seconds; one later production request on the same path took 11.47 seconds after several changes. This is not a median or an isolated-cause result.
The system handled debt negotiation conversations across WhatsApp, SMS and voice. It
combined a Python message service, Vertex AI Gemini, Twilio, Postgres, Firestore,
object storage and a React operations surface. My work sat at the boundary
between LLM behavior, backend reliability and operator visibility.
This was not a demo agent. The product had real users, real campaigns and real
production failure modes: slow message responses, ambiguous failure statuses,
provider-specific messaging semantics and loops where the AI kept responding to
an automated counterpart.
The useful work was rarely "make the model smarter" in isolation. The system
needed better boundaries around the model: guards before expensive calls,
deterministic code where possible, structured logging on hot paths and metrics
that made regressions visible.
One recorded baseline on a synchronous message path took roughly 37 seconds.
A later production request on that same path took 11.47 seconds after a
combination of changes. These two observations are not a median, an SLO, or
evidence that any individual change caused the difference.
At the same time, the agent could enter loops with automated menus, and operator
dashboards collapsed different failure causes into one generic status. That made
it hard to tell the difference between invalid contact data, a provider template issue, an
identity-flow problem or a real debtor refusal.
Case map · problem → solution → return
↔
The observed request followed several changes around the model; it is not evidence of a single cause.
I traced the message-processing path and separated setup, model work, status
analysis, persistence and logging so the team could investigate the delay.
The work combined structured logging, removal of repeated analysis, a model
migration and thinking-level tuning. The available record has one later request
after that combination, so the result cannot be attributed to any one change.
Synchronous message path — before / after
One later request followed multiple changes. It is a limited observation, not a speedup claim.
I investigated a production loop where the agent kept replying to an automated
menu bot. The important design choice was to detect the
pattern before expensive model setup. Known automated-counterpart loops should
stop before spending more Gemini calls or producing more outbound messages.
I helped plan a single-model Gemini migration with dynamic thinking levels instead
of a brittle tree of model fallbacks. Simple calls could stay cheap, while
complex conversations could request more reasoning through a single resolver.
The key was to make the routing explicit: debt size, conversation length, legal
language and repeated counterproposals became inputs to a central decision point,
not scattered conditionals across the codebase.
I worked on the retrieval and tool layer that kept answers tied to facts. Domain
documents were cleaned, split into chunks, embedded and stored in Postgres with
pgvector. At run time the question was embedded, similar passages were found,
a top-k selection was filtered and only that context reached the model. I tuned
chunk size and top-k as a quality-versus-noise trade-off against real
conversations. Postgres plus pgvector kept relational data and vectors in one
operational stack.
Knowledge and live data are different problems, so the agent also had narrow
tools for current customer and debt information. The backend validated
parameters and stayed responsible for authorization and business rules; the
model chose a capability but never had open access to the database.
Because this was a financial domain, model output was not trusted by default.
Around the model I worked on instructions, tool scope, output validation,
business-rule checks before sending, fallback and human handoff. Handoff was a
designed path, used when context was missing, validation failed or the case
should not be automated.
Conversation memory lived in the application: state and relevant history were
persisted and a limited context was rebuilt for each turn, instead of sending the
whole history to the model. I also compared quality, latency and cost to move
suitable workloads from one Gemini tier to a lighter one, and combined that with
context caching and a smaller context. No percentage saving is claimed here.
For observability I looked beyond HTTP status: model latency, context and token
use, failures, response quality and agent behavior, because a successful
response can still be a bad answer. Behind the agent, I took part in a
multi-tenant backend restructuring around clearer domain boundaries and a
migration from a document store to PostgreSQL. Mechanism and rollout details are
not published.
I also worked through provider and operations issues around outbound messaging,
campaign dispatch and failure reporting. In one diagnosis, a generic "failed
negotiation" group was hiding several unrelated causes. Breaking the status down
into observable reasons made the next fix much more obvious.
The conversation itself moved through an explicit journey. Modeling it as a small
state machine — instead of a bag of booleans — made every closure auditable and
every hand-off intentional.
Subject journey (state machine)
Status names abstracted — this is the shape of the journey, not the production schema. The opt-out guard exits from any state.
One recorded baseline on a synchronous message path was about 37 seconds; one
later production request on the same path took 11.47 seconds after multiple
changes. This is not a median or an isolated-cause result.
Removed repeated analysis from the examined path.
Designed a pre-LLM automated-counterpart guard for repeated bot/menu loops.
Planned model migration around a single model plus dynamic thinking-level
routing.
Turned generic failure groups into concrete operational hypotheses.
Built a Postgres/pgvector retrieval path and narrow live-data tools, with
layered output checks, fallback and human handoff around the model.
Rebuilt per-turn context from application state and moved suitable workloads
to a lighter model tier with context caching. No cost or latency percentage is
claimed.
Production AI failures rarely sit inside the model alone. They show up in queues,
provider APIs, locks, logs, prompts, dashboards and the human process around them.
The strongest AI engineering work was not adding another layer of prompting. It
was making the system easier to reason about: measure the path, remove duplicate
model calls, make safety gates deterministic and separate shipped wins from
projected roadmap ideas.
The natural next layer would be an eval harness, prompt versioning, token and cost
dashboards, and a tactical-notes loop that lets the agent reuse what worked or
failed in earlier sessions. I would only add retrieval once observability showed
that missing knowledge, not weak orchestration, was the bottleneck.