Agent-TS Architecture
This document covers the internal architecture of Agent-TS, including the component structure, message flow, and extension patterns.Component Overview
File Responsibilities
Core Files
| File | Responsibility |
|---|---|
index.ts | Express server, webhook routes, agent lifecycle |
olive-agent.ts | OpenAI client, assistant management, conversation state |
gateway-client.ts | Gateway API client with typed interfaces |
config.ts | Environment variable parsing and defaults |
logger.ts | Pino logging adapter |
Tools Directory
| File | Functions |
|---|---|
wallet.ts | check_balance, get_transactions, initiate_transfer, get_account_limits |
cards.ts | get_user_cards, link_card, block_card, unblock_card |
kyc.ts | upload_kyc_image, upgrade_kyc |
registration.ts | register_subscriber |
agent.ts | Agent-specific operations |
Service Files
| File | Responsibility |
|---|---|
ocr-service.ts | Tesseract.js OCR extraction and scoring |
id-card-validator.ts | OpenAI Vision + heuristics for ID validation |
image-compressor.ts | Image optimization before upload |
s3-uploader.ts | Private S3 uploads with pre-signed URLs |
Request Flow
Text Message Processing
Image Upload Processing
OpenAI Integration
Assistant Configuration
Tool Registration Pattern
Security Layers
Input Sanitization
Rate Limiting
Service Authentication
For internal service calls, the agent uses HMAC-based authentication:Error Handling
Graceful Degradation
Extension Guide
Adding a New Tool
- Create the tool definition and handler:
- Register in
olive-agent.ts:
- Restart the agent to apply changes.