You've built a "ChatGPT wrapper." You added a nice UI on top of the OpenAI API. Maybe you have conversation history. Users can chat with an AI.
Congratulations, you've built what a million other developers built in 2023.
But that's not an agent. That's a chatbot with extra steps.
This guide shows you how to build a real production agent — one with tools, memory, knowledge bases, and automation. We'll build it step by step using AI Magicx.
What We're Building
A Customer Success Agent that:
- Answers product questions using your documentation (RAG)
- Searches the web for competitor comparisons
- Checks customer status in your database
- Creates support tickets when it can't resolve issues
- Remembers customer preferences and history
- Triggers notifications for urgent issues
This isn't a chatbot. It's a system that handles support autonomously.
The Foundation: Understanding Agent Architecture
Before we build, let's understand what separates wrappers from agents:
Wrapper Architecture
User Message → LLM API → Response
That's it. Stateless. No tools. No memory. Just text in, text out.
Agent Architecture
User Message
↓
┌─────────────┐
│ Agent │
│ Engine │
└─────────────┘
│
├─→ LLM (reasoning)
├─→ Tools (actions)
├─→ Memory (context)
├─→ Knowledge (RAG)
└─→ Triggers (automation)
↓
Response + Side Effects
The agent doesn't just respond. It thinks, acts, remembers, and automates.
Step 1: Create the Agent Shell
Start with a new project in AI Magicx:
Name: Customer Success Agent
Instructions (first line): Handles customer inquiries, answers product questions, and resolves issues using documentation, customer data, and support tools.
This metadata helps users understand what the agent does and sets expectations.
Step 2: Craft the System Prompt
The system prompt is your agent's personality, capabilities, and constraints. Here's a production-ready example:
# Role
You are a Customer Success Agent for [Company Name]. You help customers
with product questions, troubleshoot issues, and ensure their success
with our platform.
# Capabilities
You have access to:
- Company documentation and knowledge base
- Customer account information
- Support ticket system
- Web search for comparisons and external resources
- Email notifications for escalations
# Guidelines
## Response Style
- Be friendly but professional
- Give concise answers with details available on request
- Use bullet points for lists
- Include relevant documentation links
- Acknowledge when you don't know something
## Handling Queries
### Product Questions
1. Search the knowledge base first
2. Provide accurate answers with sources
3. Include relevant documentation links
4. Offer to explain further if needed
### Troubleshooting
1. Ask clarifying questions about the issue
2. Check customer's account status and configuration
3. Search knowledge base for known solutions
4. Provide step-by-step resolution
5. If unresolved after 2 attempts, create support ticket
### Account Questions
1. Look up customer information
2. Verify what you can share (no sensitive data without verification)
3. For changes, direct to account settings or create ticket
### Feature Requests
1. Acknowledge the request
2. Check if feature exists or is planned
3. Create a feature request ticket
4. Thank them for feedback
### Escalations
Create a support ticket and notify team when:
- Customer expresses frustration
- Issue isn't resolved after 2 attempts
- Security or billing concerns
- Request for human agent
# Constraints
- Never share sensitive customer data (passwords, full payment info)
- Don't make promises about features or timelines
- Don't disparage competitors
- Always be honest about limitations
- Escalate rather than guess on critical issues
# Memory Usage
Remember:
- Customer's name and company
- Previous issues they've reported
- Their product tier and features
- Preferences they've expressed
This prompt defines:
- Role: What the agent is
- Capabilities: What it can do
- Guidelines: How it should behave
- Constraints: What it must not do
- Memory: What to remember
Step 3: Add Tools
Tools let your agent take action. For our Customer Success Agent:
Tool 1: Web Search
Purpose: Find information about competitors, industry trends, external resources.
In AI Magicx, enable the Web Search tool. The agent can now search the internet.
Example usage:
- "How does our pricing compare to Competitor X?"
- "What's the latest on GDPR requirements?"
Tool 2: Web Fetch
Purpose: Extract content from specific URLs.
Leave page reading on (it's part of the web tools). The agent can read documentation, blog posts, or any public URL.
Example usage:
- "What does this changelog say about the new API?"
- "Summarize the article at this link"
Tool 3: Customer Lookup (MCP Connector)
Purpose: Retrieve customer information from your database.
Add a lookup_customer tool to your own MCP server and connect the server in Customize → Connectors. The tool calls an endpoint like this:
Name: Customer Lookup
Description: Look up customer account information by email or customer ID
Endpoint: https://api.yourcompany.com/customers/lookup
Method: POST
Headers:
Authorization: Bearer ${API_KEY}
Content-Type: application/json
Body Template: |
{
"email": "${email}",
"customer_id": "${customer_id}"
}
The agent can now query:
"Look up the customer with email john@example.com"
And receive:
{
"name": "John Smith",
"company": "Acme Inc",
"plan": "Professional",
"status": "active",
"created_at": "2024-03-15",
"features": ["api_access", "team_members", "priority_support"]
}
Tool 4: Create Support Ticket
Purpose: Escalate issues to human agents.
Add a second tool to the same MCP server:
Name: Create Support Ticket
Description: Create a support ticket for issues requiring human attention
Endpoint: https://api.yourcompany.com/tickets/create
Method: POST
Headers:
Authorization: Bearer ${API_KEY}
Body Template: |
{
"customer_email": "${customer_email}",
"subject": "${subject}",
"description": "${description}",
"priority": "${priority}",
"category": "${category}"
}
The agent can now escalate:
Customer is frustrated about recurring API errors.
Creating high-priority ticket for engineering team...
Tool 5: Send Notification
Purpose: Alert team members for urgent issues.
A third MCP tool can post to Slack:
Name: Send Slack Notification
Description: Send urgent notifications to the customer success team
Endpoint: https://hooks.slack.com/services/YOUR/WEBHOOK/URL
Method: POST
Body Template: |
{
"text": "🚨 ${urgency}: ${message}",
"channel": "#customer-success-alerts"
}
Now the agent can ping the team:
"Sending urgent notification about potential churn risk..."
Step 4: Build the Knowledge Base
RAG (Retrieval-Augmented Generation) gives your agent access to your specific data.
What to Upload
For a Customer Success Agent:
-
Product Documentation
- User guides
- API references
- Feature documentation
- Troubleshooting guides
-
FAQs
- Common questions and answers
- Known issues and workarounds
- Best practices
-
Internal Resources
- Pricing details
- Feature comparison charts
- Roadmap summaries (what's shareable)
- Competitor analysis
-
Support Resources
- Escalation procedures
- SLA information
- Team contact list
Uploading Documents
In the project's Knowledge panel:
- Add your files (PDF, Word, Markdown, text)
- Wait while they're read (chunking + embedding)
- Test with sample questions in a chat inside the project
Best Practices
Chunk size matters: AI Magicx handles this automatically, but understand that larger chunks preserve context while smaller chunks improve precision.
Update regularly: Documentation changes. Set reminders to refresh your knowledge base monthly.
Test retrieval: Before going live, test queries to ensure relevant content is retrieved.
Test: "How do I set up SSO?"
Expected: SSO configuration documentation
Actual: [Check retrieval results]
Add metadata: Include section headers and document titles. This helps retrieval and citation.
Step 5: Configure Memory
Memory transforms stateless interactions into ongoing relationships.
How Memory Works in AI Magicx
AI Magicx keeps memory you can see and edit in Customize → Memory: facts about you and your work that every chat can use. It isn't a per-customer database. For per-customer history, keep each customer's conversation in its own chat, or have the agent read and update customer notes in your CRM through a connector (Step 3).
What to Keep Per Customer
Whether in the chat or in your CRM, keep:
- Customer name and company
- Product tier and features
- Previous issues and resolutions
- Expressed preferences
- Important dates (renewal, onboarding)
Memory in Action
With customer notes kept in your CRM through a connector, it looks like this.
First conversation:
Customer: Hi, I'm Sarah from TechCorp. We're on the Enterprise plan.
Agent: Hello Sarah! Great to connect. I see you're on our Enterprise
plan which includes priority support, API access, and dedicated
account management. How can I help you today?
Note saved to the CRM: "Customer Sarah, company TechCorp, Enterprise plan"
Second conversation (days later):
Customer: Hey, quick question about the API
Agent: Hi Sarah! Good to hear from you again. You mentioned TechCorp
is on our Enterprise plan with API access. What's your question
about the API?
Notes looked up through the connector. No context needed.
Memory Guidelines
Teach your agent what to remember in the system prompt:
# Memory Usage
Always remember:
- Customer's name and company
- Their plan level and key features
- Issues they've reported
- Preferences they express ("I prefer email over chat")
- Important dates (renewal, training scheduled)
Never store:
- Passwords or credentials
- Full payment details
- Personal data beyond name/email
- Complaints about specific employees
Step 6: Set Up Automation
Agents shouldn't only respond to messages. They should trigger on events.
Triggers from Your Systems
Have your systems start a run through the API when something happens (POST /api/v1/runs, paid from your prepaid API balance):
Support Ticket Created:
Call: POST /api/v1/runs (from your help desk)
Triggers: New support ticket
Action: Agent analyzes ticket, searches knowledge base, suggests response
Customer Sign-up:
Call: POST /api/v1/runs (from your sign-up flow)
Triggers: New customer registration
Action: Agent sends personalized welcome message with onboarding steps
Usage Alert:
Call: POST /api/v1/runs (from your billing system)
Triggers: Customer approaches usage limit
Action: Agent proactively reaches out with upgrade options
Scheduled Tasks
Configure the agent to run on schedule:
Daily: Check for customers with expiring trials Weekly: Generate summary of common issues Monthly: Create customer health reports
Event-Driven Intelligence
With triggers, your agent becomes proactive:
[Webhook: Customer usage dropped 50%]
Agent: Hi Sarah, I noticed your team's usage of our platform has
decreased significantly this week. Is everything okay?
I wanted to check if you're experiencing any issues or if
there's anything I can help with.
This is the difference between a chatbot (waits for messages) and an agent (takes initiative).
Step 7: Test Thoroughly
Before launch, test every capability:
Functional Tests
| Test Case | Expected Behavior |
|---|---|
| Product question | Answers from knowledge base |
| Unknown question | Admits uncertainty, offers alternatives |
| Competitor comparison | Uses web search, balanced response |
| Customer lookup | Retrieves correct data |
| Ticket creation | Creates ticket, confirms to user |
| Escalation trigger | Creates ticket + notifies team |
| Memory recall | Remembers previous conversations |
Edge Cases
- What happens if the API is down?
- How does it handle abusive messages?
- What if the customer asks about a competitor's product?
- How does it respond to data deletion requests?
Load Testing
If you expect high volume:
- Test concurrent conversations
- Measure response latency
- Check rate limit handling
- Verify memory doesn't conflict across users
Security Testing
- Try to extract system prompt
- Attempt prompt injection
- Test data access boundaries
- Verify no sensitive data leakage
Step 8: Deploy and Monitor
Deployment Options
Your own chat: There's no embeddable widget; call the API from the chat in your app or website.
API Integration: Call from your backend
const response = await fetch("https://aimagicx.com/api/v1/runs", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.AIMAGICX_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": crypto.randomUUID(),
},
body: JSON.stringify({
model: "auto",
input: userMessage,
instructions: SUPPORT_INSTRUCTIONS,
tools: ["web"],
metadata: { customerId: user.id },
}),
});
A webhook can tell your backend when the run finishes. See the API docs.
Slack/Discord: Not built in. Have your bot forward messages to the API and post the reply back in the thread.
Monitoring
Track these metrics:
Performance:
- Response latency (aim for <5s for complex queries)
- Tool execution time
- Knowledge base retrieval accuracy
Quality:
- User satisfaction ratings
- Escalation rate (lower is better, to a point)
- Resolution rate
- Repeat contacts for same issue
Usage:
- Conversations per day
- Messages per conversation
- Peak usage times
- Feature utilization
Iteration
Your first version won't be perfect. Plan for:
Week 1: Monitor closely, fix obvious issues Month 1: Analyze conversation logs, refine prompts Ongoing: Update knowledge base, add tools, improve based on feedback
The Transformation
Here's what you've built:
| ChatGPT Wrapper | Production Agent |
|---|---|
| Text in → Text out | Multi-step reasoning |
| No memory | Remembers everything |
| No tools | 5+ integrated tools |
| No data access | Knowledge base + DB |
| Manual only | Webhook automation |
| No escalation | Smart handoff |
| Single session | Relationship-aware |
This isn't an incremental improvement. It's a different category of system.
Next Steps
Now that you have a production agent:
- Expand tools: Add more integrations as needs emerge
- Grow knowledge: Keep documentation current
- Add projects: Create specialized agents as projects (billing, technical, onboarding)
- Split big jobs: Let Magicx hand parts of a task to helpers that work at the same time
- Measure impact: Track time saved, tickets deflected, satisfaction scores
Ready to build your first production agent? Start with AI Magicx's free tier and transform your customer support.