chat-agent
v0.0.4
Published
Resend for AI agents
Readme
chat-agent
chat-agent is the easiest way to create an AI chatbot using TypeScript.
- Simple config: Define your questions and completion logic in a single object.
- LLM-powered: Uses OpenAI or Claude (Anthropic) to extract and validate answers from free-form user input.
- Conversational: Handles multi-question conversations, lets users answer in natural language, and guides them to complete all required info.
- Rapid prototyping: Perfect for forms, lead capture, support, surveys, and more—no need to build a UI or complex logic.
Test Your Own Agent
You can test your own agent by creating a config file (JavaScript or TypeScript) that exports a bot agent instance (e.g., export const bot = chatAgent({...})).
You'll be prompted for your OpenAI API key and can interact with a sample plane ticket booking agent.
Then run:
npx chat-agent --config ./my-agent.jsExample agent file (my-agent.ts)
import { chatAgent } from "chat-agent";
export const bot = chatAgent({
modelProvider: {
openai: {
apiKey: process.env.OPENAI_API_KEY!,
model: "gpt-4o",
},
},
questions: [
{ id: "name", prompt: "What's your full name?" },
{ id: "from", prompt: "From which city are you departing?" },
{ id: "to", prompt: "Where are you flying to?" },
{ id: "date", prompt: "When do you want to travel?" },
{ id: "roundTrip", prompt: "Is this a round trip or one-way?" },
],
onComplete: async (data) => {
console.log("Collected data:", data);
// { name: "...", from: "...", to: "...", date: "...", roundTrip: "..." }
},
});More Example Agent Files
Sales Lead Capture Bot (sales-lead-bot.ts)
questions: [
{ id: "name", prompt: "What's your full name?" },
{ id: "company", prompt: "What company do you represent?" },
{ id: "email", prompt: "What's your business email address?" },
{
id: "interest",
prompt: "What product or service are you interested in?",
},
{ id: "budget", prompt: "What is your estimated budget?" },
],
onComplete: async (data) => {
await crm.createLead(data);
console.log("Sales lead captured:", data);
// { name: "...", company: "...", email: "...", interest: "...", budget: "..." }
},Scheduling Bot (scheduling-bot.ts)
questions: [
{ id: "name", prompt: "What's your name?" },
{ id: "email", prompt: "What's your email address?" },
{ id: "date", prompt: "What date would you like to schedule?" },
{ id: "time", prompt: "What time works best for you?" },
{ id: "purpose", prompt: "What's the purpose of the meeting?" },
],
onComplete: async (data) => {
await calendar.schedule(data);
console.log("Scheduling request:", data);
// { name: "...", email: "...", date: "...", time: "...", purpose: "..." }
}Customer Support Triage Bot (support-triage-bot.ts)
questions: [
{ id: "name", prompt: "May I have your name?" },
{ id: "email", prompt: "What's your email address?" },
{
id: "issueType",
prompt:
"What type of issue are you experiencing? (e.g., billing, technical, account)",
},
{ id: "description", prompt: "Please describe your issue in detail." },
{ id: "urgency", prompt: "How urgent is this issue? (low, medium, high)" },
],
onComplete: async (data) => {
await zendesk.createTicket(data);
console.log("Support ticket:", data);
// { name: "...", email: "...", issueType: "...", description: "...", urgency: "..." }
}Data Collection / Survey Bot (survey-bot.ts)
questions: [
{ id: "age", prompt: "What is your age?" },
{ id: "gender", prompt: "What is your gender?" },
{
id: "satisfaction",
prompt: "How satisfied are you with our service? (1-5)",
},
{ id: "feedback", prompt: "Any additional feedback or comments?" },
],
onComplete: async (data) => {
await db.saveSurvey(data);
console.log("Survey response:", data);
// { age: "...", gender: "...", satisfaction: "...", feedback: "..." }
}