How Master Agent Works: A Deep Dive
At the heart of Keystos, Master Agent is not a simple chatbot that replies to incoming messages. It is an autonomous AI Operating System that understands the intent behind requests, grasps your database schema, and confidently executes complex operations. In this post, we take a deep look at the engineering behind the Master Agent architecture.
1. Multi-Agent Orchestration
Master Agent is not a single language model (LLM). To improve the quality and speed of the work, it uses a Multi-Agent architecture made of specialized agents that work together.
The Orchestrator Agent takes the lead: it analyzes the raw incoming message, performs intent classification, and delegates the task to the most suitable sub-agent:
[Customer Input] ──► [Orchestrator Agent]
│
┌──────────────────┼──────────────────┐
▼ ▼ ▼
[Order Agent] [Appointment Agent] [Support Agent]
(Orders & Stock) (Bookings) (Knowledge Base)Thanks to this approach, each model runs the tools of its own specialty with far higher reliability and minimal deviation (low hallucination).
2. Schema-Aware Reasoning
Master Agent dynamically adapts to your business's database schema. Instead of hard-coded field definitions, the system reads the data objects and the relationships between them from the initial prompt. For example:
Patient ──[joined]──► ClinicStudy ──[includes]──► Experiment
When a user asks, *'List the patients who joined last month and whose lab results showed anomalies'*, Master Agent follows these relationships (cross-object reasoning) and autonomously builds the complex SQL or pgvector queries.
3. Two-Layer Memory (Unified Memory Architecture)
Like a human representative, Master Agent never forgets the past. To deliver a natural, fluid conversation experience, it uses two memory layers:
- Short-Term Memory (Conversation Buffer): Preserves the immediate context of the ongoing conversation, what pronouns refer to, and the flow of the discussion.
- Long-Term Memory (Vector-Based Memory): Stores previous conversations, customer habits, past order preferences, and private notes in a
pgvectordatabase. When a customer returns after two weeks, the system recalls the past context within seconds using semantic search.
4. Real-World Tool Use (Tool-Use System)
Agents do more than generate text; they trigger API endpoints and functions that perform safe read and write operations on the database.
For example, when a restaurant order comes in, the Order Agent calls these tools in sequence:
// Step 1: Stock Check
const stock = await checkStock({ itemId: "item_cafe_latte", qty: 2 });
// Step 2: Create Order
if (stock.available) {
const order = await createOrder({
workspaceId,
items: [{ id: "item_cafe_latte", qty: 2 }],
status: "PENDING_PAYMENT"
});
}5. Industrial-Grade Security and HITL (Human-in-the-Loop)
Having AI act autonomously is a huge convenience, but critical operations require human oversight. Keystos integrates flexible guardrails and human approval mechanisms:
- PII Masking: Sensitive data such as national ID numbers and credit card numbers is masked before it is sent to the language model.
- HITL (Human-in-the-Loop): When critical data deletion, bulk message sending, or high-budget transactions are detected, the system pauses the operation and drops a dynamic card onto the admin's approval screen. Nothing runs until the admin approves.
Bottom line: Master Agent follows your business rules to the letter, protects your data, and is your most dependable team member — running your sales and support operations around the clock while you sleep.
