Skip to main content
Glama

Customer Intelligence & Segmentation

Customer Tiering — Get Scoring Script (large books)

customer_tiering_get_engine
Read-only

For books LARGER than 500 transaction rows. Returns a complete, runnable Python script that scores the book into A/B/C/D tiers with survival modelling (BG/NBD), spend modelling (Gamma-Gamma), tier migration, a money layer and plain-language decision cards. Run it in your code sandbox against the user's transaction file. The rows never pass through you as tokens, so a 10,000-row book costs the same to run as a 600-row one. Needs numpy. Prints ranked decisions and headline figures; writes the full per-customer ledger to customer_tiering_result.json beside the input file. No customer data reaches this server on this path. SAVE AND RUN THE RETURNED SCRIPT VERBATIM — every block of it is required for the computation. Do not retype it from memory, shorten it, reformat it, split it up, or reimplement the maths with pandas/sklearn; only the PATH / AS_OF / CURRENCY / OUT / OVERRIDES / CONTACTS lines at the bottom may be edited. The script cleans customer identities itself before scoring — merging capitalisation and spelling variants by rule, printing what it merged, and listing the similar-but-unproven groups for you to rule on via OVERRIDES — so do not pre-clean the file or edit those rules. Optionally takes contacts_path, a log of rep calls or visits (customer_id + date only). It is not required and the book scores fine without it, but it is valuable: with it the money layer MEASURES what a contact is worth per tier from touched-vs-untouched tier transitions instead of assuming a flat rate, so ask for it whenever the user mentions a CRM, a call log or a visit register.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
as_ofNoAnalysis date YYYY-MM-DD. Defaults to latest in file.
currencyNoISO currency code for display (INR, USD, EUR...).USD
file_pathYesPath to the transaction file (CSV/TSV/JSON) inside your sandbox. The file needs one row per PURCHASE with three things: a customer identifier, a date, and an amount > 0. Column names are matched flexibly (customer_id / AccountId / Party Name; date / invoice_date / Invoice Date; amount / revenue / Invoice Amount), so most CRM and Excel exports work unchanged, including a separate name column used to label accounts when the id is a code. A pre-aggregated per-customer summary will NOT work — the models need purchase timing. The script cleans name variants itself ('Acme Pvt Ltd' and 'ACME PVT LTD' become one account), so pass the file as it is.
contacts_pathNoOptional path to a rep-contact log (CSV/TSV/JSON) inside your sandbox: one row per call, visit or WhatsApp touch, needing only a customer identifier and a date — no amount. Column names are matched as leniently as the transaction file, and the ids go through the same identity cleaning, so a log spelling 'ACME PVT LTD.' still joins 'Acme Pvt Ltd'. Strictly optional; without it the book scores exactly as it would anyway. With it, what a contact is worth stops being an assumed flat rate and is MEASURED per tier by comparing tier transitions that followed a contact against those that did not (any tier with at least 10 touched transitions; thinner tiers keep the assumption). Worth asking for whenever the user mentions a CRM, a call log or a visit register.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
notesNo
scriptYesThe runnable scoring script.
currencyNo
languageNo
requiresNo
writes_fileNo
instructionsYes
code_integrityYesRules for running the script: it must be saved and executed verbatim, which lines may be edited, why every block matters, and how to verify the copy is intact.
engine_versionYes
file_path_usedNo
scipy_requiredNo
data_requirementsNoWhat the input file must contain: required fields and their accepted aliases, formats handled, minimum data volumes, and what will not work.
identity_cleaningYesHow the script cleans customer identities before scoring: which variants it merges by rule, which similar-but-unproven groups it leaves for the caller to judge and how to feed that decision back via OVERRIDES, how accounts get their display names, and what it writes out.
contacts_path_usedNo
network_access_requiredNo

TDQS

A4.9/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already mark the tool readOnly and non-destructive, but the description adds substantial behavioral context: rows never pass through as tokens, no customer data reaches the server, the script writes a result JSON, requires numpy, cleans identities itself, and prints merged variants for review. This is far beyond what annotations provide.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is long but every sentence carries operational weight. It front-loads the threshold, the deliverable, and the key warning, then systematically covers constraints, optional inputs, and output behavior. The repeated emphasis on running the script verbatim is justified given the likely failure mode.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool that returns a script, the description covers prerequisites, execution environment, required input format, input-size rationale, optional input value, output behavior, and anti-patterns. The presence of an output schema means return values do not need to be inventoried again. Nothing essential is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline is 3. The description adds meaning beyond the schema for file_path (do not pre-clean, purchase timing required) and especially contacts_path (explains why it is valuable and when to ask for it). as_of and currency are only covered by the schema, so the description does not fully elevate to 5.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description names a specific resource ('complete, runnable Python script'), a precise action ('scores the book into A/B/C/D tiers'), and a clear scope condition ('books LARGER than 500 transaction rows'). It also enumerates the methods, making the tool's purpose impossible to confuse with a generic scoring tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives explicit when-to-use guidance: books larger than 500 transaction rows. It also warns against pre-cleaning the file, instructs the agent to run the returned script verbatim, and specifies when to ask for contacts_path ('whenever the user mentions a CRM, a call log or a visit register'). This is strong, actionable routing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Try in Browser

Glama MCP Gateway

Add one secure layer between your agents and this server.

TDQS

A4.5/5.0
Disambiguation4/5

Both tools perform the same A/B/C/D tiering workflow, but the explicit 500-row threshold and direct-vs-script delivery make them distinguishable. An agent could still misselect if it ignores the size boundary, so it is not a perfect 5.

Naming Consistency3/5

Both names share the customer_tiering prefix and use snake_case, but one is a bare action while the other appends get_engine, describing delivery mechanism rather than a distinct domain operation. The pattern is readable but not fully consistent.

Tool Count3/5

Two tools is borderline for a server whose purpose sounds broader than its actual scope. The two-path design is justified, though, since direct row submission would be impractical for large books.

Completeness4/5

The pair covers the core tiering workflow: direct scoring, large-scale script generation, identity cleaning, optional contact uplift, and result outputs. Missing pieces like override management are handled through parameters rather than separate tools, so agents are not left at a dead end.

Resources