Principal Data & AI Architect · Salesforce Panel

Agentic Customer
Growth Platform

A multi-agent AI system for payments & merchant sales intelligence — built with LangGraph, Claude, and pgvector.

Introduction

Spencer Marley

20+ years bridging quantitative finance, cloud infrastructure, and applied AI — from KPMG to AWS to building agentic systems from scratch.

🎓

Academic Foundation

MSc Mathematics, Imperial College London. Master of IT in Artificial Intelligence, Singapore Management University (2021–2023). CFA Charterholder. Chartered Accountant (ICAEW).

☁️

AWS AI/ML Leadership

Head of AI/ML, Asia Pacific & Japan at Amazon Web Services (2019–2022). Drove 100%+ year-on-year growth in AI/ML adoption. Built and landed a $600K+ pathology image AI solution from zero.

🏦

Consulting & Finance

Associate Director at KPMG Management Consulting. Financial modelling and data analytics across financial services, automotive and telecoms. Fund management at Livingbridge (GBP 100M+ AUM).

🚀

Startup & Scale-up

Independent AI & cloud consultant since 2023. Led go-to-market for a payments fintech, doubled a flagship customer contract, and advised an InsurTech on generative AI strategy.

What I Bring

Unique perspectives

The combination of quantitative depth, hands-on building, commercial leadership, and cross-industry experience is rare. That combination is what I bring to Salesforce.

Quantitative rigour

MSc Mathematics → CFA → MSIT-AI. Every model, tool, and recommendation is stress-tested with the same discipline I applied to structured finance and ML coursework.

End-to-end builder

I design, build and ship — from database schema and LangGraph state machines to Next.js UI and AWS Amplify deployment. No hand-off, no black boxes.

Commercial instinct

I have led revenue targets, go-to-market plays, and CxO conversations at AWS. I understand that AI projects succeed when they are tied to measurable business outcomes.

Cross-domain perspective

Hyperscaler (AWS), top-tier consulting (KPMG), private equity (Livingbridge), and startup advising. I translate between the language of engineers, executives, and end users.

Learning Process & Technical Discovery

Why LangGraph?

I evaluated AutoGen, CrewAI, raw LangChain, and LangGraph. LangGraph won on three dimensions: TypeScript-native type safety, fine-grained control over state and routing, and production-grade checkpointing with human-in-the-loop support.

StateGraph

Directed graph where each node is an agent function and edges define routing logic. Supports conditional branching and parallel fan-out.

Annotation.Root

Type-safe state container using LangGraph's Annotation API. Each field has a reducer (e.g. messagesStateReducer) for merge semantics.

Nodes & Edges

Nodes are async functions that read/write state. Conditional edges (addConditionalEdges) enable dynamic routing based on agent output.

Checkpointing

PostgresSaver persists full graph state after every node — enables conversation continuity, resumption after failure, and HITL interruption.

Framework comparison

FrameworkStrengthsWhy not chosen
AutoGenMulti-agent conversations, Microsoft-backedPython-first, less fine-grained state control
CrewAIRole-based agents, easy to startAbstraction hides routing logic, less transparent
LangChain LCELComposable chains, large ecosystemNo native graph topology or checkpoint support
LangGraph ✓Stateful graph, TypeScript, HITL, checkpointingChosen — best fit for production multi-agent use case

Learning Process & Technical Discovery

The build journey

Key takeaways and the real challenges encountered — with how we overcame them.

Key takeaways

🔭

Observability first

LangSmith traces were essential from day one. Without visibility into what each agent called and why, debugging agentic loops is near-impossible.

🛡️

Tool safety matters

Every tool call must be wrapped in try/catch. One unhandled error cascades through the graph. Typed tools over natural-language-to-SQL every time.

🧠

State design is the hard part

Deciding what lives in the LangGraph state, what is fetched fresh, and what is cached between nodes required several iterations to get right.

⚙️

Infrastructure constraints bite

AWS Amplify's 29-second API Gateway timeout and LangSmith's async run submission both required careful workarounds in production.

Challenges & solutions

Recursion limit exceeded

Raised limit from 12 to 25; added CRM loop cap at 2 iterations in supervisor router to prevent unbounded tool calls.

AWS Amplify 504 timeout

Persisted thread + user message to DB before agent runs, so failed requests don't lose conversation history.

LangSmith run URL missing

shareRun() race condition fixed with 3-second timeout and fallback to project dashboard URL.

Duplicate conversation messages

Split saveMessages() into saveUserMessage() (upfront) and assistant-only save (on completion) with deduplication logic.

The Problem

Which customers should I prioritise this week?

Account managers have the data — but not the synthesis. The answer is buried across a CRM, internal docs, and live market signals.

📋

Too much CRM data

