Organization: Demandfarm (Key Account Management software for B2B)
Role: Architect & builder
Period: 2024
Stack: Python, Portkey AI Gateway, SEC API, Yahoo Finance API, Google Search, AWS Cloud, PostgreSQL, REST API, ThreadPoolExecutor
Demandfarm sells Key Account Management software to enterprise B2B teams. Their users are key account managers and sales leaders managing strategic existing accounts, not SDRs prospecting cold lists.
Before any strategic account meeting, a KAM needs to know what the account is doing financially: latest earnings, year-over-year trends, recent leadership changes, competitive moves, strategic priorities from the CEO's commentary. The information exists publicly (SEC filings, earnings call transcripts, annual reports, financial news), but reading and synthesizing it for one account takes hours. At enterprise volume, the math does not work.
Demandfarm wanted an agent built into their platform that would automate this research and produce a digestible report for each account.
A REST-API account intelligence agent with two specialized data collectors and an LLM synthesis layer.
For listed companies. Input: a ticker symbol (the agent first resolves the official ticker from the CRM-provided account name, since the CRM name is often inaccurate). Collects in parallel:
Output: a structured dictionary with basic info, news, financials, balance sheet, cash flow, annual report extracts, earnings call summary, and value-proposition alignment.
For non-listed companies. Input: a company domain. Collects from the company website plus LLM analysis:
Both collectors feed a synthesis step (via Portkey Chat API) that produces five output sections:
Portkey AI Gateway. Every LLM call routes through Portkey. Lets us switch providers (Claude, GPT, open-source) without changing call sites, externalize prompt templates, get observability and logging out of the box. Critical for a long-lived API that needs to evolve model choice without redeploying.
Parallel collection with ThreadPoolExecutor. Each data source has its own latency profile (SEC API is slow, Yahoo is fast, Google Search is medium). Sequential collection would take 30+ seconds per account. Parallel fan-out brings it under 10s for the public collector.
Database UPSERT with 2-week TTL. Account research is expensive to generate. Cached results live for 2 weeks. Re-requests within that window serve from cache. After 2 weeks, the next request triggers a refresh. Refresh is PULL-based (on next request), not automatic, which keeps infrastructure cost bounded.
Async job interface. Account research takes 10 to 60 seconds depending on data sources. Synchronous REST would tie up client connections. The API uses a job-token pattern: submit a request, get a token, poll the token endpoint or receive a webhook on completion.
Credit-based rate limiting. Each customer has a credit balance with expiry (for example, 100 credits valid until a specific date). Each account research is 1 credit. Rate limit is per-customer, capped at 5 calls per minute. Audit logging captures every REST invocation for billing and debugging.
Company name resolution. CRM-stored account names are often informal or incorrect. The agent has a name-resolution step that disambiguates the official ticker symbol and long name from a fuzzy input. Handles edge cases like Nestle (multinational with regional listings) and ambiguous small-caps.
Multi-market ticker coverage. Tested across NYSE, NASDAQ, Euronext, LSE, SZSE, TSX, BSE, ASX. The agent picks the appropriate market based on the input or surfaces ambiguity.
The agent replaced 1 to 3 hours of manual KAM research per account with a single API call returning a structured report in 10 to 60 seconds, running in production with caching, credit-based rate limiting, and full audit logging.
The pattern that makes research agents reliable in production is deterministic scaffolding around the LLM: fuzzy entity disambiguation, parallel data collection, structured output synthesis, pull-based TTL caching, rate limiting, and gateway observability.