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
| Framework | Strengths | Why not chosen |
|---|---|---|
| AutoGen | Multi-agent conversations, Microsoft-backed | Python-first, less fine-grained state control |
| CrewAI | Role-based agents, easy to start | Abstraction hides routing logic, less transparent |
| LangChain LCEL | Composable chains, large ecosystem | No native graph topology or checkpoint support |
| LangGraph ✓ | Stateful graph, TypeScript, HITL, checkpointing | Chosen — 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.
Understands the request, routes to specialist agents, maintains state.
Queries merchant accounts, opportunities, and interaction history.
Retrieves internal playbooks and policies via pgvector RAG.
Searches the live web via Tavily for funding rounds and market signals.
Synthesises all context into prioritised, scored recommendations.
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.
| Layer | This app | Salesforce equivalent |
|---|---|---|
| Orchestration | LangGraph.js | Agentforce Agent Builder |
| Primary LLM | Claude Sonnet 4.6 (Anthropic) | Einstein AI — primary model |
| Fallback LLM | GPT-4o (OpenAI) | Einstein AI — bring-your-own-model |
| Embeddings | OpenAI text-embedding-3-small | Einstein AI embeddings |
| Vector store | pgvector (PostgreSQL) | Data Cloud / Data 360 |
| CRM data | PostgreSQL + Drizzle ORM | Sales Cloud / Service Cloud |
| Web search | Tavily API | Data Cloud external connectors |
| Observability | LangSmith | Agentforce Analytics / Audit Trail |
| Governance | Governance Agent + HITL flag | Einstein Trust Layer |
| Memory | PostgreSQL agent_memories table | Customer 360 context |
| Frontend | Next.js + Tailwind CSS | Experience Cloud |
| Hosting | AWS Amplify Gen 2 | Salesforce Infrastructure |
Live Demo
Try it now.
Everything below is connected to a live PostgreSQL database, a real Anthropic API, and LangSmith observability.
Run the agent — ask which accounts to prioritise, request outreach drafts, watch the pipeline execute.
Browse 20+ seeded merchant accounts with opportunities, fit scores, and churn risk.
Internal docs indexed into pgvector — playbook, catalog, compliance policy.
Full audit trail of every agent run — tool calls, latency, LangSmith links.
System diagram with Salesforce Agentforce equivalents.
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
Source documents
Five markdown files in /data/docs — sales playbook, product catalog, growth strategy, compliance policy, outreach guidelines.
Chunking
RecursiveCharacterTextSplitter: chunk size 1,000 characters, 200-character overlap. Preserves semantic coherence at boundaries.
Embedding
OpenAI text-embedding-3-small (1,536 dimensions). Batch embedded and stored in the PostgreSQL document_chunks table via pgvector.
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
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 application | Salesforce equivalent |
|---|---|
| PostgreSQL CRM tables | Sales Cloud / Service Cloud |
| /data/docs + pgvector knowledge base | Data Cloud / Data 360 |
| LangGraph StateGraph | Agentforce Agent Builder |
| Supervisor routing logic | Atlas Reasoning Engine |
| Governance Agent + requiresApproval | Einstein Trust Layer + HITL |
| LangSmith traces | Agentforce Analytics / Audit Trail |
| Typed CRM tools | Flow / Apex / API actions |
| Recommendation output with citations | Agentforce grounded action output |
| Thread + memory layer | Customer 360 context + interaction history |
| Model-agnostic LLM layer | Einstein 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.
| Area | This app | Salesforce Agentforce |
|---|---|---|
| Model agnosticism | Claude 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 transparency | Every 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 freedom | Runs 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 efficiency | Token-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 integration | Typed 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. |
| Governance | Governance 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