Account managers juggle hundreds of accounts. Fit scores, churn signals, open opportunities — all scattered.

📰

Market signals missed

A key customer raises funding or announces expansion — by the time a rep notices, a competitor has already called.

✍️

Slow outreach

Personalised, compliant outreach takes hours per account. Reps default to templates and conversion suffers.

The Solution

Six agents. One answer.

A LangGraph StateGraph orchestrates specialist agents in sequence. Each agent has a single responsibility and a constrained toolset.

Supervisor

Understands the request, routes to specialist agents, maintains state.

CRM Agent

Queries merchant accounts, opportunities, and interaction history.

Knowledge Agent

Retrieves internal playbooks and policies via pgvector RAG.

Research Agent

Searches the live web via Tavily for funding rounds and market signals.

Analyst Agent

Synthesises all context into prioritised, scored recommendations.

Governance Agent

Checks sources, flags outreach, enforces human approval. Einstein Trust Layer equivalent.

Technology

Production-credible stack.

Every layer maps to a Salesforce equivalent — demonstrating that the engineering patterns behind Agentforce are transferable across frameworks.

LayerThis appSalesforce equivalent
OrchestrationLangGraph.jsAgentforce Agent Builder
Primary LLMClaude Sonnet 4.6 (Anthropic)Einstein AI — primary model
Fallback LLMGPT-4o (OpenAI)Einstein AI — bring-your-own-model
EmbeddingsOpenAI text-embedding-3-smallEinstein AI embeddings
Vector storepgvector (PostgreSQL)Data Cloud / Data 360
CRM dataPostgreSQL + Drizzle ORMSales Cloud / Service Cloud
Web searchTavily APIData Cloud external connectors
ObservabilityLangSmithAgentforce Analytics / Audit Trail
GovernanceGovernance Agent + HITL flagEinstein Trust Layer
MemoryPostgreSQL agent_memories tableCustomer 360 context
FrontendNext.js + Tailwind CSSExperience Cloud
HostingAWS Amplify Gen 2Salesforce Infrastructure

Knowledge, RAG & External Tools

Grounded in trusted data.

Internal knowledge is embedded and retrieved via pgvector. External signals come from Tavily. Memory persists across sessions.

RAG ingestion pipeline

01

Source documents

Five markdown files in /data/docs — sales playbook, product catalog, growth strategy, compliance policy, outreach guidelines.

02

Chunking

RecursiveCharacterTextSplitter: chunk size 1,000 characters, 200-character overlap. Preserves semantic coherence at boundaries.

03

Embedding

OpenAI text-embedding-3-small (1,536 dimensions). Batch embedded and stored in the PostgreSQL document_chunks table via pgvector.

04

Retrieval

Query → embed → cosine similarity search in pgvector → top-k chunks returned to Knowledge Agent as grounded context.

External tools & memory

Tavily Web Search

Live web search API. Research Agent calls it to retrieve funding rounds, competitor news, and market signals. Results stored for audit trail.

Memory (short-term)

agent_messages table keyed by threadId. Last 8 messages loaded at run start to maintain conversation continuity.

Memory (long-term)

agent_memories table. Analyst Agent writes key account insights after each run. Recalled at the start of the next session for the same thread.

Architecture

How the components interact.

From the Next.js frontend through the LangGraph agent pipeline to the PostgreSQL data layer — left to right, top to bottom.

Frontend
Agent Layer
Tools
Data Layer

Frontend

Chat UI

Next.js App Router

Customers

CRM table view

Traces / Logs

Audit log

API

POST /api/chat

Route Handler (sync)

GET /api/threads

Thread history

GET /api/traces

Agent run log

Agent Pipeline

Supervisor

LangGraph StateGraph

CRM Agent

Account intelligence

Knowledge Agent

pgvector RAG

Research Agent

Tavily web search

Analyst Agent

Synthesis + scoring

Governance Agent

HITL + trust layer

Tools

CRM Tools

Typed safe queries

RAG Tool

pgvector retrieval

Web Search

Tavily API

Memory Tools

get / save memories

Score Tool

Deterministic scoring

Data Layer

PostgreSQL

CRM + pgvector

LangSmith

Trace observability

Claude Sonnet

Primary LLM

GPT-4o

Fallback LLM

AWS Amplify

Hosting + SSR

Salesforce Mapping

Every component maps to Agentforce.

The same architectural patterns appear in both open-framework and Salesforce-native implementations — the hard problems are identical.

