Pi's Core Mechanics for Custom Product Agents
Pi is a minimal TypeScript SDK for building coding agents: an LLM runs tools in a loop with goals and context, using agent core for prompting, events, and hooks. Instantiate an Agent class, inject context or prompts, and subscribe to events like tool calls succeeding (checkmarks in streams). Hooks before tool calls enable checks like role-based access without updating contacts prematurely. For coding, add a runtime shell (Bash) where agents discover tools like ffmpeg for untaught tasks (e.g., voice messages), creating the illusion of learning. Extensions add session events and UI interactions: select CRM leads via dropdowns in terminal or web UIs Pi generates. OpenClaw extends Pi for multi-channel sessions, threads, and plugins (routing, sub-agents), reusing Pi's session support, coding agent, agent core, LM abstraction, and terminal UI.
Build simple agents first: a 3-file TypeScript CRM lead qualifier with commands like "show all leads and score them" uses tools for listing/scoring, steered by system prompts describing tools. Sessions persist context across interactions, ideal for ongoing tasks.
Architectural Principle: Design for Agent Strengths
Make systems agent-friendly: agents excel at stitching simple tools, so expose data access via CLIs rather than complex APIs. CLIs match agent skills (Bash shell), avoiding compensation for messy interfaces. Example: Cowork bundles Excel skills using small CLIs (pandas, openpyxl, LibreOffice) instead of direct Excel interaction, yielding strong reception in finance tools.
No established patterns exist—experiment in the "fuck around and find out" phase. Tinker with Pi: ask it to build features via system prompts; rip apart/reassemble its open-source minimalism. Emerging pattern: one-thing-well programs (Ken Thompson/Unix) compose into agent power. Secure with sandboxes; explore Nvidia's OpenClaw policy/open shell for agent isolation.
Real-World Embedding: B2B Sales Pipeline
Route incoming RFP emails to per-customer agent sessions: monitor inbox, gateway routes to sessions (reuse for context), using agent.md (role/system instructions) and customer.md (quirks, discounts, access). Tools as CLIs query CRM/ERP securely in sandboxes, pulling leads/orders. Agent loops tools to analyze RFPs, generating draft responses in the inbox—humans edit without leaving email.
Dashboard shows cases (sessions), tool calls (e.g., German apologies handled), and threads. Output: RFP email triggers draft; ignored emails skipped. Scales to multiple agents/threads. Key: humans see only polished drafts; agents handle complexity underground. Pi perfect for this—minimal, extensible; bet on coding agents as core building blocks.