This applicationSalesforce equivalent
PostgreSQL CRM tablesSales Cloud / Service Cloud
/data/docs + pgvector knowledge baseData Cloud / Data 360
LangGraph StateGraphAgentforce Agent Builder
Supervisor routing logicAtlas Reasoning Engine
Governance Agent + requiresApprovalEinstein Trust Layer + HITL
LangSmith tracesAgentforce Analytics / Audit Trail
Typed CRM toolsFlow / Apex / API actions
Recommendation output with citationsAgentforce grounded action output
Thread + memory layerCustomer 360 context + interaction history
Model-agnostic LLM layerEinstein AI — bring-your-own-model

Competitive Comparison

Open framework vs Agentforce.

The goal is not to claim superiority — it is to demonstrate that I understand both approaches deeply enough to architect the right solution for any enterprise context.

AreaThis appSalesforce Agentforce
Model agnosticismClaude Sonnet 4.6 as primary, GPT-4o as fallback. Swap any model at the graph level with a single config change.Einstein AI supports BYOM but within the Salesforce platform boundary.
Full transparencyEvery agent decision, tool call, and state transition is logged and inspectable via LangSmith and the Logs page.Agentforce Analytics provides visibility, but internal reasoning is more opaque.
Infrastructure freedomRuns on any cloud. PostgreSQL + pgvector is open-source and portable. No platform lock-in.Agentforce is optimised for Salesforce-native infrastructure and Data Cloud.
Cost efficiencyToken-level cost control. Only pay for what you use. No platform licensing on top of API costs.Agentforce licensing adds cost, justified by CRM-native integration and enterprise compliance.
CRM integrationTyped safe query functions over PostgreSQL. Fast to build, easy to test. Not production CRM-connected.Native Sales Cloud integration is Salesforce's strongest advantage — no API stitching required.
GovernanceGovernance Agent + requiresApproval flag. Human-in-the-loop built into the graph topology.Einstein Trust Layer provides enterprise-grade data masking, toxicity filtering, and audit compliance.

Value Proposition

Agentic AI that earns enterprise trust.

Agentic AI only creates enterprise value when it is grounded in trusted data, connected to business workflows, governed by policy, observable in production, and measured against customer outcomes.

🎯

Production-readiness

  • ·Async agent pipeline with explicit error handling at every node
  • ·Thread persistence before agent runs — no lost conversations on timeout
  • ·Full observability via LangSmith traces, Logs page, and structured DB records
📐

Scalable architecture

  • ·LangGraph graph topology supports parallel fan-out (CRM + Knowledge + Research simultaneously)
  • ·pgvector scales with PostgreSQL — no separate vector database infrastructure required
  • ·Model-agnostic: swap Claude for GPT-4o (or any future model) at the graph level
🔒

Enterprise governance

  • ·Governance Agent enforces source citation and confidence thresholds before output
  • ·requiresApproval flag halts agentic action without human sign-off
  • ·Full audit trail: every tool call logged with input, output, latency, and status
💡

Unique technology

  • ·pgvector brings semantic search to the same database as CRM data — fewer moving parts
  • ·LangGraph checkpointing enables conversation resumption and HITL interruption
  • ·Long-term memory (agent_memories) learns account insights across sessions

Future Roadmap

Where we go from here.

A prioritised view of what would be tackled next, and how the architecture scales toward a production Salesforce deployment.

Near-term

Streaming responses

Replace synchronous POST with SSE stream — real-time token-by-token output once Amplify streaming is confirmed stable.

Parallel agent fan-out

Upgrade graph from sequential to parallel using LangGraph Send API — CRM, Knowledge, and Research agents run simultaneously.

Hybrid RAG search

Add pg_trgm full-text search alongside pgvector semantic search for improved retrieval recall on exact match queries.

Medium-term

Salesforce CRM integration

Replace seed data with live Salesforce Sales Cloud data via the REST API — direct pipeline from Salesforce objects to agent context.

S3 document upload

Move knowledge base to S3 with signed URL upload — scales to thousands of documents without filesystem limits.

Advanced memory

Activate PostgresSaver LangGraph checkpointer for full graph state persistence and resumption after failures.

Longer-term

Agentforce migration

Migrate the agent topology to Salesforce Agentforce — using the architectural patterns demonstrated here as the blueprint.

Einstein Trust Layer

Replace Governance Agent with native Einstein Trust Layer for enterprise-grade data masking, toxicity filtering, and compliance.

Real-time market signals

Replace Tavily with a structured data feed (Bloomberg, Refinitiv) for deterministic, auditable market intelligence.

Q&A & Wrap-up

Over to you.

I built this to demonstrate the mechanics behind enterprise agentic AI — grounded data, tool safety, governance, and observability. The hard part is not prompting. The hard part is reliable enterprise execution.

Questions to explore

How would you approach migrating this to Salesforce Agentforce?
How does the Governance Agent compare to Einstein Trust Layer in practice?
What would make this production-ready for a real enterprise customer?
How would you scale this across hundreds of account managers?
What metrics would you use to measure the business impact?